Search in sources :

Example 31 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class InteractionDialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param c the context component which is used to position the dialog and can also be pointed at
 */
public void showPopupDialog(Component c) {
    disposed = false;
    Rectangle componentPos = c.getSelectedRect();
    componentPos.setX(componentPos.getX() - c.getScrollX());
    componentPos.setY(componentPos.getY() - c.getScrollY());
    showPopupDialog(componentPos);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 32 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class ScaleImageButton method calcPreferredSize.

/**
 * {@inheritDoc}
 */
@Override
protected Dimension calcPreferredSize() {
    Image i = getIcon();
    if (i == null) {
        return new Dimension();
    }
    int dw = Display.getInstance().getDisplayWidth();
    int iw = i.getWidth();
    int ih = i.getHeight();
    // a scrollable container the vertical height might be granted providing so much space as to make this unrealistic...
    if (iw > dw) {
        float ratio = ((float) iw) / ((float) dw);
        iw = (int) (((float) iw) / ((float) ratio));
        ih = (int) (((float) ih) / ((float) ratio));
    }
    Style s = getStyle();
    return new Dimension(iw + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), ih + s.getPaddingTop() + s.getPaddingBottom());
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image)

Example 33 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class ClearableTextField method removeCmpBackground.

private static void removeCmpBackground(Component cmp) {
    Style s = cmp.getAllStyles();
    s.setBorder(Border.createEmpty());
    s.setBackgroundType(Style.BACKGROUND_NONE);
    s.setBgTransparency(0);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 34 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class ToastBar method getToastBarComponent.

private ToastBarComponent getToastBarComponent() {
    Form f = Display.getInstance().getCurrent();
    if (f != null && !(f instanceof Dialog)) {
        ToastBarComponent c = (ToastBarComponent) f.getClientProperty("ToastBarComponent");
        if (c == null || c.getParent() == null) {
            c = new ToastBarComponent();
            c.hidden = true;
            f.putClientProperty("ToastBarComponent", c);
            Container layered = f.getLayeredPane(this.getClass(), true);
            layered.setLayout(new BorderLayout());
            layered.addComponent(position == Component.TOP ? BorderLayout.NORTH : BorderLayout.SOUTH, c);
            updateStatus();
        }
        if (position == Component.BOTTOM && f.getInvisibleAreaUnderVKB() > 0) {
            Style s = c.getAllStyles();
            s.setMarginUnit(Style.UNIT_TYPE_PIXELS);
            s.setMarginBottom(f.getInvisibleAreaUnderVKB());
        }
        return c;
    }
    return null;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style)

Example 35 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class Component method scrollRectToVisible.

/**
 * Makes sure the component is visible in the scroll if this container
 * is scrollable
 *
 * @param x
 * @param y
 * @param width
 * @param height
 * @param coordinateSpace the component according to whose coordinates
 * rect is defined. Rect's x/y are relative to that component
 * (they are not absolute).
 */
public void scrollRectToVisible(int x, int y, int width, int height, Component coordinateSpace) {
    if (isScrollable()) {
        int scrollPosition = getScrollY();
        Style s = getStyle();
        int w = getWidth() - s.getHorizontalPadding();
        int h = getHeight() - s.getVerticalPadding();
        Rectangle view;
        int invisibleAreaUnderVKB = getInvisibleAreaUnderVKB();
        if (isSmoothScrolling() && destScrollY > -1) {
            view = new Rectangle(getScrollX(), destScrollY, w, h - invisibleAreaUnderVKB);
        } else {
            view = new Rectangle(getScrollX(), getScrollY(), w, h - invisibleAreaUnderVKB);
        }
        int relativeX = x;
        int relativeY = y;
        // component needs to be in absolute coordinates...
        Container parent = null;
        if (coordinateSpace != null) {
            parent = coordinateSpace.getParent();
        }
        if (parent == this) {
            if (view.contains(x, y, width, height)) {
                return;
            }
        } else {
            while (parent != this) {
                // mostly a special case for list
                if (parent == null) {
                    relativeX = x;
                    relativeY = y;
                    break;
                }
                relativeX += parent.getX();
                relativeY += parent.getY();
                parent = parent.getParent();
            }
            if (view.contains(relativeX, relativeY, width, height)) {
                return;
            }
        }
        if (isScrollableX()) {
            if (getScrollX() > relativeX) {
                setScrollX(relativeX);
            }
            int rightX = relativeX + width - s.getHorizontalPadding();
            if (getScrollX() + w < rightX) {
                setScrollX(getScrollX() + (rightX - (getScrollX() + w)));
            } else {
                if (getScrollX() > relativeX) {
                    setScrollX(relativeX);
                }
            }
        }
        if (isScrollableY()) {
            if (getScrollY() > relativeY) {
                scrollPosition = relativeY;
            }
            int bottomY = relativeY + height - s.getVerticalPadding();
            if (getScrollY() + h < bottomY + invisibleAreaUnderVKB) {
                scrollPosition = getScrollY() + (bottomY - (getScrollY() + h)) + invisibleAreaUnderVKB;
            } else {
                if (getScrollY() > relativeY) {
                    scrollPosition = relativeY;
                }
            }
            if (isSmoothScrolling() && isInitialized()) {
                initialScrollY = getScrollY();
                destScrollY = scrollPosition;
                initScrollMotion();
            } else {
                setScrollY(scrollPosition);
            }
        }
        repaint();
    } else {
        // try to move parent scroll if you are not scrollable
        Container parent = getParent();
        if (parent != null) {
            parent.scrollRectToVisible(getAbsoluteX() - parent.getAbsoluteX() + x, getAbsoluteY() - parent.getAbsoluteY() + y, width, height, parent);
        }
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Point(com.codename1.ui.geom.Point)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3