当前位置: 首页>>代码示例>>C#>>正文


C# CSSNode.measure方法代码示例

本文整理汇总了C#中CSSNode.measure方法的典型用法代码示例。如果您正苦于以下问题:C# CSSNode.measure方法的具体用法?C# CSSNode.measure怎么用?C# CSSNode.measure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSSNode的用法示例。


在下文中一共展示了CSSNode.measure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: layoutNodeImpl

        static void layoutNodeImpl(CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, float parentMaxHeight, CSSDirection? parentDirection)
        {
            var childCount_ = node.getChildCount();
            for (int i_ = 0; i_ < childCount_; i_++)
            {
                node.getChildAt(i_).layout.resetResult();
            }


            /** START_GENERATED **/
    
      CSSDirection direction = resolveDirection(node, parentDirection);
      int mainAxis = resolveAxis(getFlexDirection(node), direction);
      int crossAxis = getCrossFlexDirection(mainAxis, direction);
      int resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
    
      // Handle width and height style attributes
      setDimensionFromStyle(node, mainAxis);
      setDimensionFromStyle(node, crossAxis);
    
      // Set the resolved resolution in the node's layout
      node.layout.direction = direction;
    
      // The position is set by the parent, but we need to complete it with a
      // delta composed of the margin and left/top/right/bottom
      node.layout.position[leading[mainAxis]] += node.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) +
        getRelativePosition(node, mainAxis);
      node.layout.position[trailing[mainAxis]] += node.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) +
        getRelativePosition(node, mainAxis);
      node.layout.position[leading[crossAxis]] += node.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) +
        getRelativePosition(node, crossAxis);
      node.layout.position[trailing[crossAxis]] += node.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) +
        getRelativePosition(node, crossAxis);
    
      // Inline immutable values from the target node to avoid excessive method
      // invocations during the layout calculation.
      int childCount = node.getChildCount();
      float paddingAndBorderAxisResolvedRow = ((node.style.padding.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.border.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis])) + (node.style.padding.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]) + node.style.border.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])));
      float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
    
      if (isMeasureDefined(node)) {
        boolean isResolvedRowDimDefined = !float.IsNaN(node.layout.dimensions[dim[resolvedRowAxis]]);
    
        float width = CSSConstants.Undefined;
        if ((!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) {
          width = node.style.dimensions[DIMENSION_WIDTH];
        } else if (isResolvedRowDimDefined) {
          width = node.layout.dimensions[dim[resolvedRowAxis]];
        } else {
          width = parentMaxWidth -
            (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]));
        }
        width -= paddingAndBorderAxisResolvedRow;
    
        float height = CSSConstants.Undefined;
        if ((!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) {
          height = node.style.dimensions[DIMENSION_HEIGHT];
        } else if (!float.IsNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) {
          height = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]];
        } else {
          height = parentMaxHeight -
            (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]));
        }
        height -= ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
    
        // We only need to give a dimension for the text if we haven't got any
        // for it computed yet. It can either be from the style attribute or because
        // the element is flexible.
        boolean isRowUndefined = !(!float.IsNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0) && !isResolvedRowDimDefined;
        boolean isColumnUndefined = !(!float.IsNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0) &&
          float.IsNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]);
    
        // Let's not measure the text if we already know both dimensions
        if (isRowUndefined || isColumnUndefined) {
          MeasureOutput measureDim = node.measure(
            
            layoutContext.measureOutput,
            width,
            height
          );
          if (isRowUndefined) {
            node.layout.dimensions[DIMENSION_WIDTH] = measureDim.width +
              paddingAndBorderAxisResolvedRow;
          }
          if (isColumnUndefined) {
            node.layout.dimensions[DIMENSION_HEIGHT] = measureDim.height +
              paddingAndBorderAxisColumn;
          }
        }
        if (childCount == 0) {
          return;
        }
      }
    
      boolean isNodeFlexWrap = (node.style.flexWrap == CSSWrap.Wrap);
    
      CSSJustify justifyContent = node.style.justifyContent;
    
      float leadingPaddingAndBorderMain = (node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]));
      float leadingPaddingAndBorderCross = (node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]));
//.........这里部分代码省略.........
开发者ID:tryroach,项目名称:css-layout,代码行数:101,代码来源:LayoutEngine.cs

示例2: layoutNodeImpl

        //
        // This is the main routine that implements a subset of the flexbox layout algorithm
        // described in the W3C CSS documentation: https://www.w3.org/TR/css3-flexbox/.
        //
        // Limitations of this algorithm, compared to the full standard:
        //  * Display property is always assumed to be 'flex' except for Text nodes, which
        //    are assumed to be 'inline-flex'.
        //  * The 'zIndex' property (or any form of z ordering) is not supported. Nodes are
        //    stacked in document order.
        //  * The 'order' property is not supported. The order of flex items is always defined
        //    by document order.
        //  * The 'visibility' property is always assumed to be 'visible'. Values of 'collapse'
        //    and 'hidden' are not supported.
        //  * The 'wrap' property supports only 'nowrap' (which is the default) or 'wrap'. The
        //    rarely-used 'wrap-reverse' is not supported.
        //  * Rather than allowing arbitrary combinations of flexGrow, flexShrink and
        //    flexBasis, this algorithm supports only the three most common combinations:
        //      flex: 0 is equiavlent to flex: 0 0 auto
        //      flex: n (where n is a positive value) is equivalent to flex: n 1 auto
        //          If POSITIVE_FLEX_IS_AUTO is 0, then it is equivalent to flex: n 0 0
        //          This is faster because the content doesn't need to be measured, but it's
        //          less flexible because the basis is always 0 and can't be overriden with
        //          the width/height attributes.
        //      flex: -1 (or any negative value) is equivalent to flex: 0 1 auto
        //  * Margins cannot be specified as 'auto'. They must be specified in terms of pixel
        //    values, and the default value is 0.
        //  * The 'baseline' value is not supported for alignItems and alignSelf properties.
        //  * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must be
        //    specified as pixel values, not as percentages.
        //  * There is no support for calculation of dimensions based on intrinsic aspect ratios
        //     (e.g. images).
        //  * There is no support for forced breaks.
        //  * It does not support vertical inline directions (top-to-bottom or bottom-to-top text).
        //
        // Deviations from standard:
        //  * Section 4.5 of the spec indicates that all flex items have a default minimum
        //    main size. For text blocks, for example, this is the width of the widest word.
        //    Calculating the minimum width is expensive, so we forego it and assume a default
        //    minimum main size of 0.
        //  * Min/Max sizes in the main axis are not honored when resolving flexible lengths.
        //  * The spec indicates that the default value for 'flexDirection' is 'row', but
        //    the algorithm below assumes a default of 'column'.
        //
        // Input parameters:
        //    - node: current node to be sized and layed out
        //    - availableWidth & availableHeight: available size to be used for sizing the node
        //      or CSS_UNDEFINED if the size is not available; interpretation depends on layout
        //      flags
        //    - parentDirection: the inline (text) direction within the parent (left-to-right or
        //      right-to-left)
        //    - widthMeasureMode: indicates the sizing rules for the width (see below for explanation)
        //    - heightMeasureMode: indicates the sizing rules for the height (see below for explanation)
        //    - performLayout: specifies whether the caller is interested in just the dimensions
        //      of the node or it requires the entire node and its subtree to be layed out
        //      (with final positions)
        //
        // Details:
        //    This routine is called recursively to lay out subtrees of flexbox elements. It uses the
        //    information in node.style, which is treated as a read-only input. It is responsible for
        //    setting the layout.direction and layout.measured_dimensions fields for the input node as well
        //    as the layout.position and layout.line_index fields for its child nodes. The
        //    layout.measured_dimensions field includes any border or padding for the node but does
        //    not include margins.
        //
        //    The spec describes four different layout modes: "fill available", "max content", "min content",
        //    and "fit content". Of these, we don't use "min content" because we don't support default
        //    minimum main sizes (see above for details). Each of our measure modes maps to a layout mode
        //    from the spec (https://www.w3.org/TR/css3-sizing/#terms):
        //      - CSS_MEASURE_MODE_UNDEFINED: max content
        //      - CSS_MEASURE_MODE_EXACTLY: fill available
        //      - CSS_MEASURE_MODE_AT_MOST: fit content
        //
        //    When calling layoutNodeImpl and layoutNodeInternal, if the caller passes an available size of
        //    undefined then it must also pass a measure mode of CSS_MEASURE_MODE_UNDEFINED in that dimension.
        //
        static void layoutNodeImpl(CSSLayoutContext layoutContext, CSSNode node, float availableWidth, float availableHeight, CSSDirection? parentDirection, CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, boolean performLayout)
        {
            /** START_GENERATED **/

              Assertions.assertCondition(float.IsNaN(availableWidth) ? widthMeasureMode == CSSMeasureMode.Undefined : true, "availableWidth is indefinite so widthMeasureMode must be CSSMeasureMode.Undefined");
              Assertions.assertCondition(float.IsNaN(availableHeight) ? heightMeasureMode == CSSMeasureMode.Undefined : true, "availableHeight is indefinite so heightMeasureMode must be CSSMeasureMode.Undefined");

              float paddingAndBorderAxisRow = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])));
              float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])));
              float marginAxisRow = (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]));
              float marginAxisColumn = (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]));

              // Set the resolved resolution in the node's layout.
              CSSDirection direction = resolveDirection(node, parentDirection);
              node.layout.direction = direction;

              // For content (text) nodes, determine the dimensions based on the text contents.
              if (isMeasureDefined(node)) {
            float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow;
            float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn;

            if (widthMeasureMode == CSSMeasureMode.Exactly && heightMeasureMode == CSSMeasureMode.Exactly) {

              // Don't bother sizing the text if both dimensions are already defined.
              node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, availableWidth - marginAxisRow);
//.........这里部分代码省略.........
开发者ID:emilsjolander,项目名称:css-layout,代码行数:101,代码来源:LayoutEngine.cs


注:本文中的CSSNode.measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。