Changeset 5056

Show
Ignore:
Timestamp:
07/04/08 09:17:04 (6 months ago)
Author:
joonas.lehtinen@…
Message:

Made marginal and spacing calculations a lot more robust. Related to #1904

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebContent/ITMILL/themes/default/orderedlayout/orderedlayout.css

    r5040 r5056  
    1 .i-orderedlayout-margin-top { 
     1. 
     2/* Ordered layout spacing and margins are currently fixed. 
     3   This is considered to be a bug. For more info, see 
     4   http://dev.itmill.com/ticket/1904 
     5 
     6i-orderedlayout-margin-top { 
    27        padding-top: 15px; 
    38} 
     
    1924} 
    2025 
     26*/ 
     27 
    2128/* Placing error indicator right after the widget with empty caption */ 
    2229.i-orderedlayout-w:after, .i-orderedlayout-c:after { 
  • trunk/WebContent/ITMILL/themes/default/styles.css

    r5042 r5056  
    698698        white-space: nowrap; 
    699699} 
    700 .i-orderedlayout-margin-top { 
     700. 
     701/* Ordered layout spacing and margins are currently fixed. 
     702   This is considered to be a bug. For more info, see 
     703   http://dev.itmill.com/ticket/1904 
     704 
     705i-orderedlayout-margin-top { 
    701706        padding-top: 15px; 
    702707} 
     
    717722        padding-left: 8px; 
    718723} 
     724 
     725*/ 
    719726 
    720727/* Placing error indicator right after the widget with empty caption */ 
  • trunk/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java

    r5055 r5056  
    1919import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener; 
    2020import com.itmill.toolkit.terminal.gwt.client.Paintable; 
    21 import com.itmill.toolkit.terminal.gwt.client.StyleConstants; 
    2221import com.itmill.toolkit.terminal.gwt.client.UIDL; 
    2322import com.itmill.toolkit.terminal.gwt.client.Util; 
     
    4039    public static final int ORIENTATION_HORIZONTAL = 1; 
    4140 
    42     // TODO Read this from CSS as in #1904 
    43     private static final int SPACING_SIZE = 8; 
     41    // TODO Read these from CSS as in #1904 
     42    private static final int HSPACING = 8; 
     43    private static final int VSPACING = 8; 
     44    private static final int MARGIN_TOP = 15; 
     45    private static final int MARGIN_BOTTOM = 15; 
     46    private static final int MARGIN_LEFT = 18; 
     47    private static final int MARGIN_RIGHT = 18; 
    4448 
    4549    int orientationMode = ORIENTATION_VERTICAL; 
     
    203207        updateOrientation(uidl); 
    204208 
    205         // Ensure correct implementation 
    206         if (client.updateComponent(this, uidl, false)) { 
    207             return; 
    208         } 
    209  
    210209        // Handle layout margins 
    211210        if (margins.getBitMask() != uidl.getIntAttribute("margins")) { 
     
    215214        // Handle component spacing later in handleAlignments() method 
    216215        hasComponentSpacing = uidl.getBooleanAttribute("spacing"); 
     216 
     217        // Update sizes, ... 
     218        if (client.updateComponent(this, uidl, false)) { 
     219            return; 
     220        } 
    217221 
    218222        // Collect the list of contained widgets after this update 
     
    318322        if (width == null || "".equals(width)) { 
    319323            DOM.setStyleAttribute(margin, "width", ""); 
     324 
    320325            if (fixedCellSize && orientationMode == ORIENTATION_HORIZONTAL) { 
    321326                removeFixedSizes(); 
    322327            } 
    323328        } else { 
    324             DOM.setStyleAttribute(margin, "width", "100%"); 
     329 
     330            // Calculate margin pixel width 
     331            int cw = DOM.getElementPropertyInt(root, "offsetWidth"); 
     332            cw -= margins.hasLeft() ? MARGIN_LEFT : 0; 
     333            cw -= margins.hasRight() ? MARGIN_RIGHT : 0; 
     334            DOM.setStyleAttribute(margin, "width", cw + "px"); 
     335 
    325336            if (orientationMode == ORIENTATION_HORIZONTAL) { 
    326337                fixedCellSize = true; 
     
    347358            } 
    348359        } else { 
    349             DOM.setStyleAttribute(margin, "height", "100%"); 
     360 
     361            // Calculate margin pixel height 
     362            int ch = DOM.getElementPropertyInt(root, "offsetHeight"); 
     363            ch -= margins.hasTop() ? MARGIN_TOP : 0; 
     364            ch -= margins.hasBottom() ? MARGIN_BOTTOM : 0; 
     365            DOM.setStyleAttribute(margin, "height", ch + "px"); 
     366 
     367            // Turn on vertical orientation mode if needed 
    350368            if (orientationMode == ORIENTATION_VERTICAL) { 
    351369                fixedCellSize = true; 
     
    399417        } 
    400418 
    401         DOM.setStyleAttribute(margin, 
    402                 (orientationMode == ORIENTATION_HORIZONTAL) ? "width" 
    403                         : "height", "100%"); 
    404  
    405         int size = DOM.getElementPropertyInt(margin, 
     419        // Calculate the space for fixed contents minus marginals 
     420        int size = DOM.getElementPropertyInt(root, 
    406421                (orientationMode == ORIENTATION_HORIZONTAL) ? "offsetWidth" 
    407422                        : "offsetHeight"); 
     423        if (orientationMode == ORIENTATION_HORIZONTAL) { 
     424            size -= margins.hasLeft() ? MARGIN_LEFT : 0; 
     425            size -= margins.hasRight() ? MARGIN_RIGHT : 0; 
     426        } else { 
     427            size -= margins.hasTop() ? MARGIN_TOP : 0; 
     428            size -= margins.hasBottom() ? MARGIN_BOTTOM : 0; 
     429        } 
    408430 
    409431        // Horizontal layouts need fixed mode tables 
     
    417439        int numChild = childWidgets.size(); 
    418440        if (hasComponentSpacing) { 
    419             size -= SPACING_SIZE * (numChild - 1); 
     441            size -= ((orientationMode == ORIENTATION_HORIZONTAL) ? HSPACING 
     442                    : VSPACING) 
     443                    * (numChild - 1); 
    420444        } 
    421445 
     
    459483 
    460484        // Update margin classes 
    461         setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, 
    462                 margins.hasTop()); 
    463         setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT, 
    464                 margins.hasRight()); 
    465         setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_BOTTOM, 
    466                 margins.hasBottom()); 
    467         setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_LEFT, 
    468                 margins.hasLeft()); 
     485        DOM.setStyleAttribute(margin, "paddingTop", 
     486                margins.hasTop() ? MARGIN_TOP + "px" : "0"); 
     487        DOM.setStyleAttribute(margin, "paddingLeft", 
     488                margins.hasLeft() ? MARGIN_LEFT + "px" : "0"); 
     489        DOM.setStyleAttribute(margin, "paddingBottom", 
     490                margins.hasBottom() ? MARGIN_BOTTOM + "px" : "0"); 
     491        DOM.setStyleAttribute(margin, "paddingRight", 
     492                margins.hasRight() ? MARGIN_RIGHT + "px" : "0"); 
     493 
     494        // Update calculated height if needed 
     495        String currentMarginHeight = DOM.getStyleAttribute(margin, "height"); 
     496        if (currentMarginHeight != null && !"".equals(currentMarginHeight)) { 
     497            int ch = DOM.getElementPropertyInt(root, "offsetHeight"); 
     498            ch -= margins.hasTop() ? MARGIN_TOP : 0; 
     499            ch -= margins.hasBottom() ? MARGIN_BOTTOM : 0; 
     500            DOM.setStyleAttribute(margin, "height", ch + "px"); 
     501        } 
     502        String currentMarginWidth = DOM.getStyleAttribute(margin, "width"); 
     503        if (currentMarginWidth != null && !"".equals(currentMarginWidth)) { 
     504            int cw = DOM.getElementPropertyInt(root, "offsetWidth"); 
     505            cw -= margins.hasLeft() ? MARGIN_LEFT : 0; 
     506            cw -= margins.hasRight() ? MARGIN_RIGHT : 0; 
     507            DOM.setStyleAttribute(margin, "width", cw + "px"); 
     508        } 
    469509 
    470510        // Update child layouts 
     
    703743        /** Set class for spacing */ 
    704744        void setSpacingEnabled(boolean b) { 
    705             setStyleName( 
    706                     getElement(), 
    707                     CLASSNAME 
    708                             + "-" 
    709                             + (orientationMode == ORIENTATION_HORIZONTAL ? StyleConstants.HORIZONTAL_SPACING 
    710                                     : StyleConstants.VERTICAL_SPACING), b); 
    711         } 
    712  
     745            DOM.setStyleAttribute(getElement(), 
     746                    orientationMode == ORIENTATION_HORIZONTAL ? "paddingLeft" 
     747                            : "marginTop", 
     748                    b ? (orientationMode == ORIENTATION_HORIZONTAL ? HSPACING 
     749                            : VSPACING) 
     750                            + "px" : "0"); 
     751        } 
    713752    } 
    714753