use of org.gwtproject.layout.client.Layout.Layer in project gwtproject by treblereel.
the class LayoutGwt2Test method testFillParent.
/**
* Test that fillParent() works properly when the outer div is a child of another div, and that it
* correctly follows that div's size.
*/
@DoNotRunWith(Platform.HtmlUnitLayout)
public void testFillParent() {
// We don't use the default elements created in gwtSetUp() because we need
// to test the behavior when the layout is contained by an element other
// than the <body>.
Document doc = Document.get();
DivElement container = doc.createDivElement();
DivElement parent = doc.createDivElement();
DivElement child = doc.createDivElement();
child.setInnerHTML(" ");
doc.getBody().appendChild(container);
container.appendChild(parent);
// The container has to be position:relative so that it serves as an offset
// parent.
container.getStyle().setPosition(Position.RELATIVE);
container.getStyle().setWidth(128, PX);
container.getStyle().setHeight(256, PX);
Layout layout = new Layout(parent);
layout.onAttach();
Layout.Layer layer = layout.attachChild(child);
layer.setTopBottom(0, PX, 0, PX);
layer.setLeftRight(0, PX, 0, PX);
layout.fillParent();
layout.layout();
// Test 128x256.
assertEquals(128, container.getOffsetWidth());
assertEquals(256, container.getOffsetHeight());
assertEquals(128, parent.getOffsetWidth());
assertEquals(256, parent.getOffsetHeight());
assertEquals(128, child.getOffsetWidth());
assertEquals(256, child.getOffsetHeight());
// Expand to 256x256. The layout should react automatically.
container.getStyle().setWidth(256, PX);
container.getStyle().setHeight(128, PX);
assertEquals(256, container.getOffsetWidth());
assertEquals(256, parent.getOffsetWidth());
assertEquals(256, child.getOffsetWidth());
layout.onDetach();
}
use of org.gwtproject.layout.client.Layout.Layer in project gwtproject by treblereel.
the class CustomScrollPanel method add.
/**
* Add a widget to the panel in the specified layer. Note that this method does not do the logical
* attach.
*
* @param w the widget to add, or null to clear the widget
* @param toReplace the widget to replace
* @param layer the layer in which the existing widget is placed
* @return the layer in which the new widget is placed, or null if no widget
*/
private Layer add(IsWidget w, IsWidget toReplace, Layer layer) {
// Validate.
if (w == toReplace) {
return layer;
}
// Detach new child.
if (w != null) {
w.asWidget().removeFromParent();
}
// Remove old child.
if (toReplace != null) {
remove(toReplace);
}
Layer toRet = null;
if (w != null) {
// Physical attach.
toRet = layout.attachChild(w.asWidget().getElement());
adopt(w.asWidget());
}
return toRet;
}
use of org.gwtproject.layout.client.Layout.Layer in project gwtproject by treblereel.
the class DeckLayoutPanel method remove.
@Override
public boolean remove(Widget w) {
boolean removed = super.remove(w);
if (removed) {
Layer layer = (Layer) w.getLayoutData();
layout.removeChild(layer);
w.setLayoutData(null);
if (visibleWidget == w) {
visibleWidget = null;
}
if (hidingWidget == w) {
hidingWidget = null;
}
if (lastVisibleWidget == w) {
lastVisibleWidget = null;
}
}
return removed;
}
use of org.gwtproject.layout.client.Layout.Layer in project gwtproject by treblereel.
the class DeckLayoutPanel method doAfterLayout.
/**
* Hide the widget that just slid out of view.
*/
private void doAfterLayout() {
if (hidingWidget != null) {
Layer layer = (Layer) hidingWidget.getLayoutData();
setWidgetVisible(hidingWidget, layer, false);
layout.layout();
hidingWidget = null;
}
}
use of org.gwtproject.layout.client.Layout.Layer in project gwtproject by treblereel.
the class DeckLayoutPanel method doBeforeLayout.
/**
* Initialize the location of the widget that will slide into view.
*/
private void doBeforeLayout() {
Layer oldLayer = (lastVisibleWidget == null) ? null : (Layer) lastVisibleWidget.getLayoutData();
Layer newLayer = (visibleWidget == null) ? null : (Layer) visibleWidget.getLayoutData();
// Calculate the direction that the new widget will enter.
int oldIndex = getWidgetIndex(lastVisibleWidget);
int newIndex = getWidgetIndex(visibleWidget);
double direction = (oldIndex < newIndex) ? 100.0 : -100.0;
double vDirection = isAnimationVertical ? direction : 0.0;
double hDirection = isAnimationVertical ? 0.0 : LocaleInfo.getCurrentLocale().isRTL() ? -direction : direction;
/*
* Position the old widget in the center of the panel, and the new widget
* off to one side. If the old widget is the same as the new widget, then
* skip this step.
*/
hidingWidget = null;
if (visibleWidget != lastVisibleWidget) {
// Position the layers in their start positions.
if (oldLayer != null) {
// The old layer starts centered in the panel.
oldLayer.setTopHeight(0.0, Unit.PCT, 100.0, Unit.PCT);
oldLayer.setLeftWidth(0.0, Unit.PCT, 100.0, Unit.PCT);
setWidgetVisible(lastVisibleWidget, oldLayer, true);
}
if (newLayer != null) {
// The new layer starts off to one side.
newLayer.setTopHeight(vDirection, Unit.PCT, 100.0, Unit.PCT);
newLayer.setLeftWidth(hDirection, Unit.PCT, 100.0, Unit.PCT);
setWidgetVisible(visibleWidget, newLayer, true);
}
layout.layout();
hidingWidget = lastVisibleWidget;
}
// Set the end positions of the layers.
if (oldLayer != null) {
// The old layer ends off to one side.
oldLayer.setTopHeight(-vDirection, Unit.PCT, 100.0, Unit.PCT);
oldLayer.setLeftWidth(-hDirection, Unit.PCT, 100.0, Unit.PCT);
setWidgetVisible(lastVisibleWidget, oldLayer, true);
}
if (newLayer != null) {
// The new layer ends centered in the panel.
newLayer.setTopHeight(0.0, Unit.PCT, 100.0, Unit.PCT);
newLayer.setLeftWidth(0.0, Unit.PCT, 100.0, Unit.PCT);
/*
* The call to layout() above could have canceled an existing layout
* animation, which could cause this widget to be hidden if the user
* toggles between two visible widgets. We set it visible again to ensure
* that it ends up visible.
*/
setWidgetVisible(visibleWidget, newLayer, true);
}
lastVisibleWidget = visibleWidget;
}
Aggregations