Added a method to allow 'snap closed' behavior in SplitLayoutPanel. This can be used with or without setting the widget minimum size to completely close a widget's slider when the user drags past a certain width. Review at http://gwt-code-reviews.appspot.com/1657803 Review by: jlabanca@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10899 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java b/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java index aaca39f..e2265de 100644 --- a/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java +++ b/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java
@@ -100,9 +100,9 @@ private final boolean reverse; private int minSize; - + private int snapClosedSize = -1; private double centerSize, syncedCenterSize; - + private boolean toggleDisplayAllowed = false; private double lastClick = 0; @@ -195,7 +195,11 @@ // minSize value. setAssociatedWidgetSize((int) layout.size); } - + + public void setSnapClosedSize(int snapClosedSize) { + this.snapClosedSize = snapClosedSize; + } + public void setToggleDisplayAllowed(boolean allowed) { this.toggleDisplayAllowed = allowed; } @@ -230,7 +234,9 @@ size = maxSize; } - if (size < minSize) { + if (snapClosedSize > 0 && size < snapClosedSize) { + size = 0; + } else if (size < minSize) { size = minSize; } @@ -392,11 +398,35 @@ splitter.setMinSize(minSize); } } - + + /** + * Sets a size below which the slider will close completely. This can be used + * in conjunction with {@link #setWidgetMinSize} to provide a speed-bump + * effect where the slider will stick to a preferred minimum size before + * closing completely. + * + * <p> + * This method has no effect for the {@link DockLayoutPanel.Direction#CENTER} + * widget. + * </p> + * + * @param child the child whose slider should snap closed + * @param snapClosedSize the width below which the widget will close or + * -1 to disable. + */ + public void setWidgetSnapClosedSize(Widget child, int snapClosedSize) { + assertIsChild(child); + Splitter splitter = getAssociatedSplitter(child); + // The splitter is null for the center element. + if (splitter != null) { + splitter.setSnapClosedSize(snapClosedSize); + } + } + /** * Sets whether or not double-clicking on the splitter should toggle the * display of the widget. - * + * * @param child the child whose display toggling will be allowed or not. * @param allowed whether or not display toggling is allowed for this widget */