Search in sources :

Example 1 with Font

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

the class Border method paint.

void paint(Graphics g, int x, int y, int width, int height, Component c) {
    int originalColor = g.getColor();
    if (!themeColors) {
        g.setColor(colorA);
    }
    int ac = 1;
    if (thickness > 0) {
        if (millimeters) {
            ac = Display.getInstance().convertToPixels(thickness);
        } else {
            ac = (int) thickness;
        }
    }
    switch(type) {
        case TYPE_LINE:
            if (borderTitle == null) {
                if (millimeters) {
                    g.drawRect(x, y, width, height, ac);
                } else {
                    g.drawRect(x, y, width, height, ac);
                }
            } else {
                Font f = c.getStyle().getFont();
                int titleW = f.stringWidth(borderTitle);
                int topPad = c.getStyle().getPaddingTop();
                int topY = y + (topPad - ac) / 2;
                if (c.isRTL()) {
                    // top (segment before the title)
                    g.fillRect(x + width - TITLE_MARGIN, topY, TITLE_MARGIN, ac);
                    // top (segment after the title)
                    g.fillRect(x, topY, width - (TITLE_MARGIN + titleW + TITLE_SPACE * 2), ac);
                    g.drawString(borderTitle, x + width - (TITLE_MARGIN + titleW + TITLE_SPACE), y + (topPad - f.getHeight()) / 2);
                } else {
                    // top (segment before the title)
                    g.fillRect(x, topY, TITLE_MARGIN, ac);
                    // top (segment after the title)
                    g.fillRect(x + TITLE_MARGIN + titleW + TITLE_SPACE * 2, topY, width - (TITLE_MARGIN + titleW + TITLE_SPACE * 2), ac);
                    g.drawString(borderTitle, x + TITLE_MARGIN + TITLE_SPACE, y + (topPad - f.getHeight()) / 2);
                }
                // bottom
                g.fillRect(x, y + height - ac, width, ac);
                // left
                g.fillRect(x, topY, ac, height);
                // right
                g.fillRect(x + width - ac, topY, ac, height);
            }
            break;
        case TYPE_DASHED:
        case TYPE_DOTTED:
            int segWidth = ac;
            if (type == TYPE_DASHED) {
                segWidth = ac * 3;
            }
            int ix = x;
            for (; ix < x + width; ix += segWidth * 2) {
                g.fillRect(ix, y, segWidth, ac);
                g.fillRect(ix, y + height - ac, segWidth, ac);
            }
            if (ix - segWidth < x + width) {
                // fill in the gap if any
                g.fillRect(ix - segWidth, y, x + width - ix + segWidth, ac);
                g.fillRect(ix - segWidth, y + height - ac, x + width - ix + segWidth, ac);
            }
            int iy = y;
            for (; iy < y + height; iy += segWidth * 2) {
                g.fillRect(x, iy, ac, segWidth);
                g.fillRect(x + width - ac, iy, ac, segWidth);
            }
            if (iy - segWidth < y + height) {
                // fill in the gap if any
                g.fillRect(x, iy - segWidth, ac, y + height - iy + segWidth);
                g.fillRect(x + width - ac, iy - segWidth, ac, y + height - iy + segWidth);
            }
            break;
        case TYPE_DOUBLE:
            width--;
            height--;
            for (int iter = 0; iter < ac; iter++) {
                if ((iter * 100 / ac <= 33) || (iter * 100 / ac >= 66)) {
                    g.drawRect(x + iter, y + iter, width, height);
                }
                width -= 2;
                height -= 2;
            }
            break;
        case TYPE_INSET:
        case TYPE_OUTSET:
            for (int i = 0; i < ac; i++) {
                g.drawLine(x + i, y + i, x + i, y + height - i);
                g.drawLine(x + i, y + i, x + width - i, y + i);
            }
            if (type == TYPE_INSET) {
                g.lighterColor(50);
            } else {
                g.darkerColor(50);
            }
            for (int i = 0; i < ac; i++) {
                g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
                g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
            }
            break;
        case TYPE_GROOVE:
        case TYPE_RIDGE:
            for (int i = 0; i < ac / 2; i++) {
                g.drawLine(x + i, y + i, x + i, y + height - i);
                g.drawLine(x + i, y + i, x + width - i, y + i);
            }
            for (int i = ac / 2; i < ac; i++) {
                g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
                g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
            }
            if (type == TYPE_GROOVE) {
                g.lighterColor(50);
            } else {
                g.darkerColor(50);
            }
            for (int i = 0; i < ac / 2; i++) {
                g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
                g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
            }
            for (int i = ac / 2; i < ac; i++) {
                g.drawLine(x + i, y + i, x + i, y + height - i);
                g.drawLine(x + i, y + i, x + width - i, y + i);
            }
            break;
        case TYPE_ROUNDED_PRESSED:
            x++;
            y++;
            width -= 2;
            height -= 2;
        case TYPE_ROUNDED:
            width--;
            height--;
            if (outline) {
                g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
            }
            break;
        case TYPE_ETCHED_LOWERED:
        case TYPE_ETCHED_RAISED:
            g.drawRect(x, y, width - 2, height - 2);
            if (themeColors) {
                if (type == TYPE_ETCHED_LOWERED) {
                    g.lighterColor(40);
                } else {
                    g.darkerColor(40);
                }
            } else {
                g.setColor(colorB);
            }
            g.drawLine(x + 1, y + height - 3, x + 1, y + 1);
            g.drawLine(x + 1, y + 1, x + width - 3, y + 1);
            g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
            g.drawLine(x + width - 1, y + height - 1, x + width - 1, y);
            break;
        case TYPE_BEVEL_RAISED:
            if (themeColors) {
                g.setColor(getBackgroundColor(c));
                g.lighterColor(50);
            } else {
                g.setColor(colorA);
            }
            g.drawLine(x, y, x, y + height - 2);
            g.drawLine(x + 1, y, x + width - 2, y);
            if (themeColors) {
                g.darkerColor(25);
            } else {
                g.setColor(colorB);
            }
            g.drawLine(x + 1, y + 1, x + 1, y + height - 3);
            g.drawLine(x + 2, y + 1, x + width - 3, y + 1);
            if (themeColors) {
                g.darkerColor(50);
            } else {
                g.setColor(colorC);
            }
            g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
            g.drawLine(x + width - 1, y, x + width - 1, y + height - 2);
            if (themeColors) {
                g.darkerColor(25);
            } else {
                g.setColor(colorD);
            }
            g.drawLine(x + 1, y + height - 2, x + width - 2, y + height - 2);
            g.drawLine(x + width - 2, y + 1, x + width - 2, y + height - 3);
            break;
        case TYPE_UNDERLINE:
            g.fillRect(x, y + height - ac - 1, width, ac);
            break;
        case TYPE_BEVEL_LOWERED:
            if (themeColors) {
                g.setColor(getBackgroundColor(c));
                g.darkerColor(50);
            } else {
                g.setColor(colorD);
            }
            g.drawLine(x, y, x, y + height - 1);
            g.drawLine(x + 1, y, x + width - 1, y);
            if (themeColors) {
                g.lighterColor(25);
            } else {
                g.setColor(colorC);
            }
            g.drawLine(x + 1, y + 1, x + 1, y + height - 2);
            g.drawLine(x + 2, y + 1, x + width - 2, y + 1);
            if (themeColors) {
                g.lighterColor(50);
            } else {
                g.setColor(colorC);
            }
            g.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
            g.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 2);
            if (themeColors) {
                g.lighterColor(25);
            } else {
                g.setColor(colorA);
            }
            g.drawLine(x + 2, y + height - 2, x + width - 2, y + height - 2);
            g.drawLine(x + width - 2, y + 2, x + width - 2, y + height - 3);
            break;
        case TYPE_COMPOUND:
            Style style = c.getStyle();
            boolean drawLeft = true;
            boolean drawRight = true;
            if (c.getUIManager().getLookAndFeel().isRTL()) {
                boolean temp = drawLeft;
                drawLeft = drawRight;
                drawRight = temp;
            }
            Border top = compoundBorders[Component.TOP];
            Border bottom = compoundBorders[Component.BOTTOM];
            Border left = compoundBorders[Component.LEFT];
            Border right = compoundBorders[Component.RIGHT];
            int topThickness = 0;
            int bottomThickness = 0;
            if (top != null) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                topThickness = (int) top.thickness;
                g.clipRect(x, y, width, topThickness);
                // top.paint(g, c);
                top.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            if (bottom != null) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                bottomThickness = (int) bottom.thickness;
                g.clipRect(x, y + height - bottomThickness, width, bottomThickness);
                // bottom.paint(g, c);
                bottom.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            if ((drawLeft) && (left != null)) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                g.clipRect(x, y + topThickness, (int) left.thickness, height - topThickness - bottomThickness);
                // left.paint(g, c);
                left.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            if ((drawRight) && (right != null)) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                g.clipRect(x + width - (int) right.thickness, y + topThickness, (int) right.thickness, height - topThickness - bottomThickness);
                // right.paint(g, c);
                right.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            break;
        case TYPE_IMAGE:
        case TYPE_IMAGE_SCALED:
        case TYPE_IMAGE_HORIZONTAL:
        case TYPE_IMAGE_VERTICAL:
            break;
    }
    g.setColor(originalColor);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Font(com.codename1.ui.Font)

Example 2 with Font

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

the class DefaultLookAndFeel method drawTextArea.

/**
 * {@inheritDoc}
 */
public void drawTextArea(Graphics g, TextArea ta) {
    setFG(g, ta);
    int line = ta.getLines();
    int oX = g.getClipX();
    int oY = g.getClipY();
    int oWidth = g.getClipWidth();
    int oHeight = g.getClipHeight();
    Font f = ta.getStyle().getFont();
    int fontHeight = f.getHeight();
    int align = reverseAlignForBidi(ta);
    int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL());
    int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL());
    int topPadding = ta.getStyle().getPaddingTop();
    boolean shouldBreak = false;
    for (int i = 0; i < line; i++) {
        int x = ta.getX() + leftPadding;
        int y = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * i;
        if (Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) {
            String rowText = (String) ta.getTextAt(i);
            // display ******** if it is a password field
            String displayText = "";
            if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
                int rlen = rowText.length();
                for (int j = 0; j < rlen; j++) {
                    displayText += passwordChar;
                }
            } else {
                displayText = rowText;
            }
            switch(align) {
                case Component.RIGHT:
                    x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
                    break;
                case Component.CENTER:
                    x += (ta.getWidth() - leftPadding - rightPadding - f.stringWidth(displayText)) / 2;
                    break;
            }
            int nextY = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * (i + 2);
            // add "..." at the last row
            if (ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line) {
                if (displayText.length() > 3) {
                    displayText = displayText.substring(0, displayText.length() - 3);
                }
                g.drawString(displayText + "...", x, y, ta.getStyle().getTextDecoration());
                return;
            } else {
                g.drawString(displayText, x, y, ta.getStyle().getTextDecoration());
            }
            shouldBreak = true;
        } else {
            if (shouldBreak) {
                break;
            }
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Example 3 with Font

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

the class DefaultLookAndFeel method drawTextFieldCursor.

/**
 * {@inheritDoc}
 */
public void drawTextFieldCursor(Graphics g, TextArea ta) {
    Style style = ta.getStyle();
    Font f = style.getFont();
    int cursorY;
    if (ta.isSingleLineTextArea()) {
        switch(ta.getVerticalAlignment()) {
            case Component.BOTTOM:
                cursorY = ta.getY() + ta.getHeight() - f.getHeight();
                break;
            case Component.CENTER:
                cursorY = ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2;
                break;
            default:
                cursorY = ta.getY() + style.getPaddingTop();
                break;
        }
    } else {
        cursorY = ta.getY() + style.getPaddingTop() + ta.getCursorY() * (ta.getRowsGap() + f.getHeight());
    }
    int cursorX = getTextFieldCursorX(ta);
    int align = reverseAlignForBidi(ta);
    int x = 0;
    if (align == Component.RIGHT) {
        String inputMode = ta.getInputMode();
        int inputModeWidth = f.stringWidth(inputMode);
        int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
        if (cursorX < baseX) {
            x = baseX - cursorX;
        }
    }
    int oldColor = g.getColor();
    if (getTextFieldCursorColor() == 0) {
        g.setColor(style.getFgColor());
    } else {
        g.setColor(getTextFieldCursorColor());
    }
    g.drawLine(cursorX + x, cursorY, cursorX + x, cursorY + f.getHeight());
    g.setColor(oldColor);
}
Also used : Font(com.codename1.ui.Font)

Example 4 with Font

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

the class DefaultLookAndFeel method drawLabelText.

/**
 * Draws the text of a label
 *
 * @param g graphics context
 * @param l label component
 * @param text the text for the label
 * @param x position for the label
 * @param y position for the label
 * @param textSpaceW the width available for the component
 * @return the space used by the drawing
 */
protected int drawLabelText(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
    Style style = l.getStyle();
    Font f = style.getFont();
    boolean rtl = l.isRTL();
    boolean isTickerRunning = l.isTickerRunning();
    int txtW = l.getStringWidth(f);
    if ((!isTickerRunning) || rtl) {
        // if there is no space to draw the text add ... at the end
        if (txtW > textSpaceW && textSpaceW > 0) {
            if (rtl) {
                if ((!isTickerRunning) && (l.isEndsWith3Points())) {
                    String points = "...";
                    int pointsW = f.stringWidth(points);
                    g.drawString(points, l.getShiftText() + x, y, l.getStyle().getTextDecoration());
                    g.clipRect(pointsW + l.getShiftText() + x, y, textSpaceW - pointsW, f.getHeight());
                }
                x = x - txtW + textSpaceW;
            } else {
                if (l.isEndsWith3Points()) {
                    String points = "...";
                    int index = 1;
                    int widest = f.charWidth('W');
                    int pointsW = f.stringWidth(points);
                    int tlen = text.length();
                    while (fastCharWidthCheck(text, index, textSpaceW - pointsW, widest, f) && index < tlen) {
                        index++;
                    }
                    text = text.substring(0, Math.min(text.length(), Math.max(1, index - 1))) + points;
                    txtW = f.stringWidth(text);
                }
            }
        }
    }
    g.drawString(text, l.getShiftText() + x, y, style.getTextDecoration());
    return Math.min(txtW, textSpaceW);
}
Also used : Font(com.codename1.ui.Font)

Example 5 with Font

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

the class DefaultLookAndFeel method drawComponent.

private void drawComponent(Graphics g, Label l, Image icon, Image stateIcon, int preserveSpaceForState) {
    setFG(g, l);
    int gap = l.getGap();
    int stateIconSize = 0;
    int stateIconYPosition = 0;
    String text = l.getText();
    Style style = l.getStyle();
    int cmpX = l.getX();
    int cmpY = l.getY();
    int cmpHeight = l.getHeight();
    int cmpWidth = l.getWidth();
    boolean rtl = l.isRTL();
    int leftPadding = style.getPaddingLeft(rtl);
    int rightPadding = style.getPaddingRight(rtl);
    int topPadding = style.getPaddingTop();
    int bottomPadding = style.getPaddingBottom();
    Font font = style.getFont();
    int fontHeight = 0;
    if (text == null) {
        text = "";
    }
    if (text.length() > 0) {
        fontHeight = font.getHeight();
    }
    int x = cmpX + leftPadding;
    int y = cmpY + topPadding;
    boolean opposite = false;
    if (stateIcon != null) {
        // square image width == height
        stateIconSize = stateIcon.getWidth();
        preserveSpaceForState = stateIconSize + gap;
        stateIconYPosition = cmpY + topPadding + (cmpHeight - topPadding - bottomPadding) / 2 - stateIconSize / 2;
        int tX = cmpX;
        if (((Button) l).isOppositeSide()) {
            if (rtl) {
                tX += leftPadding;
            } else {
                tX = tX + cmpWidth - leftPadding - stateIconSize;
            }
            cmpWidth -= leftPadding - stateIconSize;
            preserveSpaceForState = 0;
            opposite = true;
        } else {
            x = cmpX + leftPadding + preserveSpaceForState;
            if (rtl) {
                tX = tX + cmpWidth - leftPadding - stateIconSize;
            } else {
                tX += leftPadding;
            }
        }
        g.drawImage(stateIcon, tX, stateIconYPosition);
    }
    // default for bottom left alignment
    int align = reverseAlignForBidi(l, style.getAlignment());
    int textPos = reverseAlignForBidi(l, l.getTextPosition());
    // set initial x,y position according to the alignment and textPosition
    if (align == Component.LEFT) {
        switch(textPos) {
            case Label.LEFT:
            case Label.RIGHT:
                y = y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? icon.getHeight() : 0), fontHeight))) / 2;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? icon.getHeight() + gap : 0) + fontHeight)) / 2;
                break;
        }
    } else if (align == Component.CENTER) {
        switch(textPos) {
            case Label.LEFT:
            case Label.RIGHT:
                x = x + (cmpWidth - (preserveSpaceForState + leftPadding + rightPadding + ((icon != null) ? icon.getWidth() + l.getGap() : 0) + l.getStringWidth(font))) / 2;
                if (!opposite) {
                    x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                } else {
                    x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? icon.getHeight() : 0), fontHeight))) / 2;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                x = x + (cmpWidth - (preserveSpaceForState + leftPadding + rightPadding + Math.max(((icon != null) ? icon.getWidth() + l.getGap() : 0), l.getStringWidth(font)))) / 2;
                if (!opposite) {
                    x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                } else {
                    x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? icon.getHeight() + gap : 0) + fontHeight)) / 2;
                break;
        }
    } else if (align == Component.RIGHT) {
        switch(textPos) {
            case Label.LEFT:
            case Label.RIGHT:
                x = cmpX + cmpWidth - rightPadding - (((icon != null) ? (icon.getWidth() + gap) : 0) + l.getStringWidth(font));
                if (l.isRTL()) {
                    if (!opposite) {
                        x = Math.max(x - preserveSpaceForState, cmpX + leftPadding);
                    } else {
                        x = Math.min(x - preserveSpaceForState, cmpX + leftPadding);
                    }
                } else {
                    if (!opposite) {
                        x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                    } else {
                        x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                    }
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? icon.getHeight() : 0), fontHeight))) / 2;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                x = cmpX + cmpWidth - rightPadding - (Math.max(((icon != null) ? (icon.getWidth()) : 0), l.getStringWidth(font)));
                if (!opposite) {
                    x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                } else {
                    x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? icon.getHeight() + gap : 0) + fontHeight)) / 2;
                break;
        }
    }
    int textSpaceW = cmpWidth - rightPadding - leftPadding;
    if (icon != null && (textPos == Label.RIGHT || textPos == Label.LEFT)) {
        textSpaceW = textSpaceW - icon.getWidth();
    }
    if (stateIcon != null) {
        textSpaceW = textSpaceW - stateIconSize;
    } else {
        textSpaceW = textSpaceW - preserveSpaceForState;
    }
    if (icon == null) {
        // no icon only string
        drawLabelString(g, l, text, x, y, textSpaceW);
    } else {
        int strWidth = l.getStringWidth(font);
        int iconWidth = icon.getWidth();
        int iconHeight = icon.getHeight();
        int iconStringWGap;
        int iconStringHGap;
        switch(textPos) {
            case Label.LEFT:
                if (iconHeight > fontHeight) {
                    iconStringHGap = (iconHeight - fontHeight) / 2;
                    strWidth = drawLabelStringValign(g, l, text, x, y, iconStringHGap, iconHeight, textSpaceW, fontHeight);
                    g.drawImage(icon, x + strWidth + gap, y);
                } else {
                    iconStringHGap = (fontHeight - iconHeight) / 2;
                    strWidth = drawLabelString(g, l, text, x, y, textSpaceW);
                    g.drawImage(icon, x + strWidth + gap, y + iconStringHGap);
                }
                break;
            case Label.RIGHT:
                if (iconHeight > fontHeight) {
                    iconStringHGap = (iconHeight - fontHeight) / 2;
                    g.drawImage(icon, x, y);
                    drawLabelStringValign(g, l, text, x + iconWidth + gap, y, iconStringHGap, iconHeight, textSpaceW, fontHeight);
                } else {
                    iconStringHGap = (fontHeight - iconHeight) / 2;
                    g.drawImage(icon, x, y + iconStringHGap);
                    drawLabelString(g, l, text, x + iconWidth + gap, y, textSpaceW);
                }
                break;
            case Label.BOTTOM:
                if (iconWidth > strWidth) {
                    // center align the smaller
                    iconStringWGap = (iconWidth - strWidth) / 2;
                    g.drawImage(icon, x, y);
                    drawLabelString(g, l, text, x + iconStringWGap, y + iconHeight + gap, textSpaceW);
                } else {
                    iconStringWGap = (Math.min(strWidth, textSpaceW) - iconWidth) / 2;
                    g.drawImage(icon, x + iconStringWGap, y);
                    drawLabelString(g, l, text, x, y + iconHeight + gap, textSpaceW);
                }
                break;
            case Label.TOP:
                if (iconWidth > strWidth) {
                    // center align the smaller
                    iconStringWGap = (iconWidth - strWidth) / 2;
                    drawLabelString(g, l, text, x + iconStringWGap, y, textSpaceW);
                    g.drawImage(icon, x, y + fontHeight + gap);
                } else {
                    iconStringWGap = (Math.min(strWidth, textSpaceW) - iconWidth) / 2;
                    drawLabelString(g, l, text, x, y, textSpaceW);
                    g.drawImage(icon, x + iconStringWGap, y + fontHeight + gap);
                }
                break;
        }
    }
}
Also used : Button(com.codename1.ui.Button) 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