Search in sources :

Example 16 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a SpanLabel
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(SpanLabel l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 17 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class Tabs method addTab.

/**
 * Adds a <code>component</code>
 * represented by a <code>title</code> and/or <code>icon</code>,
 * either of which can be <code>null</code>.
 * Cover method for <code>insertTab</code>.
 *
 * @param title the title to be displayed in this tab
 * @param materialIcon one of the material design icon constants from {@link com.codename1.ui.FontImage}
 * @param iconSize icon size in millimeters
 * @param component the component to be displayed when this tab is clicked
 * @return this so these calls can be chained
 *
 * @see #insertTab
 * @see #removeTabAt
 */
public Tabs addTab(String title, char materialIcon, float iconSize, Component component) {
    int index = tabsContainer.getComponentCount();
    FontImage i = FontImage.createMaterial(materialIcon, "Tab", iconSize);
    insertTab(title, i, component, index);
    Style sel = getUIManager().getComponentSelectedStyle("Tab");
    i = FontImage.createMaterial(materialIcon, sel, iconSize);
    setTabSelectedIcon(index, i);
    return this;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 18 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class Paint method measureTextHeight.

float measureTextHeight(char[] chars, int start, int count) {
    Font f = getTypeface();
    float h = 0f;
    if (f != null) {
        int clen = chars.length;
        for (int i = start; i < clen && i < start + count; i++) {
            float nh = f.getHeight();
            h = nh > h ? nh : h;
        }
    } else {
        throw new RuntimeException("Failed to get font");
    }
    return h;
}
Also used : Font(com.codename1.ui.Font)

Example 19 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class Paint method breakText.

public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) {
    char[] chars = text.toCharArray();
    Font f = getTypeface();
    float tmp = 0;
    if (f != null) {
        int start = measureForwards ? 0 : chars.length - 1;
        int inc = measureForwards ? 1 : -1;
        float currWidth = 0f;
        int clen = chars.length;
        int wlen = measuredWidth != null ? measuredWidth.length : -1;
        for (int i = start; (measureForwards && i < clen) || (!measureForwards && i >= 0); i += inc) {
            tmp = f.charWidth(chars[i]);
            if (currWidth + tmp > maxWidth) {
                return i;
            }
            if (i < wlen) {
                measuredWidth[i] = tmp;
            }
            currWidth += tmp;
        }
    } else {
        throw new RuntimeException("Failed to get font");
    }
    return chars.length;
}
Also used : Font(com.codename1.ui.Font)

Example 20 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class Paint method measureText.

public float measureText(char[] chars, int start, int count) {
    float out = 0f;
    Font f = getTypeface();
    if (f != null) {
        int clen = chars.length;
        for (int i = start; i < clen && i < start + count; i++) {
            out += f.charWidth(chars[i]);
        }
    } else {
        throw new RuntimeException("Failed to get font");
    }
    return out;
}
Also used : Font(com.codename1.ui.Font)

Aggregations

Style (com.codename1.ui.plaf.Style)15 Font (com.codename1.ui.Font)8 ArrayList (java.util.ArrayList)5 ComponentImage (ca.weblite.shared.components.ComponentImage)4 Image (com.codename1.ui.Image)4 Point (java.awt.Point)4 Hashtable (java.util.Hashtable)4 MultiButton (com.codename1.components.MultiButton)3 SpanButton (com.codename1.components.SpanButton)3 EventObject (java.util.EventObject)3 List (java.util.List)3 Vector (java.util.Vector)3 SpanLabel (com.codename1.components.SpanLabel)2 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)2 IconUIID (com.codename1.rad.attributes.IconUIID)2 UIID (com.codename1.rad.attributes.UIID)2 Button (com.codename1.ui.Button)2 TextArea (com.codename1.ui.TextArea)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 UIManager (com.codename1.ui.plaf.UIManager)2