use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class List method pointerDraggedImpl.
private void pointerDraggedImpl(int x, int y) {
if (!isEnabled()) {
return;
}
if (isSmoothScrolling()) {
if (fixedSelection < FIXED_NONE_BOUNDRY) {
super.pointerDragged(x, y);
} else {
if (!isDragActivated()) {
setDragActivated(true);
}
Dimension size = getElementSize(false, true);
boolean vertical = orientation == List.VERTICAL;
int pos;
int s;
if (vertical) {
pos = y;
s = size.getHeight();
} else {
pos = x;
s = size.getWidth();
}
fixedDraggedAnimationPosition = fixedDraggedAnimationPosition - (fixedDraggedPosition - pos);
fixedDraggedPosition = pos;
if (fixedDraggedAnimationPosition <= -s) {
fixedDraggedSelection++;
if (fixedDraggedSelection >= model.getSize()) {
fixedDraggedSelection = 0;
}
} else if (fixedDraggedAnimationPosition >= s) {
fixedDraggedSelection--;
if (fixedDraggedSelection < 0) {
fixedDraggedSelection = model.getSize() - 1;
}
}
fixedDraggedAnimationPosition = fixedDraggedAnimationPosition % s;
}
} else {
int sel = pointerSelect(x, y);
if (sel > -1) {
model.setSelectedIndex(sel);
}
}
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class List method pointerSelect.
private int pointerSelect(int x, int y) {
int selectedIndex = -1;
int numOfcomponents = getModel().getSize();
Style style = getStyle();
Dimension rendererSize = getElementSize(false, true);
Dimension selectedSize = getElementSize(true, true);
Rectangle pos = new Rectangle();
int width = getWidth() - style.getHorizontalPadding() - getSideGap();
if (isScrollableX()) {
width = Math.max(width, getScrollDimension().getWidth() - style.getHorizontalPadding() - getSideGap());
}
y = y - getAbsoluteY();
x = x - getAbsoluteX();
if (fixedSelection < FIXED_NONE_BOUNDRY) {
calculateComponentPosition(getSelectedIndex(), width, pos, rendererSize, getElementSize(true, true), true);
if (orientation != HORIZONTAL) {
if (y < pos.getY()) {
selectedIndex = (y - style.getPaddingTop()) / (rendererSize.getHeight() + itemGap);
} else {
int current = getSelectedIndex();
if (y < pos.getY() + selectedSize.getHeight()) {
selectedIndex = current;
} else {
selectedIndex = (current + 1) + (y - (pos.getY() + selectedSize.getHeight())) / (rendererSize.getHeight() + itemGap);
}
}
} else {
if (isRTL()) {
if (x > pos.getX() + selectedSize.getWidth()) {
int delta = x - (pos.getX() + selectedSize.getWidth());
delta /= (rendererSize.getWidth() + itemGap);
// should have been -1-delta, but works better like this.
selectedIndex = getSelectedIndex() - 1 - delta;
} else {
if (x >= pos.getX()) {
selectedIndex = getSelectedIndex();
} else {
int delta = pos.getX() - x;
delta /= (rendererSize.getWidth() + itemGap);
selectedIndex = getSelectedIndex() + 1 + delta;
}
}
} else {
if (x < pos.getX()) {
selectedIndex = (x - style.getPaddingLeftNoRTL()) / (rendererSize.getWidth() + itemGap);
} else {
int current = getSelectedIndex();
if (x < pos.getX() + selectedSize.getWidth()) {
selectedIndex = current;
} else {
selectedIndex = (current + 1) + (x - (pos.getX() + selectedSize.getWidth())) / (rendererSize.getWidth() + itemGap);
}
}
}
}
} else {
for (int i = 0; i < numOfcomponents; i++) {
calculateComponentPosition(i, width, pos, rendererSize, selectedSize, true);
if (pos.contains(x, y)) {
selectedIndex = i;
break;
}
}
}
if (selectedIndex < 0 || selectedIndex >= size()) {
return -1;
}
return selectedIndex;
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class List method getVisibleBounds.
/**
* {@inheritDoc}
*/
protected Rectangle getVisibleBounds() {
Rectangle pos = new Rectangle();
Dimension rendererSize = getElementSize(false, true);
Style style = getStyle();
int width = getWidth() - style.getHorizontalPadding() - getSideGap();
calculateComponentPosition(getCurrentSelected(), width, pos, rendererSize, getElementSize(true, true), true);
pos.setX(pos.getX() + getX());
pos.setY(pos.getY() + getY());
return pos;
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class List method scrollRectToVisible.
/**
* Makes sure the selected index is visible if it is not in the current view
* rect the list will scroll so it fits within
*
* @param rect the rectangle area to scroll to
*/
public void scrollRectToVisible(Rectangle rect) {
if (fixedSelection < FIXED_NONE_BOUNDRY) {
// Dimension elemSize = getElementSize();
Rectangle toScroll;
if (orientation != HORIZONTAL) {
toScroll = new Rectangle(getScrollX(), rect.getY(), rect.getSize().getWidth(), rect.getSize().getHeight() + itemGap);
} else {
toScroll = new Rectangle(rect.getX(), getScrollY(), rect.getSize().getWidth() + itemGap, rect.getSize().getHeight());
}
super.scrollRectToVisible(toScroll, this);
}
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class List method selectElement.
void selectElement(int selectedIndex) {
Dimension size = getElementSize(false, true);
Rectangle rect;
if (getOrientation() != HORIZONTAL) {
rect = new Rectangle(getX(), (size.getHeight() + itemGap) * selectedIndex, getElementSize(true, true));
} else {
int x = (size.getWidth() + itemGap) * selectedIndex;
if (isRTL() && isScrollableX()) {
x = getScrollDimension().getWidth() - x - (size.getWidth() + itemGap);
}
rect = new Rectangle(x, getY(), getElementSize(true, true));
}
if (hasScrollableParent(getParent())) {
if (hasFocus()) {
scrollRectToVisible(rect);
}
} else {
scrollRectToVisible(rect);
}
}
Aggregations