use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.
the class Container method calculateLastPaintableOffset.
/**
* Gets the index of the "last" child component that intersects the given rectangle. This is
* only helpful if the components are sorted (e.g. with BoxLayout.Y_AXIS). If they aren't
* sorted then this will just return components.size()-1.
* @param pos The starting position to search. It is assumed that this starting
* position is in the visible region.
* @param clipX1 The left bounds of the region to search. (0,0) is the top left corner of the container.
* @param clipY1 The top bounds of the region to search. (0,0) is the top left corner of the container.
* @param clipX2 The right bounds of the region to search. (0,0) is the top left corner of the container.
* @param clipY2 The bottom bounds of the region to search. (0,0) is the top left corner of the container.
* @return The index of the last visible component in this container - or components.size()-1
*/
private int calculateLastPaintableOffset(int pos, int clipX1, int clipY1, int clipX2, int clipY2) {
final int len = components.size();
if (pos >= len - 1) {
// Let's return one less than pos to indicate this
return len - 1;
}
final Layout l = getLayout();
if (l.getClass() == BoxLayout.class) {
if (((BoxLayout) l).getAxis() == BoxLayout.Y_AXIS) {
// Use a binary search to find the first visible
// Component c = components.get(++pos);
Component c = null;
int cy1 = -1;
final int end = len - 1;
// This should still be a valid index because
pos++;
// we previously checked to see if it was >= len-1
do {
c = components.get(pos);
cy1 = c.getBounds().getY();
} while (++pos <= end && cy1 <= clipY2);
return pos - 1;
}
}
return len - 1;
}
use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.
the class Toolbar method showOnTopSidemenu.
void showOnTopSidemenu(int draggedX, boolean fromCurrent) {
int v = 0;
int dw = Display.getInstance().getDisplayWidth();
if (Display.getInstance().isPortrait()) {
if (Display.getInstance().isTablet()) {
v = getUIManager().getThemeConstant("sideMenuSizeTabPortraitInt", -1);
if (v < 0) {
v = dw * 2 / 3;
} else {
v = dw * (100 - v) / 100;
}
} else {
v = getUIManager().getThemeConstant("sideMenuSizePortraitInt", -1);
if (v < 0) {
v = dw - Display.getInstance().convertToPixels(10);
} else {
v = dw * (100 - v) / 100;
}
}
} else {
if (Display.getInstance().isTablet()) {
v = getUIManager().getThemeConstant("sideMenuSizeTabLandscapeInt", -1);
if (v < 0) {
v = dw * 3 / 4;
} else {
v = dw * (100 - v) / 100;
}
} else {
v = getUIManager().getThemeConstant("sideMenuSizeLandscapeInt", -1);
if (v < 0) {
v = dw * 4 / 10;
} else {
v = dw * (100 - v) / 100;
}
}
}
int actualV = v;
if (draggedX > 0) {
v = Math.min(v, draggedX);
sidemenuDialog.setAnimateShow(false);
sidemenuDialog.dispose();
} else {
sidemenuDialog.setAnimateShow(true);
}
// workaround for layout issue on first show
if (sidemenuDialog.getClientProperty("cn1$firstShow") == null) {
sidemenuDialog.setAnimateShow(false);
sidemenuDialog.setVisible(false);
sidemenuDialog.show(0, 0, 0, dw - v);
sidemenuDialog.disposeToTheLeft();
sidemenuDialog.setVisible(true);
sidemenuDialog.putClientProperty("cn1$firstShow", Boolean.TRUE);
sidemenuDialog.setAnimateShow(draggedX < 1);
}
sidemenuDialog.setHeight(Display.getInstance().getDisplayHeight());
sidemenuDialog.setWidth(v);
if (!fromCurrent) {
sidemenuDialog.setX(-v);
}
sidemenuDialog.setRepositionAnimation(false);
sidemenuDialog.layoutContainer();
if (!getUIManager().isThemeConstant("sideMenuTensileDragBool", true)) {
sidemenuDialog.getContentPane().setTensileDragEnabled(false);
}
float f = ((float) v) / ((float) dw) * 80.0f;
Container cnt = getComponentForm().getFormLayeredPane(Toolbar.class, false);
Style s = cnt.getUnselectedStyle();
s.setBgTransparency((int) f);
s.setBgColor(0);
sidemenuDialog.show(0, 0, 0, dw - actualV);
if (draggedX > 0) {
sidemenuDialog.setX(Math.min(0, draggedX - actualV));
}
}
use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.
the class SideMenuBar method installRightCommands.
void installRightCommands() {
if (rightCommands != null) {
for (int i = 0; i < rightCommands.size(); i++) {
Command rightCommand = (Command) rightCommands.get(rightCommands.size() - 1 - i);
String uiid = (String) rightCommand.getClientProperty("uiid");
if (uiid == null) {
uiid = "TitleCommand";
}
int txtPosition = Component.RIGHT;
Integer pos = (Integer) rightCommand.getClientProperty("textPosition");
if (pos != null) {
txtPosition = pos.intValue();
}
Layout l = getTitleAreaContainer().getLayout();
if (l instanceof BorderLayout) {
final Button b = new Button(rightCommand);
b.setUIID(uiid);
b.putClientProperty("TitleCommand", Boolean.TRUE);
b.setTextPosition(txtPosition);
BorderLayout bl = (BorderLayout) l;
final Component east = bl.getEast();
if (east == null) {
getTitleAreaContainer().addComponent(BorderLayout.EAST, b);
} else {
if (east instanceof Container) {
Container cnt = (Container) east;
// check if this command is already added
boolean shouldAdd = true;
for (int j = 0; j < cnt.getComponentCount(); j++) {
Component c = cnt.getComponentAt(j);
if (c instanceof Button) {
Command cc = ((Button) c).getCommand();
if (cc != null && cc.equals(b.getCommand())) {
shouldAdd = false;
break;
}
}
}
if (shouldAdd) {
cnt.addComponent(b);
}
} else {
if (east instanceof Button) {
Command cc = ((Button) east).getCommand();
if (cc != null && cc.equals(b.getCommand())) {
continue;
}
}
east.getParent().removeComponent(east);
Container buttons = new Container(new BoxLayout(BoxLayout.X_AXIS));
buttons.addComponent(east);
buttons.addComponent(b);
getTitleAreaContainer().addComponent(BorderLayout.EAST, buttons);
}
}
}
}
}
initTitleBarStatus();
}
use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.
the class SideMenuBar method installLeftCommands.
void installLeftCommands() {
if (leftCommands != null) {
for (int i = 0; i < leftCommands.size(); i++) {
Command leftCommand = (Command) leftCommands.get(leftCommands.size() - 1 - i);
String uiid = (String) leftCommand.getClientProperty("uiid");
if (uiid == null) {
uiid = "TitleCommand";
}
int txtPosition = Component.RIGHT;
Integer pos = (Integer) leftCommand.getClientProperty("textPosition");
if (pos != null) {
txtPosition = pos.intValue();
}
Layout l = getTitleAreaContainer().getLayout();
if (l instanceof BorderLayout) {
Button b = new Button(leftCommand);
b.setUIID(uiid);
b.putClientProperty("TitleCommand", Boolean.TRUE);
b.setTextPosition(txtPosition);
BorderLayout bl = (BorderLayout) l;
Component west = bl.getWest();
if (west == null) {
getTitleAreaContainer().addComponent(BorderLayout.WEST, b);
} else {
if (west instanceof Container) {
Container cnt = (Container) west;
// check if this command is already added
boolean shouldAdd = true;
for (int j = 0; j < cnt.getComponentCount(); j++) {
Component c = cnt.getComponentAt(j);
if (c instanceof Button) {
Command cc = ((Button) c).getCommand();
if (cc != null && cc.equals(b.getCommand())) {
shouldAdd = false;
break;
}
}
}
if (shouldAdd) {
cnt.addComponent(b);
}
} else {
if (west instanceof Button) {
Command cc = ((Button) west).getCommand();
if (cc != null && cc.equals(b.getCommand())) {
continue;
}
}
west.getParent().removeComponent(west);
Container buttons = new Container(new BoxLayout(BoxLayout.X_AXIS));
buttons.addComponent(west);
buttons.addComponent(b);
getTitleAreaContainer().addComponent(BorderLayout.WEST, buttons);
}
}
}
}
}
initTitleBarStatus();
}
use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.
the class BorderLayout method addLayoutComponent.
/**
* {@inheritDoc}
*/
public void addLayoutComponent(Object name, Component comp, Container c) {
// helper check for a common mistake...
if (name == null) {
throw new IllegalArgumentException("Cannot add component to BorderLayout Container without constraint parameter");
}
// allows us to work with Component constraints too which makes some code simpler
if (name instanceof Integer) {
switch(((Integer) name).intValue()) {
case Component.TOP:
name = NORTH;
break;
case Component.BOTTOM:
name = SOUTH;
break;
case Component.LEFT:
name = WEST;
break;
case Component.RIGHT:
name = EAST;
break;
case Component.CENTER:
name = CENTER;
break;
default:
throw new IllegalArgumentException("BorderLayout Container expects one of the constraints BorderLayout.NORTH/SOUTH/EAST/WEST/CENTER");
}
}
Component previous = null;
/* Assign the component to one of the known regions of the layout.
*/
if (CENTER.equals(name)) {
previous = portraitCenter;
portraitCenter = comp;
} else if (NORTH.equals(name)) {
previous = portraitNorth;
portraitNorth = comp;
} else if (SOUTH.equals(name)) {
previous = portraitSouth;
portraitSouth = comp;
} else if (EAST.equals(name)) {
previous = portraitEast;
portraitEast = comp;
} else if (WEST.equals(name)) {
previous = portraitWest;
portraitWest = comp;
} else if (OVERLAY.equals(name)) {
previous = overlay;
overlay = comp;
} else {
throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);
}
if (previous != null && previous != comp) {
c.removeComponent(previous);
}
}
Aggregations