Search in sources :

Example 31 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class TextField method updateScroll.

private void updateScroll() {
    if (!isSingleLineTextArea() && isScrollableY()) {
        Font textFont = getStyle().getFont();
        int rowsGap = getRowsGap();
        int lineHeight = textFont.getHeight() + rowsGap;
        Rectangle rect = new Rectangle(getScrollX(), getCursorY() * lineHeight, getWidth(), lineHeight);
        scrollRectToVisible(rect, this);
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 32 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class TextArea method keyPressed.

/**
 * {@inheritDoc}
 */
public void keyPressed(int keyCode) {
    super.keyPressed(keyCode);
    int action = com.codename1.ui.Display.getInstance().getGameAction(keyCode);
    // this works around a bug where fire is also a softkey on devices such as newer Nokia
    // series 40's (e.g. the Nokia emulator). It closes its native text box on fire then
    // as a result of a Nokia bug we get the key released of that closing and assume the
    // users wants to edit the text... When means the only way to exit the native text box
    // is via the cancel option (after pressing OK once).
    triggerClose = action == Display.GAME_FIRE;
    // scroll the TextArea
    Rectangle rect = new Rectangle(getScrollX(), getScrollY(), getWidth(), getHeight());
    Font textFont = getStyle().getFont();
    if (action == Display.GAME_DOWN) {
        if ((getScrollY() + getHeight()) < (rowsGap + getStyle().getFont().getHeight()) * getLines()) {
            rect.setY(rect.getY() + (textFont.getHeight() + rowsGap) * linesToScroll);
            scrollRectToVisible(rect, this);
        } else {
            setHandlesInput(false);
        }
    } else {
        if (action == Display.GAME_UP) {
            if (getScrollY() > 0) {
                rect.setY(Math.max(0, rect.getY() - (textFont.getHeight() + rowsGap) * linesToScroll));
                scrollRectToVisible(rect, this);
            } else {
                setHandlesInput(false);
            }
        }
    }
    if (action == Display.GAME_RIGHT || action == Display.GAME_LEFT) {
        setHandlesInput(false);
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 33 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawLabelString.

/**
 * Implements the drawString for the text component and adjust the valign
 * assuming the icon is in one of the sides
 */
private int drawLabelString(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
    Style style = l.getStyle();
    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    // g.pushClip();
    g.clipRect(x, cy, textSpaceW, ch);
    if (l.isTickerRunning()) {
        Font font = style.getFont();
        if (l.getShiftText() > 0) {
            if (l.getShiftText() > textSpaceW) {
                l.setShiftText(x - l.getX() - l.getStringWidth(font));
            }
        } else if (l.getShiftText() + l.getStringWidth(font) < 0) {
            l.setShiftText(textSpaceW);
        }
    }
    int drawnW = drawLabelText(g, l, text, x, y, textSpaceW);
    g.setClip(cx, cy, cw, ch);
    return drawnW;
}
Also used : Font(com.codename1.ui.Font)

Example 34 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class DefaultLookAndFeel method getCheckBoxPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getCheckBoxPreferredSize(Button cb) {
    if (cb.isToggle()) {
        return getButtonPreferredSize(cb);
    }
    threeImageCache[0] = cb.getMaskedIcon();
    threeImageCache[1] = cb.getRolloverIcon();
    threeImageCache[2] = cb.getPressedIcon();
    if (chkBoxImages != null) {
        return getPreferredSize(cb, threeImageCache, chkBoxImages[0]);
    }
    Dimension d = getPreferredSize(cb, threeImageCache, null);
    // checkbox square needs to be the height and width of the font height even
    // when no text is in the check box this is a good indication of phone DPI
    int checkBoxSquareSize = cb.getStyle().getFont().getHeight();
    // allow for checkboxes without a string within them
    d.setHeight(Math.max(checkBoxSquareSize, d.getHeight()));
    d.setWidth(d.getWidth() + checkBoxSquareSize + cb.getGap());
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 35 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class DefaultLookAndFeel method getPreferredSize.

/**
 * {@inheritDoc}
 */
private Dimension getPreferredSize(Label l, Image[] icons, Image stateImage) {
    int prefW = 0;
    int prefH = 0;
    Style style = l.getStyle();
    int gap = l.getGap();
    int ilen = icons.length;
    for (int i = 0; i < ilen; i++) {
        Image icon = icons[i];
        if (icon != null) {
            prefW = Math.max(prefW, icon.getWidth());
            prefH = Math.max(prefH, icon.getHeight());
        }
    }
    String text = l.getText();
    Font font = style.getFont();
    if (font == null) {
        System.out.println("Missing font for " + l);
        font = Font.getDefaultFont();
    }
    if (text != null && text.length() > 0) {
        // add the text size
        switch(l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += font.stringWidth(text);
                prefH = Math.max(prefH, font.getHeight());
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefW = Math.max(prefW, font.stringWidth(text));
                prefH += font.getHeight();
                break;
        }
    }
    // add the state image(relevant for CheckBox\RadioButton)
    if (stateImage != null) {
        prefW += (stateImage.getWidth() + gap);
        prefH = Math.max(prefH, stateImage.getHeight());
    }
    if (icons[0] != null && text != null && text.length() > 0) {
        switch(l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += gap;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefH += gap;
                break;
        }
    }
    if (l.isShowEvenIfBlank()) {
        prefH += style.getVerticalPadding();
        prefW += style.getHorizontalPadding();
    } else {
        if (prefH != 0) {
            prefH += style.getVerticalPadding();
        }
        if (prefW != 0) {
            prefW += style.getHorizontalPadding();
        }
    }
    if (style.getBorder() != null) {
        prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
        prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
    }
    if (isBackgroundImageDetermineSize() && style.getBgImage() != null) {
        prefW = Math.max(style.getBgImage().getWidth(), prefW);
        prefH = Math.max(style.getBgImage().getHeight(), prefH);
    }
    return new Dimension(prefW, prefH);
}
Also used : Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage) Font(com.codename1.ui.Font)

Aggregations

Font (com.codename1.ui.Font)30 Image (com.codename1.ui.Image)12 Hashtable (java.util.Hashtable)10 EditorFont (com.codename1.ui.EditorFont)8 Border (com.codename1.ui.plaf.Border)8 Component (com.codename1.ui.Component)7 Style (com.codename1.ui.plaf.Style)7 EncodedImage (com.codename1.ui.EncodedImage)6 TextArea (com.codename1.ui.TextArea)6 AnimationObject (com.codename1.ui.animations.AnimationObject)6 BufferedImage (java.awt.image.BufferedImage)6 IOException (java.io.IOException)6 java.awt (java.awt)5 Container (com.codename1.ui.Container)4 Dimension (com.codename1.ui.geom.Dimension)4 RoundBorder (com.codename1.ui.plaf.RoundBorder)4 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)4 ParseException (java.text.ParseException)4 Paint (android.graphics.Paint)3 EditorTTFFont (com.codename1.ui.EditorTTFFont)3