Example #1
0
  /**
   * Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it
   * represents). The results of the layout (the offset and span for each children) are placed in
   * the given arrays which represent the allocations to the children along the minor axis.
   *
   * @param targetSpan the total span given to the view, which would be used to layout the children.
   * @param axis the axis being layed out
   * @param offsets the offsets from the origin of the view for each of the child views; this is a
   *     return value and is filled in by the implementation of this method
   * @param spans the span of each child view; this is a return value and is filled in by the
   *     implementation of this method
   */
  protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
    int n = getViewCount();
    Object key = (axis == X_AXIS) ? CSS.Attribute.WIDTH : CSS.Attribute.HEIGHT;
    for (int i = 0; i < n; i++) {
      View v = getView(i);
      int min = (int) v.getMinimumSpan(axis);
      int max;

      // check for percentage span
      AttributeSet a = v.getAttributes();
      CSS.LengthValue lv = (CSS.LengthValue) a.getAttribute(key);
      if ((lv != null) && lv.isPercentage()) {
        // bound the span to the percentage specified
        min = Math.max((int) lv.getValue(targetSpan), min);
        max = min;
      } else {
        max = (int) v.getMaximumSpan(axis);
      }

      // assign the offset and span for the child
      if (max < targetSpan) {
        // can't make the child this wide, align it
        float align = v.getAlignment(axis);
        offsets[i] = (int) ((targetSpan - max) * align);
        spans[i] = max;
      } else {
        // make it the target width, or as small as it can get.
        offsets[i] = 0;
        spans[i] = Math.max(min, targetSpan);
      }
    }
  }
Example #2
0
 /**
  * Adjust the given requirements to the CSS width or height if it is specified along the
  * applicable axis. Return true if the size is exactly specified, false if the span is not
  * specified in an attribute or the size specified is a percentage.
  */
 static boolean spanSetFromAttributes(
     int axis, SizeRequirements r, CSS.LengthValue cssWidth, CSS.LengthValue cssHeight) {
   if (axis == X_AXIS) {
     if ((cssWidth != null) && (!cssWidth.isPercentage())) {
       r.minimum = r.preferred = r.maximum = (int) cssWidth.getValue();
       return true;
     }
   } else {
     if ((cssHeight != null) && (!cssHeight.isPercentage())) {
       r.minimum = r.preferred = r.maximum = (int) cssHeight.getValue();
       return true;
     }
   }
   return false;
 }