Search in sources :

Example 1 with Button

use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.

the class ExampleGui method createSelectBox.

private void createSelectBox() {
    SelectBox<Object> selectBox = new SelectBox<>(20, 260, 100, 20);
    selectBox.addElement(0.25f);
    selectBox.addElement(0.5d);
    selectBox.addElement(1);
    selectBox.addElement("MyText");
    selectBox.addElement(new Long(2L));
    selectBox.setVisibleCount(7);
    selectBox.setElementHeight(20);
    selectBox.addSelectBoxChangeSelectionEventListener((SelectBoxChangeSelectionEventListener<Object>) event -> {
        Dialog dialog = new Dialog("SelectBox clicked", 300, 100);
        Label valueLabel = new Label("Value: " + event.getNewValue().toString(), 10, 10, 300, 20);
        dialog.getContainer().add(valueLabel);
        Label classLabel = new Label("Class: " + event.getNewValue().getClass().getName(), 10, 30, 300, 20);
        dialog.getContainer().add(classLabel);
        dialog.show(event.getFrame());
    });
    this.add(selectBox);
    Button sbb = new Button("Add element", 130, 260, 70, 20);
    sbb.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (event.getAction() == CLICK) {
            selectBox.addElement("Dynamic#" + selectBox.getElements().size());
        }
    });
    this.add(sbb);
}
Also used : TextInput(com.spinyowl.legui.component.TextInput) Button(com.spinyowl.legui.component.Button) ChangeSizeEvent(com.spinyowl.legui.component.event.component.ChangeSizeEvent) PRESS(com.spinyowl.legui.event.MouseClickEvent.MouseClickAction.PRESS) BASELINE(com.spinyowl.legui.component.optional.align.VerticalAlign.BASELINE) SliderChangeValueEventListener(com.spinyowl.legui.component.event.slider.SliderChangeValueEventListener) Shadow(com.spinyowl.legui.style.shadow.Shadow) SliderChangeValueEvent(com.spinyowl.legui.component.event.slider.SliderChangeValueEvent) Themes(com.spinyowl.legui.theme.Themes) KeyEvent(com.spinyowl.legui.event.KeyEvent) Theme(com.spinyowl.legui.theme.Theme) RELEASE(com.spinyowl.legui.event.MouseClickEvent.MouseClickAction.RELEASE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageLoader(com.spinyowl.legui.image.loader.ImageLoader) TOP(com.spinyowl.legui.component.optional.align.VerticalAlign.TOP) SelectBoxChangeSelectionEventListener(com.spinyowl.legui.component.event.selectbox.SelectBoxChangeSelectionEventListener) DropEvent(com.spinyowl.legui.event.DropEvent) UpdateLabelWidthListener(com.spinyowl.legui.component.misc.listener.label.UpdateLabelWidthListener) CursorEnterEventListener(com.spinyowl.legui.listener.CursorEnterEventListener) CursorEnterEvent(com.spinyowl.legui.event.CursorEnterEvent) TextUtil(com.spinyowl.legui.util.TextUtil) HorizontalAlign(com.spinyowl.legui.component.optional.align.HorizontalAlign) PositionType(com.spinyowl.legui.style.Style.PositionType) Animation(com.spinyowl.legui.animation.Animation) ColorConstants(com.spinyowl.legui.style.color.ColorConstants) LEFT(com.spinyowl.legui.component.optional.align.HorizontalAlign.LEFT) Icon(com.spinyowl.legui.icon.Icon) RadioButtonGroup(com.spinyowl.legui.component.RadioButtonGroup) MIDDLE(com.spinyowl.legui.component.optional.align.VerticalAlign.MIDDLE) PasswordInput(com.spinyowl.legui.component.PasswordInput) Label(com.spinyowl.legui.component.Label) Orientation(com.spinyowl.legui.component.optional.Orientation) LabelWidthChangeEvent(com.spinyowl.legui.component.event.label.LabelWidthChangeEvent) GLFW(org.lwjgl.glfw.GLFW) CheckBox(com.spinyowl.legui.component.CheckBox) List(java.util.List) MOUSE_BUTTON_LEFT(com.spinyowl.legui.input.Mouse.MouseButton.MOUSE_BUTTON_LEFT) FocusEvent(com.spinyowl.legui.event.FocusEvent) Vector2f(org.joml.Vector2f) CLICK(com.spinyowl.legui.event.MouseClickEvent.MouseClickAction.CLICK) TooltipTextSizeChangeEvent(com.spinyowl.legui.component.event.tooltip.TooltipTextSizeChangeEvent) Component(com.spinyowl.legui.component.Component) MouseClickEventListener(com.spinyowl.legui.listener.MouseClickEventListener) ImageView(com.spinyowl.legui.component.ImageView) VerticalAlign(com.spinyowl.legui.component.optional.align.VerticalAlign) ScrollablePanel(com.spinyowl.legui.component.ScrollablePanel) SelectBox(com.spinyowl.legui.component.SelectBox) RadioButton(com.spinyowl.legui.component.RadioButton) SplitPanel(com.spinyowl.legui.component.SplitPanel) Style(com.spinyowl.legui.style.Style) CENTER(com.spinyowl.legui.component.optional.align.HorizontalAlign.CENTER) ToggleButton(com.spinyowl.legui.component.ToggleButton) ProgressBar(com.spinyowl.legui.component.ProgressBar) BOTTOM(com.spinyowl.legui.component.optional.align.VerticalAlign.BOTTOM) FontRegistry(com.spinyowl.legui.style.font.FontRegistry) Dialog(com.spinyowl.legui.component.Dialog) ImageIcon(com.spinyowl.legui.icon.ImageIcon) TextDirection(com.spinyowl.legui.style.font.TextDirection) RIGHT(com.spinyowl.legui.component.optional.align.HorizontalAlign.RIGHT) Tooltip(com.spinyowl.legui.component.Tooltip) Panel(com.spinyowl.legui.component.Panel) ScrollBar(com.spinyowl.legui.component.ScrollBar) MouseClickEvent(com.spinyowl.legui.event.MouseClickEvent) KeyEventListener(com.spinyowl.legui.listener.KeyEventListener) DisplayType(com.spinyowl.legui.style.Style.DisplayType) FocusEventListener(com.spinyowl.legui.listener.FocusEventListener) Slider(com.spinyowl.legui.component.Slider) SimpleLineBorder(com.spinyowl.legui.style.border.SimpleLineBorder) Widget(com.spinyowl.legui.component.Widget) TextArea(com.spinyowl.legui.component.TextArea) Vector4f(org.joml.Vector4f) Button(com.spinyowl.legui.component.Button) RadioButton(com.spinyowl.legui.component.RadioButton) ToggleButton(com.spinyowl.legui.component.ToggleButton) SelectBox(com.spinyowl.legui.component.SelectBox) Dialog(com.spinyowl.legui.component.Dialog) Label(com.spinyowl.legui.component.Label)

Example 2 with Button

use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.

the class SingleClassExample method generateOnFly.

private static List<Component> generateOnFly() {
    List<Component> list = new ArrayList<>();
    Widget widget = new Widget(10, 50, 380, 240);
    widget.getContainer().getStyle().setDisplay(FLEX);
    widget.setDraggable(false);
    TabbedPanel tabbedPanel = new TabbedPanel();
    tabbedPanel.getStyle().setPosition(PositionType.RELATIVE);
    tabbedPanel.getStyle().getFlexStyle().setFlexGrow(1);
    tabbedPanel.getStyle().getFlexStyle().setFlexShrink(1);
    tabbedPanel.getStyle().setMargin(10F);
    tabbedPanel.getStyle().setBorder(new SimpleLineBorder(ColorConstants.black(), 1F));
    widget.getContainer().add(tabbedPanel);
    Tab tab1 = new Tab("Planes", new Label("Show all planes available"));
    Tab tab2 = new Tab("Cars", new Label("Show all cars available"));
    Tab tab3 = new Tab("Boats", new Label("Show all boats available"));
    tabbedPanel.addTab(tab1);
    tabbedPanel.addTab(tab2);
    tabbedPanel.addTab(tab3);
    AtomicInteger tabIdx = new AtomicInteger();
    Button addTabButton = new Button("Add tab", 180, 10, 70, 30);
    addTabButton.getListenerMap().addListener(MouseClickEvent.class, event -> {
        if (MouseClickAction.CLICK.equals(event.getAction())) {
            String tabName = "Tab #" + tabIdx.incrementAndGet();
            Component tabComponent = new Panel();
            tabComponent.getStyle().getBackground().setColor(ColorUtil.randomColor());
            tabComponent.getStyle().setPadding(10F, 20F);
            tabbedPanel.addTab(new Tab(tabName, tabComponent));
        }
    });
    Button removeTabButton = new Button("Remove tab", 260, 10, 70, 30);
    removeTabButton.getListenerMap().addListener(MouseClickEvent.class, event -> {
        if (MouseClickAction.CLICK.equals(event.getAction()) && tabbedPanel.tabCount() > 0) {
            tabbedPanel.removeTab(tabbedPanel.getCurrentTab());
        }
    });
    Button changeStripPosition = new Button("Switch", 340, 10, 50, 30);
    changeStripPosition.getListenerMap().addListener(MouseClickEvent.class, event -> {
        if (MouseClickAction.CLICK.equals(event.getAction())) {
            TabStripPosition current = tabbedPanel.getTabStripPosition();
            if (TOP == current) {
                tabbedPanel.setTabStripPosition(LEFT);
            } else if (LEFT == current) {
                tabbedPanel.setTabStripPosition(BOTTOM);
            } else if (BOTTOM == current) {
                tabbedPanel.setTabStripPosition(RIGHT);
            } else {
                tabbedPanel.setTabStripPosition(TOP);
            }
        }
    });
    widget.getTitle().getListenerMap().addListener(KeyEvent.class, event -> {
        if (event.getAction() == GLFW_RELEASE) {
            if (event.getKey() == GLFW_KEY_1) {
                tabbedPanel.setTabWidth(30);
            } else if (event.getKey() == GLFW_KEY_2) {
                tabbedPanel.setTabHeight(120);
            } else if (event.getKey() == GLFW_KEY_3) {
                tabbedPanel.setTabStripPosition(LEFT);
            } else if (event.getKey() == GLFW_KEY_4) {
                tabbedPanel.setTabWidth(120);
            } else if (event.getKey() == GLFW_KEY_5) {
                tabbedPanel.setTabHeight(30);
            } else if (event.getKey() == GLFW_KEY_6) {
                tabbedPanel.setTabStripPosition(TOP);
            }
        }
    });
    list.add(addTabButton);
    list.add(removeTabButton);
    list.add(changeStripPosition);
    list.add(widget);
    return list;
}
Also used : ArrayList(java.util.ArrayList) Widget(com.spinyowl.legui.component.Widget) Label(com.spinyowl.legui.component.Label) TabbedPanel(com.spinyowl.legui.component.TabbedPanel) SimpleLineBorder(com.spinyowl.legui.style.border.SimpleLineBorder) TabbedPanel(com.spinyowl.legui.component.TabbedPanel) Panel(com.spinyowl.legui.component.Panel) Tab(com.spinyowl.legui.component.TabbedPanel.Tab) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Button(com.spinyowl.legui.component.Button) TabStripPosition(com.spinyowl.legui.component.TabbedPanel.TabStripPosition) Component(com.spinyowl.legui.component.Component)

Example 3 with Button

use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.

the class UpdateButtonStyleWidthListener method process.

/**
 * Used to handle {@link ButtonContentChangeEvent} event.
 *
 * @param event event to handle.
 */
@Override
public void process(ButtonWidthChangeEvent event) {
    Button button = event.getTargetComponent();
    float textWidth = button.getTextState().getTextWidth();
    button.getStyle().setWidth(textWidth);
}
Also used : Button(com.spinyowl.legui.component.Button)

Example 4 with Button

use of com.spinyowl.legui.component.Button 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 5 with Button

use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.

the class FlatWidgetTheme method applyAll.

/**
 * Used to apply theme for component and for all children of this component. Should be
 * reimplemented for components that contains other child components.
 *
 * @param component component to apply theme.
 */
@Override
public void applyAll(T component) {
    super.apply(component);
    component.getStyle().getBackground().setColor(settings.backgroundColor());
    Button minimizeButton = component.getMinimizeButton();
    minimizeButton.getStyle().getBackground().setColor(settings.borderColor());
    minimizeButton.getStyle().setShadow(null);
    Button closeButton = component.getCloseButton();
    closeButton.getStyle().getBackground().setColor(settings.borderColor());
    closeButton.getStyle().setShadow(null);
    Component titleContainer = component.getTitleContainer();
    titleContainer.getStyle().getBackground().setColor(settings.borderColor());
    Button resizeButton = component.getResizeButton();
    resizeButton.getStyle().setBorder(null);
    resizeButton.getStyle().getBackground().setColor(ColorConstants.transparent());
    resizeButton.getHoveredStyle().getBackground().setColor(ColorConstants.transparent());
    resizeButton.getPressedStyle().getBackground().setColor(ColorConstants.transparent());
    CharIcon icon = new CharIcon(FontRegistry.MATERIAL_DESIGN_ICONS, '\uF45D');
    icon.setHorizontalAlign(HorizontalAlign.RIGHT);
    icon.setVerticalAlign(VerticalAlign.BOTTOM);
    icon.setColor(settings.textColor());
    resizeButton.getStyle().getBackground().setIcon(icon);
    resizeButton.getStyle().setShadow(null);
    component.getTitle().getStyle().setPadding(3f, 5f);
    Icon closeIcon = component.getCloseIcon();
    if (closeIcon instanceof CharIcon) {
        CharIcon bgIcon = (CharIcon) closeIcon;
        bgIcon.setColor(settings.textColor());
        bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
        bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
    }
    Icon minimizeIcon = component.getMinimizeIcon();
    if (minimizeIcon instanceof CharIcon) {
        CharIcon bgIcon = (CharIcon) minimizeIcon;
        bgIcon.setColor(settings.textColor());
        bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
        bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
    }
    Icon maximizeIcon = component.getMaximizeIcon();
    if (maximizeIcon instanceof CharIcon) {
        CharIcon bgIcon = (CharIcon) maximizeIcon;
        bgIcon.setColor(settings.textColor());
        bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
        bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
    }
    Themes.getDefaultTheme().applyAll(component.getContainer());
    component.getContainer().getStyle().setShadow(null);
}
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) Component(com.spinyowl.legui.component.Component)

Aggregations

Button (com.spinyowl.legui.component.Button)17 Component (com.spinyowl.legui.component.Component)9 SimpleLineBorder (com.spinyowl.legui.style.border.SimpleLineBorder)9 Label (com.spinyowl.legui.component.Label)8 RadioButton (com.spinyowl.legui.component.RadioButton)8 MouseClickEvent (com.spinyowl.legui.event.MouseClickEvent)7 Panel (com.spinyowl.legui.component.Panel)6 RadioButtonGroup (com.spinyowl.legui.component.RadioButtonGroup)6 Widget (com.spinyowl.legui.component.Widget)6 CursorEnterEvent (com.spinyowl.legui.event.CursorEnterEvent)6 CursorEnterEventListener (com.spinyowl.legui.listener.CursorEnterEventListener)6 MouseClickEventListener (com.spinyowl.legui.listener.MouseClickEventListener)6 ColorConstants (com.spinyowl.legui.style.color.ColorConstants)6 List (java.util.List)6 GLFW (org.lwjgl.glfw.GLFW)6 ToggleButton (com.spinyowl.legui.component.ToggleButton)5 Frame (com.spinyowl.legui.component.Frame)4 EventProcessorProvider (com.spinyowl.legui.listener.processor.EventProcessorProvider)4 CallbackKeeper (com.spinyowl.legui.system.context.CallbackKeeper)4 Context (com.spinyowl.legui.system.context.Context)4