use of com.spinyowl.legui.icon.Icon in project legui by SpinyOwl.
the class NvgDefaultComponentRenderer method renderBackground.
protected void renderBackground(C component, Context context, long nanovg) {
Icon bgIcon = getStyle(component, s -> s.getBackground().getIcon());
Vector4f bgColor = getStyle(component, s -> s.getBackground().getColor());
Vector4f cornerRadius = getBorderRadius(component);
NvgRenderUtils.renderShadow(nanovg, component);
nvgSave(nanovg);
NvgShapes.drawRect(nanovg, component.getAbsolutePosition(), component.getSize(), bgColor, cornerRadius);
if (bgIcon != null) {
renderIcon(bgIcon, component, context);
}
nvgRestore(nanovg);
}
use of com.spinyowl.legui.icon.Icon in project legui by SpinyOwl.
the class FlatSelectBoxTheme method apply.
/**
* Used to apply theme only for component and not apply for child components.
*
* @param component component to apply theme.
*/
@Override
public void apply(T component) {
super.apply(component);
Button expandButton = component.getExpandButton();
expandButton.getStyle().setShadow(null);
expandButton.getStyle().getBackground().setColor(ColorConstants.transparent());
Button selectionButton = component.getSelectionButton();
selectionButton.getStyle().setShadow(null);
selectionButton.getStyle().getBackground().setColor(ColorConstants.transparent());
Icon collapseIcon = component.getCollapseIcon();
if (collapseIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) collapseIcon;
bgIcon.setColor(ColorUtil.oppositeBlackOrWhite(settings.backgroundColor()));
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
Icon expandIcon = component.getExpandIcon();
if (expandIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) expandIcon;
bgIcon.setColor(ColorUtil.oppositeBlackOrWhite(settings.backgroundColor()));
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
}
use of com.spinyowl.legui.icon.Icon in project legui by SpinyOwl.
the class NvgCheckBoxRenderer method renderSelf.
@Override
public void renderSelf(CheckBox checkBox, Context context, long nanovg) {
createScissor(nanovg, checkBox);
{
Style style = checkBox.getStyle();
Vector2f pos = checkBox.getAbsolutePosition();
Vector2f size = checkBox.getSize();
/*Draw background rectangle*/
renderBackground(checkBox, context, nanovg);
TextState textState = checkBox.getTextState();
Icon icon = checkBox.isChecked() ? checkBox.getIconChecked() : checkBox.getIconUnchecked();
float iconWid = icon.getSize().x;
Vector4f padding = getPadding(checkBox, style);
float iconWidthForUse = (icon.getHorizontalAlign().index == 0 ? 1 : 0) * iconWid;
float h = size.y - (padding.y + padding.w);
float y = pos.y + padding.y;
float x = pos.x + iconWidthForUse + padding.x;
float w = size.x - iconWidthForUse - padding.z - padding.x;
Vector2fc size1 = new Vector2f(w, h);
Vector4f rect = new Vector4f(new Vector2f(x, y), size1.x(), size1.y());
NvgText.drawTextLineToRect(nanovg, rect, true, getStyle(checkBox, Style::getHorizontalAlign, HorizontalAlign.LEFT), getStyle(checkBox, Style::getVerticalAlign, VerticalAlign.MIDDLE), getStyle(checkBox, Style::getFontSize, 16F), getStyle(checkBox, Style::getFont, FontRegistry.getDefaultFont()), textState.getText(), getStyle(checkBox, Style::getTextColor));
renderIcon(icon, checkBox, context);
}
resetScissor(nanovg);
}
use of com.spinyowl.legui.icon.Icon in project legui by SpinyOwl.
the class NvgRadioButtonRenderer method renderSelf.
@Override
public void renderSelf(RadioButton radioButton, Context context, long nanovg) {
createScissor(nanovg, radioButton);
{
// default renderer used
Style style = radioButton.getStyle();
Vector2f pos = radioButton.getAbsolutePosition();
Vector2f size = radioButton.getSize();
// Draw background rectangle
renderBackground(radioButton, context, nanovg);
TextState textState = radioButton.getTextState();
Icon icon = radioButton.isChecked() ? radioButton.getIconChecked() : radioButton.getIconUnchecked();
Vector4f padding = getPadding(radioButton, style);
Vector4f pad = new Vector4f(padding.w, padding.x, padding.y, padding.z);
// renderNvg text
float iconWidthForUse;
if (icon != null) {
iconWidthForUse = (icon.getHorizontalAlign().index == 0 ? 1 : 0) * icon.getSize().x;
} else {
iconWidthForUse = 0F;
}
Vector2f textRectPos = new Vector2f(pos).add(iconWidthForUse, pad.y);
Vector2f textRectSize = new Vector2f(size).sub(iconWidthForUse + pad.z, pad.y + pad.w);
Vector4f rect = new Vector4f(textRectPos, textRectSize.x(), textRectSize.y());
drawTextLineToRect(nanovg, rect, true, getStyle(radioButton, Style::getHorizontalAlign, HorizontalAlign.LEFT), getStyle(radioButton, Style::getVerticalAlign, VerticalAlign.MIDDLE), getStyle(radioButton, Style::getFontSize, 16F), getStyle(radioButton, Style::getFont, FontRegistry.getDefaultFont()), textState.getText(), getStyle(radioButton, Style::getTextColor));
renderIcon(icon, radioButton, context);
}
resetScissor(nanovg);
}
use of com.spinyowl.legui.icon.Icon in project legui by SpinyOwl.
the class NvgToggleButtonRenderer method renderBackground.
private void renderBackground(long nvg, ToggleButton agui, Vector2f pos, Vector2f size, Context context) {
Icon icon = getStyle(agui, s -> s.getBackground().getIcon());
Vector4f bgColor = getStyle(agui, s -> s.getBackground().getColor());
Vector4f cornerRadius = getBorderRadius(agui);
renderShadow(nvg, agui);
boolean toggled = agui.isToggled();
if (toggled) {
NvgShapes.drawRect(nvg, pos, size, agui.getToggledBackgroundColor(), cornerRadius);
} else {
NvgShapes.drawRect(nvg, pos, size, bgColor, cornerRadius);
}
if (icon != null) {
createScissorByParent(nvg, agui);
renderIcon(icon, agui, context);
}
}
Aggregations