Search in sources :

Example 1 with MouseClickEventListener

use of com.spinyowl.legui.listener.MouseClickEventListener 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 MouseClickEventListener

use of com.spinyowl.legui.listener.MouseClickEventListener in project legui by SpinyOwl.

the class SelectBox method initialize.

/**
 * Used to initialize selectbox.
 */
private void initialize() {
    selectionListPanel.setHorizontalScrollBarVisible(false);
    selectionListPanel.getContainer().getStyle().setDisplay(DisplayType.FLEX);
    selectionListPanel.getContainer().getStyle().getFlexStyle().setFlexDirection(FlexDirection.COLUMN);
    selectionListPanel.getContainer().getStyle().getBackground().setColor(ColorConstants.lightBlue());
    this.getStyle().setDisplay(DisplayType.FLEX);
    expandIcon = new CharIcon(new Vector2f(expandButton.getSize()), DEFAULT_ICON_FONT, (char) EXPAND_ICON_CHAR, ColorConstants.black());
    collapseIcon = new CharIcon(new Vector2f(expandButton.getSize()), DEFAULT_ICON_FONT, (char) COLLAPSE_ICON_CHAR, ColorConstants.black());
    expandButton.getStyle().getBackground().setIcon(expandIcon);
    expandButton.getStyle().setMinimumSize(buttonWidth, 0);
    expandButton.getStyle().setMaximumSize(buttonWidth, Float.MAX_VALUE);
    expandButton.getStyle().setRight(0f);
    expandButton.getStyle().setTop(0f);
    expandButton.getStyle().setBottom(0f);
    selectionButton.getStyle().setTop(0f);
    selectionButton.getStyle().setLeft(0f);
    selectionButton.getStyle().setBottom(0f);
    selectionButton.getStyle().setRight(buttonWidth);
    this.add(expandButton);
    this.add(selectionButton);
    MouseClickEventListener mouseClickEventListener = new SelectBoxClickListener<>(this);
    selectionButton.getListenerMap().addListener(MouseClickEvent.class, mouseClickEventListener);
    expandButton.getListenerMap().addListener(MouseClickEvent.class, mouseClickEventListener);
    selectBoxLayer.getListenerMap().addListener(MouseClickEvent.class, mouseClickEventListener);
    FocusEventListener focusEventListener = new SelectBoxFocusListener<>(this);
    selectionListPanel.getVerticalScrollBar().getListenerMap().getListeners(FocusEvent.class).add(focusEventListener);
    selectionButton.getListenerMap().getListeners(FocusEvent.class).add(focusEventListener);
    expandButton.getListenerMap().getListeners(FocusEvent.class).add(focusEventListener);
    selectBoxLayer.add(selectionListPanel);
    SelectBoxAnimation animation = new SelectBoxAnimation(this, selectionListPanel);
    animation.startAnimation();
    Themes.getDefaultTheme().getThemeManager().getComponentTheme(SelectBox.class).applyAll(this);
}
Also used : SelectBoxClickListener(com.spinyowl.legui.component.misc.listener.selectbox.SelectBoxClickListener) SelectBoxFocusListener(com.spinyowl.legui.component.misc.listener.selectbox.SelectBoxFocusListener) MouseClickEventListener(com.spinyowl.legui.listener.MouseClickEventListener) FocusEventListener(com.spinyowl.legui.listener.FocusEventListener) Vector2f(org.joml.Vector2f) CharIcon(com.spinyowl.legui.icon.CharIcon) SelectBoxAnimation(com.spinyowl.legui.component.misc.animation.selectbox.SelectBoxAnimation) FocusEvent(com.spinyowl.legui.event.FocusEvent)

Example 3 with MouseClickEventListener

use of com.spinyowl.legui.listener.MouseClickEventListener in project legui by SpinyOwl.

the class ToggleButton method initialize.

/**
 * Initialize toggle button with default states.
 */
private void initialize() {
    getStyle().getBackground().setColor(ColorConstants.red());
    toggledBackgroundColor = ColorConstants.green();
    MouseClickEventListener toggleButtonClickListener = new ToggleButtonMouseClickListener();
    getListenerMap().addListener(MouseClickEvent.class, toggleButtonClickListener);
    Themes.getDefaultTheme().getThemeManager().getComponentTheme(ToggleButton.class).applyAll(this);
}
Also used : MouseClickEventListener(com.spinyowl.legui.listener.MouseClickEventListener) ToggleButtonMouseClickListener(com.spinyowl.legui.component.misc.listener.togglebutton.ToggleButtonMouseClickListener)

Example 4 with MouseClickEventListener

use of com.spinyowl.legui.listener.MouseClickEventListener in project legui by SpinyOwl.

the class ExampleGui method createWidgetsWithSomeButtons.

private void createWidgetsWithSomeButtons() {
    Widget widget = new Widget("Hello widget", 250, 170, 100, 100);
    widget.setTitleHeight(20);
    widget.getTitleContainer().getStyle().getBackground().setColor(ColorConstants.lightGreen());
    widget.getStyle().setTextColor(ColorConstants.black());
    String innerText = "Inner Widget; Resize events: ";
    Widget inner = new Widget(innerText + 0);
    inner.setResizable(false);
    inner.getStyle().setPosition(PositionType.RELATIVE);
    inner.getStyle().getFlexStyle().setFlexGrow(1);
    inner.getStyle().setMargin(10f);
    inner.getContainer().getStyle().getBackground().setColor(ColorConstants.lightGreen());
    widget.getContainer().getStyle().setDisplay(DisplayType.FLEX);
    widget.getContainer().add(inner);
    AtomicInteger counter = new AtomicInteger();
    inner.getListenerMap().addListener(ChangeSizeEvent.class, e -> {
        counter.getAndIncrement();
        inner.getTitle().getTextState().setText(innerText + "; Resize events: " + counter.get());
    });
    this.add(widget);
    Button turnWidVisible = new Button("", 360, 280, 20, 20);
    turnWidVisible.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (CLICK == (event.getAction())) {
            widget.show();
        }
    });
    Icon bgIm = new ImageIcon(ImageLoader.loadImage("com/spinyowl/legui/demo/1.png"));
    bgIm.setSize(new Vector2f(20, 20));
    turnWidVisible.getStyle().getBackground().setIcon(bgIm);
    Icon hbgIm = new ImageIcon(ImageLoader.loadImage("com/spinyowl/legui/demo/2.png"));
    hbgIm.setSize(new Vector2f(20, 20));
    // turnWidVisible.setHoveredBackgroundIcon(hbgIm);
    Icon pbIm = new ImageIcon(ImageLoader.loadImage("com/spinyowl/legui/demo/3.png"));
    pbIm.setSize(new Vector2f(20, 20));
    // turnWidVisible.setPressedBackgroundIcon(pbIm);
    this.add(turnWidVisible);
    Widget widget2 = new Widget("Hello 2 widget", 250, 310, 100, 100);
    widget2.setTitleHeight(20);
    widget2.setCloseButtonColor(ColorConstants.white());
    widget2.getCloseButton().getStyle().getBackground().setColor(ColorConstants.black());
    widget2.getTitleContainer().getStyle().getBackground().setColor(ColorConstants.lightGreen());
    widget2.getStyle().setTextColor(ColorConstants.black());
    widget2.setDraggable(false);
    widget2.setMinimizable(true);
    Button turnDraggable = new Button("Draggable", 10, 10, 80, 20);
    turnDraggable.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (event.getAction() == CLICK) {
            Dialog dialog = new Dialog("Question:", 300, 100);
            Label questionLabel = new Label("Are you sure want to turn " + (widget2.isDraggable() ? "off" : "on") + "this widget draggable?", 10, 10, 200, 20);
            Button yesButton = new Button("Yes", 10, 50, 50, 20);
            Button noButton = new Button("No", 70, 50, 50, 20);
            yesButton.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) e -> {
                if (CLICK == e.getAction()) {
                    widget2.setDraggable(!widget2.isDraggable());
                    dialog.close();
                }
            });
            noButton.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) e -> {
                if (CLICK == e.getAction()) {
                    dialog.close();
                }
            });
            dialog.getContainer().add(questionLabel);
            dialog.getContainer().add(yesButton);
            dialog.getContainer().add(noButton);
            dialog.show(event.getFrame());
        }
    });
    widget2.getContainer().add(turnDraggable);
    this.add(widget2);
    Button turnWidVisible2 = new Button("", 360, 310, 20, 20);
    turnWidVisible2.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (CLICK == event.getAction()) {
            widget2.show();
        }
    });
    this.add(turnWidVisible2);
    Widget widget3 = new Widget("Hello 2 widget", 250, 420, 100, 100);
    widget3.setTitleHeight(20);
    widget3.setTitleEnabled(false);
    widget3.getTitleContainer().getStyle().getBackground().setColor(ColorConstants.lightGreen());
    widget3.setCloseable(false);
    widget3.setMinimizable(true);
    widget3.getStyle().setTextColor(ColorConstants.black());
    this.add(widget3);
    Button turnWidVisible3 = new Button("", 360, 340, 20, 20);
    turnWidVisible3.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (CLICK == event.getAction()) {
            widget3.show();
        }
    });
    this.add(turnWidVisible3);
    widget3.getContainer().add(new Panel(5, 5, 20, 20));
    widget3.getContainer().add(new Panel(30, 5, 20, 20));
    widget3.getContainer().add(new Panel(30, 30, 20, 20));
    widget3.getContainer().add(new Panel(5, 30, 20, 20));
    Button b = new Button(55, 5, 40, 20);
    b.getStyle().setFont(FontRegistry.MATERIAL_ICONS_REGULAR);
    b.getStyle().setVerticalAlign(MIDDLE);
    b.getStyle().setHorizontalAlign(CENTER);
    b.getStyle().setFontSize(16f);
    String up = TextUtil.cpToStr(0xE5D8);
    String down = TextUtil.cpToStr(0xE5DB);
    b.getTextState().setText(down);
    b.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (event.getAction() == CLICK) {
            widget3.setTitleEnabled(!widget3.isTitleEnabled());
            b.getTextState().setText(widget3.isTitleEnabled() ? up : down);
        }
    });
    widget3.getContainer().add(b);
    Button b2 = new Button(55, 30, 40, 20);
    b2.getStyle().setVerticalAlign(MIDDLE);
    b2.getStyle().setHorizontalAlign(CENTER);
    b2.getStyle().setFontSize(16f);
    String up2 = "-";
    String down2 = "+";
    b2.getTextState().setText(down2);
    b2.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (event.getAction() == CLICK) {
            widget3.setCloseable(!widget3.isCloseable());
            b2.getTextState().setText(widget3.isCloseable() ? up2 : down2);
        }
    });
    widget3.getContainer().add(b2);
    widget3.getStyle().setMinWidth(100f);
    widget3.getStyle().setMinHeight(50f);
    widget3.getStyle().setMaxWidth(400f);
    widget3.getStyle().setMaxHeight(150f);
}
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) ImageIcon(com.spinyowl.legui.icon.ImageIcon) MouseClickEventListener(com.spinyowl.legui.listener.MouseClickEventListener) Widget(com.spinyowl.legui.component.Widget) Label(com.spinyowl.legui.component.Label) ScrollablePanel(com.spinyowl.legui.component.ScrollablePanel) SplitPanel(com.spinyowl.legui.component.SplitPanel) Panel(com.spinyowl.legui.component.Panel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Button(com.spinyowl.legui.component.Button) RadioButton(com.spinyowl.legui.component.RadioButton) ToggleButton(com.spinyowl.legui.component.ToggleButton) Vector2f(org.joml.Vector2f) Dialog(com.spinyowl.legui.component.Dialog) Icon(com.spinyowl.legui.icon.Icon) ImageIcon(com.spinyowl.legui.icon.ImageIcon) MouseClickEvent(com.spinyowl.legui.event.MouseClickEvent)

Example 5 with MouseClickEventListener

use of com.spinyowl.legui.listener.MouseClickEventListener in project legui by SpinyOwl.

the class ExampleGui method createToggleButtonWithLongTooltip.

private ToggleButton createToggleButtonWithLongTooltip() {
    ToggleButton toggleButton = new ToggleButton("", 100, 170, 40, 20);
    Icon bgImageNormal = new ImageIcon(ImageLoader.loadImage("com/spinyowl/legui/demo/toggle.png"));
    toggleButton.getListenerMap().addListener(CursorEnterEvent.class, (CursorEnterEventListener) System.out::println);
    toggleButton.setTooltip(new Tooltip("Just toggle button with long tooltipText text"));
    toggleButton.getListenerMap().addListener(CursorEnterEvent.class, (CursorEnterEventListener) event -> {
        if (event.isEntered()) {
            getColorAnimation(toggleButton, ColorConstants.blue()).startAnimation();
        } else {
            getColorAnimation(toggleButton, ColorConstants.red()).startAnimation();
        }
    });
    toggleButton.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> getSlideImageOnClick(toggleButton, bgImageNormal).startAnimation());
    toggleButton.getTooltip().setPosition(45, 0);
    toggleButton.getTooltip().getSize().set(140, 40);
    toggleButton.getTooltip().getStyle().getBackground().setColor(ColorConstants.darkGray());
    toggleButton.getTooltip().getStyle().setTextColor(ColorConstants.white());
    toggleButton.getTooltip().getStyle().setPadding(4f);
    int[] id = { 0 };
    toggleButton.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
        if (event.getAction().equals(CLICK)) {
            id[0]++;
            HorizontalAlign h = LEFT;
            VerticalAlign v = TOP;
            int hh = id[0] % 3;
            int vv = (id[0] / 3) % 3;
            switch(hh) {
                case 0:
                    h = LEFT;
                    break;
                case 1:
                    h = CENTER;
                    break;
                case 2:
                    h = RIGHT;
                    break;
            }
            switch(vv) {
                case 0:
                    v = TOP;
                    break;
                case 1:
                    v = MIDDLE;
                    break;
                case 2:
                    v = BOTTOM;
                    break;
            }
            System.out.println(h + " " + v);
            toggleButton.getTooltip().getStyle().setHorizontalAlign(h);
            toggleButton.getTooltip().getStyle().setVerticalAlign(v);
        }
    });
    bgImageNormal.setSize(new Vector2f(100 * 40 / 60, 20));
    bgImageNormal.setPosition(new Vector2f(40 - 100 * 40 / 60, 0));
    toggleButton.getStyle().getBackground().setIcon(bgImageNormal);
    return toggleButton;
}
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) ImageIcon(com.spinyowl.legui.icon.ImageIcon) ToggleButton(com.spinyowl.legui.component.ToggleButton) VerticalAlign(com.spinyowl.legui.component.optional.align.VerticalAlign) Vector2f(org.joml.Vector2f) Tooltip(com.spinyowl.legui.component.Tooltip) HorizontalAlign(com.spinyowl.legui.component.optional.align.HorizontalAlign) Icon(com.spinyowl.legui.icon.Icon) ImageIcon(com.spinyowl.legui.icon.ImageIcon)

Aggregations

MouseClickEventListener (com.spinyowl.legui.listener.MouseClickEventListener)9 Button (com.spinyowl.legui.component.Button)7 Component (com.spinyowl.legui.component.Component)7 Label (com.spinyowl.legui.component.Label)7 RadioButton (com.spinyowl.legui.component.RadioButton)6 RadioButtonGroup (com.spinyowl.legui.component.RadioButtonGroup)6 CursorEnterEvent (com.spinyowl.legui.event.CursorEnterEvent)6 MouseClickEvent (com.spinyowl.legui.event.MouseClickEvent)6 CursorEnterEventListener (com.spinyowl.legui.listener.CursorEnterEventListener)6 SimpleLineBorder (com.spinyowl.legui.style.border.SimpleLineBorder)6 ColorConstants (com.spinyowl.legui.style.color.ColorConstants)6 List (java.util.List)6 GLFW (org.lwjgl.glfw.GLFW)6 Frame (com.spinyowl.legui.component.Frame)4 Panel (com.spinyowl.legui.component.Panel)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 LayoutManager (com.spinyowl.legui.system.layout.LayoutManager)4 Renderer (com.spinyowl.legui.system.renderer.Renderer)4