![JAR search and dependency download from the Maven repository](/logo.png)
com.extjs.gxt.ui.client.widget.layout.ColumnLayout Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxt Show documentation
Show all versions of gxt Show documentation
Rich Internet Application Framework for GWT
/*
* Sencha GXT 2.3.1a - Sencha for GWT
* Copyright(c) 2007-2013, Sencha, Inc.
* [email protected]
*
* http://www.sencha.com/products/gxt/license/
*/
package com.extjs.gxt.ui.client.widget.layout;
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.core.XDOM;
import com.extjs.gxt.ui.client.util.Size;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.Container;
import com.extjs.gxt.ui.client.widget.Layout;
/**
* This layout positions and sizes the container's children in columns
* horizontally. Each component may specify its width in pixels or as percentage
* of the parent remaining width.
*
*
* Child Widgets are:
*
* - Sized : Yes - the width of a widget is adjusted by the ColumnData
* hint
* - Positioned : Yes - widgets are placed in columns
*
*
*
* Code snippet:
*
*
LayoutContainer container = new LayoutContainer();
container.setLayout(new ColumnLayout());
container.add(new Button("100px"), new ColumnData(100));
container.add(new Button("30%"), new ColumnData(.3));
container.add(new Button("50px"), new ColumnData(50));
*
*
* @see ColumnData
*/
public class ColumnLayout extends Layout {
protected El innerCt;
protected boolean adjustForScroll = false;
/**
* Creates a new column layout.
*/
public ColumnLayout() {
setExtraStyle("x-column");
monitorResize = true;
}
/**
* Returns true if adjust for scroll is enabled.
*
* @return the adjust for scroll state
*/
public boolean isAdjustForScroll() {
return adjustForScroll;
}
/**
* True to adjust the container width calculations to account for the scroll
* bar (defaults to false).
*
* @param adjustForScroll the adjust for scroll state
*/
public void setAdjustForScroll(boolean adjustForScroll) {
this.adjustForScroll = adjustForScroll;
}
@Override
protected void onLayout(Container> container, El target) {
if (innerCt == null) {
container.addStyleName("x-column-layout-ct");
innerCt = target.createChild("");
innerCt.createChild("");
}
renderAll(container, innerCt);
Size size = target.getStyleSize();
int w = size.width - (adjustForScroll ? XDOM.getScrollBarWidth() : 0);
int pw = w;
int count = container.getItemCount();
// some columns can be percentages while others are fixed
// so we need to make 2 passes
for (int i = 0; i < count; i++) {
Component c = container.getItem(i);
ColumnData layoutData = null;
LayoutData d = getLayoutData(c);
if (d != null && d instanceof ColumnData) {
layoutData = (ColumnData) d;
} else {
layoutData = new ColumnData();
}
if (layoutData.getWidth() > 1) {
pw -= layoutData.getWidth();
}
pw -= getSideMargins(c);
}
pw = pw < 0 ? 0 : pw;
for (int i = 0; i < count; i++) {
Component c = container.getItem(i);
ColumnData layoutData = null;
LayoutData d = getLayoutData(c);
if (d != null && d instanceof ColumnData) {
layoutData = (ColumnData) d;
} else {
layoutData = new ColumnData();
}
int width = -1;
if (layoutData.getWidth() > 0 && layoutData.getWidth() <= 1) {
width = (int) (layoutData.getWidth() * pw);
} else {
width = (int) layoutData.getWidth();
}
setSize(c, width, -1);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy