Reviewers: zundel, jgw, jlabanca,

Description:
Add support for arbitrary units in SplitLayoutPanel


Please review this at http://gwt-code-reviews.appspot.com/1244801/show

Affected files:
  M user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java


Index: user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java (revision 9475) +++ user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java (working copy)
@@ -60,7 +60,7 @@
   class HSplitter extends Splitter {
     public HSplitter(Widget target, boolean reverse) {
       super(target, reverse);
-      getElement().getStyle().setPropertyPx("width", splitterSize);
+ getElement().getStyle().setProperty("width", String.valueOf(splitterSize) + getUnit());
       setStyleName("gwt-SplitLayoutPanel-HDragger");
     }

@@ -138,14 +138,20 @@

         case Event.ONMOUSEMOVE:
           if (mouseDown) {
-            int size;
+            int pxSize;
             if (reverse) {
-              size = getTargetPosition() + getTargetSize()
+              pxSize = getTargetPosition() + getTargetSize()
                   - getEventPosition(event) - offset;
             } else {
- size = getEventPosition(event) - getTargetPosition() - offset; + pxSize = getEventPosition(event) - getTargetPosition() - offset;
             }
-            setAssociatedWidgetSize(size);
+
+            // Force the old values to be >= 1 in calculations to avoid
+            // getting stuck in 0.
+ double oldSize = Math.max(((LayoutData)target.getLayoutData()).size, 1);
+            int oldPxSize = Math.max(getTargetSize(), 1);
+
+            setAssociatedWidgetSize(oldSize * pxSize / oldPxSize);
             event.preventDefault();
           }
           break;
@@ -169,7 +175,7 @@

     protected abstract int getTargetSize();

-    private void setAssociatedWidgetSize(int size) {
+    private void setAssociatedWidgetSize(double size) {
       if (size < minSize) {
         size = minSize;
       }
@@ -198,7 +204,7 @@
   class VSplitter extends Splitter {
     public VSplitter(Widget target, boolean reverse) {
       super(target, reverse);
-      getElement().getStyle().setPropertyPx("height", splitterSize);
+ getElement().getStyle().setProperty("height", String.valueOf(splitterSize) + getUnit());
       setStyleName("gwt-SplitLayoutPanel-VDragger");
     }

@@ -248,7 +254,18 @@
    * @param splitterSize the size of the splitter in pixels
    */
   public SplitLayoutPanel(int splitterSize) {
-    super(Unit.PX);
+    this(splitterSize, Unit.PX);
+  }
+
+  /**
+ * Construct a new {...@link SplitLayoutPanel} with the specified splitter size
+   * and layout unit.
+   *
+   * @param splitterSize the size of the splitter
+   * @param layoutUnit the unit to be used for layout
+   */
+  public SplitLayoutPanel(int splitterSize, Unit layoutUnit) {
+    super(layoutUnit);
     this.splitterSize = splitterSize;
     setStyleName("gwt-SplitLayoutPanel");



--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to