Search in sources :

Example 1 with Icon

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);
}
Also used : Vector4f(org.joml.Vector4f) Icon(com.spinyowl.legui.icon.Icon) NvgRenderer.renderIcon(com.spinyowl.legui.system.renderer.nvg.NvgRenderer.renderIcon)

Example 2 with Icon

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);
    }
}
Also used : Button(com.spinyowl.legui.component.Button) CharIcon(com.spinyowl.legui.icon.CharIcon) Icon(com.spinyowl.legui.icon.Icon) CharIcon(com.spinyowl.legui.icon.CharIcon)

Example 3 with Icon

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);
}
Also used : Vector2fc(org.joml.Vector2fc) TextState(com.spinyowl.legui.component.optional.TextState) Vector4f(org.joml.Vector4f) Vector2f(org.joml.Vector2f) Style(com.spinyowl.legui.style.Style) StyleUtilities.getStyle(com.spinyowl.legui.style.util.StyleUtilities.getStyle) Icon(com.spinyowl.legui.icon.Icon) NvgRenderer.renderIcon(com.spinyowl.legui.system.renderer.nvg.NvgRenderer.renderIcon)

Example 4 with Icon

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);
}
Also used : TextState(com.spinyowl.legui.component.optional.TextState) Vector4f(org.joml.Vector4f) Vector2f(org.joml.Vector2f) Style(com.spinyowl.legui.style.Style) StyleUtilities.getStyle(com.spinyowl.legui.style.util.StyleUtilities.getStyle) Icon(com.spinyowl.legui.icon.Icon) NvgRenderer.renderIcon(com.spinyowl.legui.system.renderer.nvg.NvgRenderer.renderIcon)

Example 5 with Icon

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);
    }
}
Also used : Vector4f(org.joml.Vector4f) Icon(com.spinyowl.legui.icon.Icon) NvgRenderer.renderIcon(com.spinyowl.legui.system.renderer.nvg.NvgRenderer.renderIcon)

Aggregations

Icon (com.spinyowl.legui.icon.Icon)8 Vector4f (org.joml.Vector4f)6 Button (com.spinyowl.legui.component.Button)4 Style (com.spinyowl.legui.style.Style)4 NvgRenderer.renderIcon (com.spinyowl.legui.system.renderer.nvg.NvgRenderer.renderIcon)4 Vector2f (org.joml.Vector2f)4 Component (com.spinyowl.legui.component.Component)3 Animation (com.spinyowl.legui.animation.Animation)2 CheckBox (com.spinyowl.legui.component.CheckBox)2 Dialog (com.spinyowl.legui.component.Dialog)2 ImageView (com.spinyowl.legui.component.ImageView)2 Label (com.spinyowl.legui.component.Label)2 Panel (com.spinyowl.legui.component.Panel)2 PasswordInput (com.spinyowl.legui.component.PasswordInput)2 ProgressBar (com.spinyowl.legui.component.ProgressBar)2 RadioButton (com.spinyowl.legui.component.RadioButton)2 RadioButtonGroup (com.spinyowl.legui.component.RadioButtonGroup)2 ScrollBar (com.spinyowl.legui.component.ScrollBar)2 ScrollablePanel (com.spinyowl.legui.component.ScrollablePanel)2 SelectBox (com.spinyowl.legui.component.SelectBox)2