Search in sources :

Example 1 with Widget

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

the class ExampleGui method createShadowWidget.

private Widget createShadowWidget() {
    Widget shadowWidget = new Widget(20, 310, 200, 120);
    shadowWidget.getTitleTextState().setText("Shadow test widget");
    shadowWidget.setCloseable(false);
    shadowWidget.setResizable(false);
    shadowWidget.setAscendible(true);
    shadowWidget.getStyle().setShadow(new Shadow());
    shadowWidget.getStyle().getShadow().setColor(ColorConstants.red());
    Slider hOffsetSlider = new Slider(110, 5 + 20 * 0, 80, 10);
    shadowWidget.getContainer().add(hOffsetSlider);
    hOffsetSlider.setValue(50f);
    hOffsetSlider.addSliderChangeValueEventListener((e) -> shadowWidget.getStyle().getShadow().sethOffset(hOffsetSlider.getValue() - 50f));
    Label hOffsetLabel = new Label(10, 2 + 20 * 0, 90, 14);
    hOffsetLabel.getStyle().setFontSize(12f);
    hOffsetLabel.getHoveredStyle().setFontSize(14f);
    hOffsetLabel.getTextState().setText("HOffset: ");
    shadowWidget.getContainer().add(hOffsetLabel);
    Slider vOffsetSlider = new Slider(110, 2 + 20 * 1, 80, 14);
    shadowWidget.getContainer().add(vOffsetSlider);
    vOffsetSlider.setValue(50f);
    vOffsetSlider.addSliderChangeValueEventListener((e) -> shadowWidget.getStyle().getShadow().setvOffset(vOffsetSlider.getValue() - 50f));
    Label vOffsetLabel = new Label(10, 2 + 20 * 1, 90, 14);
    vOffsetLabel.getTextState().setText("VOffset: ");
    shadowWidget.getContainer().add(vOffsetLabel);
    Slider blurSlider = new Slider(110, 2 + 20 * 2, 80, 14);
    shadowWidget.getContainer().add(blurSlider);
    blurSlider.addSliderChangeValueEventListener((e) -> shadowWidget.getStyle().getShadow().setBlur(blurSlider.getValue()));
    Label blurLabel = new Label(10, 2 + 20 * 2, 90, 14);
    blurLabel.getTextState().setText("Blur: ");
    shadowWidget.getContainer().add(blurLabel);
    Slider spreadSlider = new Slider(110, 2 + 20 * 3, 80, 14);
    shadowWidget.getContainer().add(spreadSlider);
    spreadSlider.setValue(50f);
    spreadSlider.addSliderChangeValueEventListener((e) -> shadowWidget.getStyle().getShadow().setSpread(spreadSlider.getValue() - 50f));
    Label spreadLabel = new Label(10, 2 + 20 * 3, 90, 14);
    spreadLabel.getTextState().setText("Spread: ");
    shadowWidget.getContainer().add(spreadLabel);
    Slider transparencySlider = new Slider(110, 2 + 20 * 4, 80, 14);
    shadowWidget.getContainer().add(transparencySlider);
    transparencySlider.addSliderChangeValueEventListener((e) -> {
        shadowWidget.getStyle().getBackground().getColor().w = 1 - transparencySlider.getValue() / 100f;
        shadowWidget.getContainer().getStyle().getBackground().getColor().w = 1 - transparencySlider.getValue() / 100f;
    });
    Label transparencyLabel = new Label(10, 2 + 20 * 4, 90, 14);
    transparencyLabel.getTextState().setText("W Transparency: ");
    shadowWidget.getContainer().add(transparencyLabel);
    return shadowWidget;
}
Also used : Slider(com.spinyowl.legui.component.Slider) Widget(com.spinyowl.legui.component.Widget) Label(com.spinyowl.legui.component.Label) Shadow(com.spinyowl.legui.style.shadow.Shadow)

Example 2 with Widget

use of com.spinyowl.legui.component.Widget 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 Widget

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

the class WidgetTreeExample method checkAndCollapse.

private void checkAndCollapse(Widget root, Widget widget) {
    Component parent = widget.getParent();
    if (parent != null) {
        // collapse sibling widgets
        for (Component sibling : parent.getChildComponents()) {
            if (sibling instanceof Widget && sibling != widget) {
                Widget siblingWidget = (Widget) sibling;
                collapseChildWidgets(siblingWidget);
                siblingWidget.setMinimized(true);
            }
        }
        Component pp = parent.getParent();
        if (pp instanceof Widget) {
            Widget parentWidget = (Widget) pp;
            if (parentWidget != root) {
                checkAndCollapse(root, parentWidget);
            }
        }
    }
}
Also used : Widget(com.spinyowl.legui.component.Widget) Component(com.spinyowl.legui.component.Component)

Example 4 with Widget

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

the class WidgetTreeExample method collapseChildWidgets.

private void collapseChildWidgets(Widget widget) {
    for (Component child : widget.getContainer().getChildComponents()) {
        if (child instanceof Widget) {
            Widget childWidget = (Widget) child;
            collapseChildWidgets(childWidget);
            childWidget.setMinimized(true);
        }
    }
}
Also used : Widget(com.spinyowl.legui.component.Widget) Component(com.spinyowl.legui.component.Component)

Example 5 with Widget

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

the class MouseClickEventHandler method pushWidgetsUp.

private void pushWidgetsUp(Component gui) {
    Component parent = gui.getParent();
    Component current = gui;
    if (parent != null) {
        boolean push = false;
        while (parent != null) {
            if (parent instanceof Widget) {
                Widget widget = (Widget) parent;
                push = widget.isAscendible() && (parent.getParent() != null) && (parent.getParent().getStyle().getDisplay() == DisplayType.MANUAL);
            }
            current = parent;
            parent = parent.getParent();
            if (push) {
                break;
            }
        }
        if (push) {
            parent.remove(current);
            parent.add(current);
        }
    }
}
Also used : Widget(com.spinyowl.legui.component.Widget) Component(com.spinyowl.legui.component.Component)

Aggregations

Widget (com.spinyowl.legui.component.Widget)15 Component (com.spinyowl.legui.component.Component)5 ImageView (com.spinyowl.legui.component.ImageView)4 Button (com.spinyowl.legui.component.Button)3 Label (com.spinyowl.legui.component.Label)3 Panel (com.spinyowl.legui.component.Panel)3 Frame (com.spinyowl.legui.component.Frame)2 Slider (com.spinyowl.legui.component.Slider)2 DisplayType (com.spinyowl.legui.style.Style.DisplayType)2 PositionType (com.spinyowl.legui.style.Style.PositionType)2 Context (com.spinyowl.legui.system.context.Context)2 DefaultCallbackKeeper (com.spinyowl.legui.system.context.DefaultCallbackKeeper)2 SystemEventProcessorImpl (com.spinyowl.legui.system.handler.processor.SystemEventProcessorImpl)2 NvgRenderer (com.spinyowl.legui.system.renderer.nvg.NvgRenderer)2 GLFW (org.lwjgl.glfw.GLFW)2 Animation (com.spinyowl.legui.animation.Animation)1 AnimatorProvider (com.spinyowl.legui.animation.AnimatorProvider)1 CheckBox (com.spinyowl.legui.component.CheckBox)1 Dialog (com.spinyowl.legui.component.Dialog)1 PasswordInput (com.spinyowl.legui.component.PasswordInput)1