use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class Container method scrollComponentToVisible.
/**
* Makes sure the component is visible in the scroll if this container is
* scrollable
*
* @param c the component that will be scrolling for visibility
*/
public void scrollComponentToVisible(Component c) {
if (isScrollable()) {
if (c != null) {
Rectangle r = c.getVisibleBounds();
if (c.getParent() != null) {
// special case for the first component to allow the user to scroll all the
// way to the top
Form f = getComponentForm();
if (f != null && f.getInvisibleAreaUnderVKB() == 0 && f.findFirstFocusable() == c) {
// support this use case only if the component doesn't explicitly declare visible bounds
if (r == c.getBounds() && !Display.getInstance().isTouchScreenDevice()) {
scrollRectToVisible(new Rectangle(0, 0, c.getX() + Math.min(c.getWidth(), getWidth()), c.getY() + Math.min(c.getHeight(), getHeight())), this);
return;
}
}
}
boolean moveToVisible = true;
boolean large = c.getVisibleBounds().getSize().getHeight() > getHeight() || c.getVisibleBounds().getSize().getWidth() > getWidth();
if (large) {
int x = getScrollX();
int y = getScrollY();
int w = getWidth();
int h = getHeight();
boolean visible = contains(c) && Rectangle.intersects(c.getAbsoluteX(), c.getAbsoluteY(), c.getWidth(), c.getHeight(), getAbsoluteX() + x, getAbsoluteY() + y, w, h);
// if this is a big component no need to scroll to the begining if it's
// partially visible
moveToVisible = !visible;
}
if (moveToVisible) {
scrollRectToVisible(r.getX(), r.getY(), Math.min(r.getSize().getWidth(), getWidth()), Math.min(r.getSize().getHeight(), getHeight()), c);
}
}
}
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class Container method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
if (enableLayoutOnPaint) {
layoutContainer();
}
g.translate(getX(), getY());
int size = components.size();
int startIter = 0;
if (size >= 30) {
int clipX1 = g.getClipX();
int clipX2 = g.getClipX() + g.getClipWidth();
int clipY1 = g.getClipY();
int clipY2 = g.getClipY() + g.getClipHeight();
startIter = calculateFirstPaintableOffset(clipX1, clipY1, clipX2, clipY2);
if (startIter < 0) {
// There was no efficient way to calculate the offset
startIter = 0;
} else if (startIter < size) {
// There was an efficient way to calculate the offset so we
// will continue this approach
size = calculateLastPaintableOffset(startIter, clipX1, clipY1, clipX2, clipY2) + 1;
}
}
CodenameOneImplementation impl = Display.impl;
if (dontRecurseContainer) {
for (int iter = startIter; iter < size; iter++) {
Component cmp = components.get(iter);
if (cmp.getClass() == Container.class) {
paintContainerChildrenForAnimation((Container) cmp, g);
} else {
cmp.paintInternal(impl.getComponentScreenGraphics(this, g), false);
}
}
} else {
for (int iter = startIter; iter < size; iter++) {
Component cmp = components.get(iter);
cmp.paintInternal(impl.getComponentScreenGraphics(this, g), false);
}
}
int tx = g.getTranslateX();
int ty = g.getTranslateY();
g.translate(-tx, -ty);
if (sidemenuBarTranslation > 0) {
g.translate(sidemenuBarTranslation, 0);
paintGlass(g);
paintTensile(g);
g.translate(-sidemenuBarTranslation, 0);
} else {
paintGlass(g);
paintTensile(g);
}
g.translate(tx, ty);
g.translate(-getX(), -getY());
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class Container method isObscuredByChildren.
/**
* Invoked internally to indicate if child components are hiding this container
* thus removing the need to invoke its own paint methods
* @return true if child components are obscuring this component
*/
boolean isObscuredByChildren() {
if (!blockOverdraw) {
return false;
}
if (!getLayout().obscuresPotential(this)) {
return false;
}
Style s = getStyle();
if (s.getPaddingTop() != 0 || s.getPaddingLeftNoRTL() != 0 || s.getPaddingRightNoRTL() != 0 || s.getPaddingBottom() != 0) {
return false;
}
int size = components.size();
for (int iter = 0; iter < size; iter++) {
Component cmp = components.get(iter);
s = cmp.getStyle();
if (cmp.getWidth() == 0 || cmp.getHeight() == 0) {
continue;
}
// need to think of a better way, this means we invoke the same logic recurisvely again and again by a factor of depth. Not good...
if (cmp instanceof Container) {
if (!((Container) cmp).getLayout().obscuresPotential(this)) {
return false;
}
if (s.getOpacity() != 0xff || s.getMarginTop() != 0 || s.getMarginLeftNoRTL() != 0 || s.getMarginRightNoRTL() != 0 || s.getMarginBottom() != 0) {
return false;
}
if ((s.getBgTransparency() & 0xff) != 0xff && !((Container) cmp).isObscuredByChildren()) {
return false;
}
} else {
if ((s.getBgTransparency() & 0xff) != 0xff || s.getOpacity() != 0xff || s.getMarginTop() != 0 || s.getMarginLeftNoRTL() != 0 || s.getMarginRightNoRTL() != 0 || s.getMarginBottom() != 0) {
return false;
}
}
}
return true;
}
use of com.codename1.ui.Container 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.Container in project CodenameOne by codenameone.
the class Dialog method placeButtonCommands.
/**
* Places the given commands in the dialog command area, this is very useful for touch devices.
*
* @param cmds the commands to place
* @deprecated this method shouldn't be invoked externally, it should have been private
*/
public void placeButtonCommands(Command[] cmds) {
buttonCommands = cmds;
Container buttonArea;
if (getUIManager().isThemeConstant("dlgCommandGridBool", false)) {
buttonArea = new Container(new GridLayout(1, cmds.length));
} else {
buttonArea = new Container(new FlowLayout(CENTER));
}
buttonArea.setUIID("DialogCommandArea");
String uiid = getUIManager().getThemeConstant("dlgButtonCommandUIID", null);
addButtonBar(buttonArea);
if (cmds.length > 0) {
String lineColor = getUIManager().getThemeConstant("dlgInvisibleButtons", null);
if (cmds.length > 3) {
lineColor = null;
}
int largest = Integer.parseInt(getUIManager().getThemeConstant("dlgCommandButtonSizeInt", "0"));
for (int iter = 0; iter < cmds.length; iter++) {
Button b = new Button(cmds[iter]);
if (uiid != null) {
b.setUIID(uiid);
}
// special case for dialog butons uppercase on Android
if (Button.isCapsTextDefault()) {
b.setCapsText(true);
}
largest = Math.max(b.getPreferredW(), largest);
if (lineColor != null && lineColor.length() > 0) {
int color = Integer.parseInt(lineColor, 16);
Border brd = null;
if (iter < cmds.length - 1) {
brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, Border.createLineBorder(1, color));
} else {
brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, null);
}
b.getUnselectedStyle().setBorder(brd);
b.getSelectedStyle().setBorder(brd);
b.getPressedStyle().setBorder(brd);
}
buttonArea.addComponent(b);
}
for (int iter = 0; iter < cmds.length; iter++) {
buttonArea.getComponentAt(iter).setPreferredW(largest);
}
buttonArea.getComponentAt(0).requestFocus();
}
}
Aggregations