Search in sources :

Example 76 with Dimension

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);
        }
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 77 with Dimension

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;
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 78 with Dimension

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;
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 79 with Dimension

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);
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 80 with Dimension

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);
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Dimension (com.codename1.ui.geom.Dimension)74 Style (com.codename1.ui.plaf.Style)27 Component (com.codename1.ui.Component)16 Image (com.codename1.ui.Image)16 Rectangle (com.codename1.ui.geom.Rectangle)9 EncodedImage (com.codename1.ui.EncodedImage)8 Label (com.codename1.ui.Label)7 Container (com.codename1.ui.Container)6 FileEncodedImage (com.codename1.components.FileEncodedImage)5 StorageImage (com.codename1.components.StorageImage)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Form (com.codename1.ui.Form)4 Dimension (java.awt.Dimension)4 Font (com.codename1.ui.Font)3 FontImage (com.codename1.ui.FontImage)3 TextArea (com.codename1.ui.TextArea)3 ActionListener (com.codename1.ui.events.ActionListener)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Border (com.codename1.ui.plaf.Border)3