Esempio n. 1
0
 /**
  * Calculate the requirements of the block along the major axis (i.e. the axis along with it
  * tiles). This is implemented to provide the superclass behavior and then adjust it if the CSS
  * width or height attribute is specified and applicable to the axis.
  */
 protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
   if (r == null) {
     r = new SizeRequirements();
   }
   if (!spanSetFromAttributes(axis, r, cssWidth, cssHeight)) {
     r = super.calculateMajorAxisRequirements(axis, r);
   } else {
     // Offset by the margins so that pref/min/max return the
     // right value.
     SizeRequirements parentR = super.calculateMajorAxisRequirements(axis, null);
     int margin =
         (axis == X_AXIS) ? getLeftInset() + getRightInset() : getTopInset() + getBottomInset();
     r.minimum -= margin;
     r.preferred -= margin;
     r.maximum -= margin;
     constrainSize(axis, r, parentR);
   }
   return r;
 }
Esempio n. 2
0
  /**
   * Calculate the requirements of the block along the minor axis (i.e. the axis orthogonal to the
   * axis along with it tiles). This is implemented to provide the superclass behavior and then
   * adjust it if the CSS width or height attribute is specified and applicable to the axis.
   */
  protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
    if (r == null) {
      r = new SizeRequirements();
    }

    if (!spanSetFromAttributes(axis, r, cssWidth, cssHeight)) {

      /*
       * The requirements were not directly specified by attributes, so
       * compute the aggregate of the requirements of the children.  The
       * children that have a percentage value specified will be treated
       * as completely stretchable since that child is not limited in any
       * way.
       */
      /*
      int min = 0;
      long pref = 0;
      int max = 0;
      int n = getViewCount();
      for (int i = 0; i < n; i++) {
          View v = getView(i);
          min = Math.max((int) v.getMinimumSpan(axis), min);
          pref = Math.max((int) v.getPreferredSpan(axis), pref);
          if (
          max = Math.max((int) v.getMaximumSpan(axis), max);

      }
      r.preferred = (int) pref;
      r.minimum = min;
      r.maximum = max;
      */
      r = super.calculateMinorAxisRequirements(axis, r);
    } else {
      // Offset by the margins so that pref/min/max return the
      // right value.
      SizeRequirements parentR = super.calculateMinorAxisRequirements(axis, null);
      int margin =
          (axis == X_AXIS) ? getLeftInset() + getRightInset() : getTopInset() + getBottomInset();
      r.minimum -= margin;
      r.preferred -= margin;
      r.maximum -= margin;
      constrainSize(axis, r, parentR);
    }

    /*
     * Set the alignment based upon the CSS properties if it is
     * specified.  For X_AXIS this would be text-align, for
     * Y_AXIS this would be vertical-align.
     */
    if (axis == X_AXIS) {
      Object o = getAttributes().getAttribute(CSS.Attribute.TEXT_ALIGN);
      if (o != null) {
        String align = o.toString();
        if (align.equals("center")) {
          r.alignment = 0.5f;
        } else if (align.equals("right")) {
          r.alignment = 1.0f;
        } else {
          r.alignment = 0.0f;
        }
      }
    }
    // Y_AXIS TBD
    return r;
  }