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));
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations