Search in sources :

Example 51 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class Label method getBaseline.

@Override
public int getBaseline(int width, int height) {
    Style s = getStyle();
    Font f = s.getFont();
    int innerHeight = height - s.getVerticalPadding();
    return s.getPaddingTop() + (innerHeight - f.getHeight()) / 2 + f.getAscent();
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 52 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class Label method paintImpl.

void paintImpl(Graphics g) {
    initAutoResize();
    Object icn = null;
    Image i = getIconFromState();
    if (i != null) {
        icn = i.getImage();
    } else {
        // optimize away a common usage pattern for drawing the background only
        if (text == null || text.equals("") || text.equals(" ")) {
            return;
        }
    }
    // getUIManager().getLookAndFeel().drawLabel(g, this);
    int cmpX = getX() + g.getTranslateX();
    int cmpY = getY() + g.getTranslateY();
    int cmpHeight = getHeight();
    int cmpWidth = getWidth();
    Style s = getStyle();
    Font f = s.getFont();
    String t = text;
    if (text == null) {
        t = "";
    }
    Display.impl.drawLabelComponent(g.getGraphics(), cmpX, cmpY, cmpHeight, cmpWidth, s, t, icn, null, 0, gap, isRTL(), false, textPosition, getStringWidth(f), tickerRunning, shiftText, endsWith3Points, valign);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 53 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class List method calculateElementSize.

/**
 * Calculates the size of an element based on a forumla or on rendering prototype
 */
private Dimension calculateElementSize(boolean selected, boolean addMargin) {
    if (renderingPrototype != null) {
        Component unselected = renderer.getListCellRendererComponent(this, renderingPrototype, 0, selected);
        if (addMargin) {
            return unselected.getPreferredSizeWithMargin();
        } else {
            return unselected.getPreferredSize();
        }
    }
    int width = 0;
    int height = 0;
    int elements = Math.min(listSizeCalculationSampleCount, model.getSize());
    int marginY = 0;
    int marginX = 0;
    for (int iter = 0; iter < elements; iter++) {
        Component cmp = renderer.getListCellRendererComponent(this, model.getItemAt(iter), iter, selected);
        if (cmp instanceof Container) {
            cmp.setShouldCalcPreferredSize(true);
        }
        Dimension d = cmp.getPreferredSize();
        width = Math.max(width, d.getWidth());
        height = Math.max(height, d.getHeight());
        if (iter == 0) {
            Style s = cmp.getStyle();
            marginY = s.getVerticalMargins();
            marginX = s.getHorizontalMargins();
        }
    }
    return new Dimension(width + marginX, height + marginY);
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 54 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class HTMLComponent method applyPageStyle.

/**
 * Applies the user defined page style to the main container. This clones the page style and sets the clone to the page, as various CSS directives may change the style of the main container.
 */
private void applyPageStyle() {
    Style pageStyleCopy = new Style(pageStyle);
    mainContainer.setUnselectedStyle(pageStyleCopy);
    mainContainer.setSelectedStyle(pageStyleCopy);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 55 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class HTMLComponent method newLine.

/**
 * Adds the container representing the current line to the current container and creates a new one
 */
private void newLine(int align) {
    if (curLine.getComponentCount() == 0) {
        // If no components are present, create a vertical spacing in the size of the font height
        curLine.setPreferredH(font.getHeight());
    } else if (maxSuperscript != 0) {
        // NOTE: handling this is the line level is not an ideal implementation, but other approaches will make it too complicated
        for (int i = 0; i < curLine.getComponentCount(); i++) {
            Component cmp = curLine.getComponentAt(i);
            Style style = cmp.getStyle();
            style.setMargin(Component.TOP, style.getMargin(Component.TOP) + maxSuperscript - style.getMargin(Component.BOTTOM));
            style.setMargin(Component.BOTTOM, 0);
            if (cmp instanceof HTMLLink) {
                style = cmp.getSelectedStyle();
                style.setMargin(Component.TOP, style.getMargin(Component.TOP) + maxSuperscript - style.getMargin(Component.BOTTOM));
                style.setMargin(Component.BOTTOM, 0);
                style = ((HTMLLink) cmp).getPressedStyle();
                style.setMargin(Component.TOP, style.getMargin(Component.TOP) + maxSuperscript - style.getMargin(Component.BOTTOM));
                style.setMargin(Component.BOTTOM, 0);
            }
        }
        maxSuperscript = 0;
    }
    lastWasEmpty = (curLine.getComponentCount() == 0);
    curContainer.addComponent(curLine);
    curLine = new Container();
    curLine.getStyle().setBgTransparency(0);
    if (!FIXED_WIDTH) {
        FlowLayout fl = new FlowLayout(align);
        fl.setValign(Component.BOTTOM);
        fl.setValignByRow(true);
        curLine.setLayout(fl);
    } else {
        FlowLayout fl = (FlowLayout) curLine.getLayout();
        fl.setValign(Component.BOTTOM);
    }
    curLine.setScrollableX(false);
    curLine.getStyle().setMargin(Component.LEFT, leftIndent);
    x = leftIndent;
}
Also used : Container(com.codename1.ui.Container) FlowLayout(com.codename1.ui.layouts.FlowLayout) Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

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