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