Created
October 10, 2018 18:46
-
-
Save branflake2267/0cf0c5cbd179f541ae4da39cb1f619b1 to your computer and use it in GitHub Desktop.
When the HorizontalLayoutContainer clips the widgets workaround.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.gwt.core.client.EntryPoint; | |
| import com.google.gwt.user.client.ui.RootPanel; | |
| import com.sencha.gxt.core.client.util.Margins; | |
| import com.sencha.gxt.widget.core.client.button.TextButton; | |
| import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer; | |
| import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer.HorizontalLayoutData; | |
| import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; | |
| import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; | |
| import com.sencha.gxt.widget.core.client.form.FieldLabel; | |
| import com.sencha.gxt.widget.core.client.form.FieldSet; | |
| import com.sencha.gxt.widget.core.client.form.FormPanel.LabelAlign; | |
| public class HlcLayoutIssue implements EntryPoint { | |
| @Override | |
| public void onModuleLoad() { | |
| TextButton button = new TextButton("Button"); | |
| button.setWidth("70px"); | |
| FieldLabel fieldLabel1 = new FieldLabel(); | |
| fieldLabel1.setLabelAlign(LabelAlign.TOP); | |
| fieldLabel1.setLabelSeparator(""); | |
| fieldLabel1.add(button); | |
| // ~~~ workaround | |
| //fieldLabel1.getElement().getStyle().setOverflow(Overflow.VISIBLE); | |
| HorizontalLayoutContainer hlcInner = new HorizontalLayoutContainer(); | |
| hlcInner.setBorders(true); | |
| hlcInner.setHeight("50px"); | |
| hlcInner.setWidth(200); | |
| hlcInner.add(fieldLabel1, new HorizontalLayoutData(70, 30, new Margins(15, 12, 0, 12))); | |
| VerticalLayoutContainer vlcInner = new VerticalLayoutContainer(); | |
| vlcInner.add(hlcInner, new VerticalLayoutData(-1, -1)); | |
| HorizontalLayoutContainer hlc = new HorizontalLayoutContainer(); | |
| hlc.setHeight("130"); | |
| hlc.add(vlcInner, new HorizontalLayoutData(-1, -1)); | |
| FieldSet fieldSet = new FieldSet(); | |
| fieldSet.setHeading("Heading"); | |
| fieldSet.add(hlc); | |
| VerticalLayoutContainer vlc = new VerticalLayoutContainer(); | |
| vlc.add(fieldSet, new VerticalLayoutData(1165, -1, new Margins(0, 10, 5, 10))); | |
| vlc.setHeight("500"); | |
| vlc.setWidth("1224"); | |
| RootPanel.get().add(vlc); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Sencha GXT 4.0.3 - Sencha for GWT | |
| * Copyright (c) 2006-2018, Sencha Inc. | |
| * | |
| * [email protected] | |
| * http://www.sencha.com/products/gxt/license/ | |
| * | |
| * ================================================================================ | |
| * Commercial License | |
| * ================================================================================ | |
| * This version of Sencha GXT is licensed commercially and is the appropriate | |
| * option for the vast majority of use cases. | |
| * | |
| * Please see the Sencha GXT Licensing page at: | |
| * http://www.sencha.com/products/gxt/license/ | |
| * | |
| * For clarification or additional options, please contact: | |
| * [email protected] | |
| * ================================================================================ | |
| * | |
| * | |
| * | |
| * | |
| * | |
| * | |
| * | |
| * | |
| * ================================================================================ | |
| * Disclaimer | |
| * ================================================================================ | |
| * THIS SOFTWARE IS DISTRIBUTED "AS-IS" WITHOUT ANY WARRANTIES, CONDITIONS AND | |
| * REPRESENTATIONS WHETHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE | |
| * IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, MERCHANTABLE QUALITY, | |
| * FITNESS FOR A PARTICULAR PURPOSE, DURABILITY, NON-INFRINGEMENT, PERFORMANCE AND | |
| * THOSE ARISING BY STATUTE OR FROM CUSTOM OR USAGE OF TRADE OR COURSE OF DEALING. | |
| * ================================================================================ | |
| */ | |
| package com.sencha.gxt.widget.core.client.container; | |
| import java.util.logging.Logger; | |
| import com.google.gwt.core.client.Scheduler; | |
| import com.google.gwt.dom.client.Document; | |
| import com.google.gwt.dom.client.Style.Overflow; | |
| import com.google.gwt.dom.client.Style.Position; | |
| import com.google.gwt.dom.client.Style.Unit; | |
| import com.google.gwt.event.dom.client.HasScrollHandlers; | |
| import com.google.gwt.event.dom.client.ScrollEvent; | |
| import com.google.gwt.event.dom.client.ScrollHandler; | |
| import com.google.gwt.event.shared.HandlerRegistration; | |
| import com.google.gwt.uibinder.client.UiChild; | |
| import com.google.gwt.uibinder.client.UiConstructor; | |
| import com.google.gwt.user.client.DOM; | |
| import com.google.gwt.user.client.Event; | |
| import com.google.gwt.user.client.ui.HasWidgets; | |
| import com.google.gwt.user.client.ui.IndexedPanel; | |
| import com.google.gwt.user.client.ui.IsWidget; | |
| import com.google.gwt.user.client.ui.Widget; | |
| import com.sencha.gxt.core.client.GXT; | |
| import com.sencha.gxt.core.client.GXTLogConfiguration; | |
| import com.sencha.gxt.core.client.Style.Side; | |
| import com.sencha.gxt.core.client.dom.DefaultScrollSupport; | |
| import com.sencha.gxt.core.client.dom.HasScrollSupport; | |
| import com.sencha.gxt.core.client.dom.ScrollSupport; | |
| import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; | |
| import com.sencha.gxt.core.client.dom.XDOM; | |
| import com.sencha.gxt.core.client.gestures.ScrollGestureRecognizer; | |
| import com.sencha.gxt.core.client.util.Margins; | |
| import com.sencha.gxt.core.client.util.Rectangle; | |
| import com.sencha.gxt.core.client.util.Size; | |
| /** | |
| * <p> | |
| * A layout container that lays out its children in a single row. The layout properties for each child are specified | |
| * using {@link HorizontalLayoutData}. | |
| * </p> | |
| * | |
| * <p> | |
| * Code Snippet: | |
| * </p> | |
| * | |
| * <pre> | |
| * <code> | |
| * HorizontalLayoutContainer c = new HorizontalLayoutContainer(); | |
| * HorizontalLayoutData layoutData = new HorizontalLayoutData(100, 100, new Margins(5)); | |
| * c.add(new TextButton("Button 1"), layoutData); | |
| * c.add(new TextButton("Button 2"), layoutData); | |
| * c.add(new TextButton("Button 3"), layoutData); | |
| * RootPanel.get().add(c); | |
| * </code> | |
| * </pre> | |
| */ | |
| public class HorizontalLayoutContainer extends InsertResizeContainer implements HasScrollHandlers, HasScrollSupport { | |
| /** | |
| * Specifies parameters that control the layout of the widget in the container. | |
| */ | |
| public static class HorizontalLayoutData extends MarginData implements HasWidth, HasHeight, LayoutData { | |
| protected double height = -1d; | |
| protected double width = -1d; | |
| /** | |
| * Creates horizontal layout parameters with default values for height (-1) and width (-1) and margins (none). | |
| */ | |
| @UiConstructor | |
| public HorizontalLayoutData() { | |
| } | |
| /** | |
| * Creates horizontal layout parameters with the specified values. | |
| * | |
| * @param width the width specification (see {@link HasWidth}) | |
| * @param height the height specification (see {@link HasHeight}) | |
| */ | |
| public HorizontalLayoutData(double width, double height) { | |
| setWidth(width); | |
| setHeight(height); | |
| } | |
| /** | |
| * Creates horizontal layout parameters with the specified values. | |
| * | |
| * @param width the width specification (see {@link HasWidth}) | |
| * @param height the height specification (see {@link HasHeight}) | |
| * @param margins the margin specification (see {@link HasMargins}) | |
| */ | |
| public HorizontalLayoutData(double width, double height, Margins margins) { | |
| super(margins); | |
| setWidth(width); | |
| setHeight(height); | |
| } | |
| @Override | |
| public double getHeight() { | |
| return height; | |
| } | |
| @Override | |
| public double getWidth() { | |
| return width; | |
| } | |
| @Override | |
| public void setHeight(double height) { | |
| this.height = height; | |
| } | |
| @Override | |
| public void setWidth(double width) { | |
| this.width = width; | |
| } | |
| } | |
| protected boolean adjustForScroll; | |
| protected boolean secondPassRequired; | |
| protected ScrollSupport scrollSupport; | |
| protected ScrollGestureRecognizer scrollGestureRecognizer; | |
| protected static Logger logger = Logger.getLogger(HorizontalLayoutContainer.class.getName()); | |
| /** | |
| * Creates a horizontal layout container. | |
| */ | |
| public HorizontalLayoutContainer() { | |
| setElement(Document.get().createDivElement()); | |
| getContainerTarget().makePositionable(false); | |
| } | |
| /** | |
| * Adds a widget to the horizontal layout container with the specified layout parameters. | |
| * | |
| * @param child the widget to add to the layout container | |
| * @param layoutData the parameters that describe how to lay out the widget | |
| */ | |
| @UiChild(tagname = "child") | |
| public void add(IsWidget child, HorizontalLayoutData layoutData) { | |
| if (child != null) { | |
| child.asWidget().setLayoutData(layoutData); | |
| } | |
| super.add(child); | |
| } | |
| @Override | |
| public HandlerRegistration addScrollHandler(ScrollHandler handler) { | |
| DOM.sinkEvents(getContainerTarget(), Event.ONSCROLL | DOM.getEventsSunk(getContainerTarget())); | |
| return addDomHandler(handler, ScrollEvent.getType()); | |
| } | |
| /** | |
| * Returns the scroll mode from the container's ScrollSupport instance. | |
| * | |
| * @return the scroll mode | |
| */ | |
| public ScrollMode getScrollMode() { | |
| return getScrollSupport().getScrollMode(); | |
| } | |
| @Override | |
| public ScrollSupport getScrollSupport() { | |
| if (scrollSupport == null) { | |
| scrollSupport = new DefaultScrollSupport(getContainerTarget()); | |
| } | |
| if (GXT.isTouch() && GXT.isSafari()) { | |
| initScrollGestureRecognizer(); | |
| } | |
| return scrollSupport; | |
| } | |
| /** | |
| * Inserts the widget at the specified index in the horizontal layout container. | |
| * | |
| * @param w the widget to insert in the layout container | |
| * @param beforeIndex the insert index | |
| * @param layoutData the parameters that describe how to lay out the widget | |
| */ | |
| public void insert(IsWidget w, int beforeIndex, HorizontalLayoutData layoutData) { | |
| if (w != null) { | |
| w.asWidget().setLayoutData(layoutData); | |
| } | |
| super.insert(w, beforeIndex); | |
| } | |
| /** | |
| * Returns true if the container reserves space for the scroll bar. | |
| * | |
| * @return true if the container reserves space for the scroll bar | |
| */ | |
| public boolean isAdjustForScroll() { | |
| return adjustForScroll; | |
| } | |
| /** | |
| * True to request that the container reserve space for the scroll bar (defaults to false). | |
| * | |
| * @param adjustForScroll true to reserve space for the scroll bar | |
| */ | |
| public void setAdjustForScroll(boolean adjustForScroll) { | |
| this.adjustForScroll = adjustForScroll; | |
| } | |
| /** | |
| * Sets the scroll mode on the container's ScrollSupport instance. The scroll mode will not be preserved if | |
| * {@link #setScrollSupport(ScrollSupport)} is called AFTER calling this method. | |
| * | |
| * @param scrollMode the scroll mode | |
| */ | |
| public void setScrollMode(ScrollMode scrollMode) { | |
| getScrollSupport().setScrollMode(scrollMode); | |
| } | |
| @Override | |
| public void setScrollSupport(ScrollSupport support) { | |
| this.scrollSupport = support; | |
| if (GXT.isTouch() && GXT.isSafari()) { | |
| initScrollGestureRecognizer(); | |
| } | |
| } | |
| @Override | |
| protected void doLayout() { | |
| Size size = getContainerTarget().getStyleSize(); | |
| if (GXTLogConfiguration.loggingIsEnabled()) { | |
| logger.finest(getId() + " doLayout size: " + size); | |
| } | |
| int w = size.getWidth() - (adjustForScroll ? XDOM.getScrollBarWidth() : 0); | |
| int h = size.getHeight(); | |
| int pw = w; | |
| // If 0, then be sure a width is not set. | |
| if (w == 0) { | |
| w = -1; | |
| } | |
| // If 0, then be sure a height is not set. | |
| if (h == 0) { | |
| h = -1; | |
| } | |
| int count = getWidgetCount(); | |
| // some columns can be percentages while others are fixed | |
| // so we need to make 2 passes | |
| for (int i = 0; i < count; i++) { | |
| Widget c = getWidget(i); | |
| if (!c.isVisible()) { | |
| continue; | |
| } | |
| c.getElement().getStyle().setPosition(Position.ABSOLUTE); | |
| double width = -1; | |
| Object d = c.getLayoutData(); | |
| if (d instanceof HasWidth) { | |
| width = ((HasWidth) d).getWidth(); | |
| } | |
| if (width > 1) { | |
| pw -= width; | |
| } else if (width == -1) { | |
| if ((c instanceof HasWidgets || c instanceof IndexedPanel) && !secondPassRequired) { | |
| secondPassRequired = true; | |
| Scheduler.get().scheduleDeferred(layoutCommand); | |
| return; | |
| } | |
| pw -= c.getOffsetWidth(); | |
| pw -= getLeftRightMargins(c); | |
| } else if (width < -1) { | |
| pw -= (w + width); | |
| pw -= getLeftRightMargins(c); | |
| } | |
| } | |
| secondPassRequired = false; | |
| pw = pw < 0 ? 0 : pw; | |
| int x = getContainerTarget().getPadding(Side.LEFT); | |
| int sTop = getContainerTarget().getPadding(Side.TOP); | |
| for (int i = 0; i < count; i++) { | |
| Widget c = getWidget(i); | |
| if (!c.isVisible()) { | |
| continue; | |
| } | |
| c.getElement().getStyle().setMargin(0, Unit.PX); | |
| double width = -1; | |
| double height = -1; | |
| Object d = c.getLayoutData(); | |
| if (d instanceof HasWidth) { | |
| width = ((HasWidth) d).getWidth(); | |
| } | |
| if (d instanceof HasHeight) { | |
| height = ((HasHeight) d).getHeight(); | |
| } | |
| if (height >= 0 && height <= 1) { | |
| height = height * h; | |
| } else if (height < -1) { | |
| height = h + height; | |
| } | |
| if (width >= 0 && width <= 1) { | |
| width = width * pw; | |
| } else if (width < -1) { | |
| width = w + width; | |
| } | |
| int tx = x; | |
| int ty = sTop; | |
| int tw = (int) Math.floor(width); | |
| int th = (int) Math.floor(height); | |
| Margins m = null; | |
| if (d instanceof HasMargins) { | |
| m = ((HasMargins) d).getMargins(); | |
| if (m != null) { | |
| tx += m.getLeft(); | |
| ty += m.getTop(); | |
| if (th != -1) { | |
| th -= m.getTop() + m.getBottom(); | |
| } | |
| if (tw != -1) { | |
| tw -= m.getLeft() + m.getRight(); | |
| } | |
| } | |
| } | |
| applyLayout(c, new Rectangle(tx, ty, tw, th)); | |
| if (tw == -1) { | |
| tw = c.getOffsetWidth(); | |
| } | |
| x += tw + (m != null ? (m.getLeft() + m.getRight()) : 0); | |
| } | |
| } | |
| @Override | |
| protected void onInsert(int index, Widget child) { | |
| // no op, super applies margins | |
| // ~~~ workaround | |
| child.getElement().getStyle().setOverflow(Overflow.VISIBLE); | |
| } | |
| protected void initScrollGestureRecognizer() { | |
| if (scrollGestureRecognizer == null) { | |
| scrollGestureRecognizer = new ScrollGestureRecognizer(getContainerTarget()) { | |
| @Override | |
| protected ScrollDirection getDirection() { | |
| ScrollMode scrollMode = getScrollMode(); | |
| switch (scrollMode) { | |
| case AUTOX: | |
| return ScrollDirection.HORIZONTAL; | |
| case AUTOY: | |
| return ScrollDirection.VERTICAL; | |
| } | |
| return ScrollDirection.BOTH; | |
| } | |
| }; | |
| addGestureRecognizer(scrollGestureRecognizer); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Directions to use this workaround.