Search in sources :

Example 1 with Panel

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

the class SingleClassExample2 method createPersonPanel.

private static Panel createPersonPanel() {
    Panel personPanel = new Panel();
    personPanel.getStyle().setPosition(RELATIVE);
    personPanel.getStyle().setMinHeight(80F);
    Label personIcon = new Label("\uF009", 10, 10, 60, 60);
    personIcon.getStyle().setFont(FontRegistry.MATERIAL_DESIGN_ICONS);
    personIcon.getStyle().setFontSize(60F);
    personIcon.getStyle().setBorder(new SimpleLineBorder(ColorConstants.black(), 1));
    personPanel.add(personIcon);
    Label username = new Label("John Doe", 80, 20, 100, 20);
    username.getStyle().setFontSize(20f);
    username.getStyle().setFont(FontRegistry.ROBOTO_BOLD);
    personPanel.add(username);
    Label position = new Label("Alien Protector", 80, 40, 100, 20);
    position.getStyle().setFontSize(14f);
    personPanel.add(position);
    return personPanel;
}
Also used : Panel(com.spinyowl.legui.component.Panel) Label(com.spinyowl.legui.component.Label) SimpleLineBorder(com.spinyowl.legui.style.border.SimpleLineBorder)

Example 2 with Panel

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

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

the class BoxLayoutDemo method createGuiElements.

@Override
protected void createGuiElements(Frame frame) {
    Component frameContainer = frame.getContainer();
    frameContainer.getStyle().setDisplay(DisplayType.FLEX);
    frameContainer.getStyle().getBackground().setColor(ColorConstants.lightGray());
    c1 = new Panel();
    frameContainer.add(c1);
    c2 = new Panel(0, 0, 100, 100);
    frameContainer.add(c2);
    c11 = new Panel();
    c1.add(c11);
    c12 = new Panel();
    c1.add(c12);
    c1.getStyle().getBackground().setColor(ColorConstants.lightGreen());
    c1.getStyle().setHeight(50f);
    c1.getStyle().setLeft(0f);
    c1.getStyle().setRight(0f);
    c2.getStyle().getBackground().setColor(ColorConstants.lightBlue());
    c2.getStyle().setHeight(50f);
    c2.getStyle().setLeft(0f);
    c2.getStyle().setRight(0f);
    c2.getStyle().setBottom(0f);
    c1.getStyle().setDisplay(DisplayType.FLEX);
    c1.getStyle().getFlexStyle().setFlexDirection(FlexDirection.ROW);
    c11.getStyle().setPosition(PositionType.ABSOLUTE);
    c11.getStyle().setTop(10f);
    c11.getStyle().setRight(0f);
    c11.getStyle().setWidth(50f);
    c11.getStyle().setHeight(50f);
    c12.getStyle().setPosition(PositionType.ABSOLUTE);
    c12.getStyle().setTop(10f);
    c12.getStyle().setRight(50f);
    c12.getStyle().setWidth(50f);
    c12.getStyle().setHeight(50f);
}
Also used : Panel(com.spinyowl.legui.component.Panel) Component(com.spinyowl.legui.component.Component)

Example 4 with Panel

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

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

the class ExampleGui method createNinePanels.

private void createNinePanels() {
    Panel p1 = new Panel(1 * 20, 10, 10, 10);
    this.add(p1);
    p1.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p2 = new Panel(2 * 20, 10, 10, 10);
    this.add(p2);
    p2.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p3 = new Panel(3 * 20, 10, 10, 10);
    this.add(p3);
    p3.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p4 = new Panel(4 * 20, 10, 10, 10);
    this.add(p4);
    p4.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p5 = new Panel(5 * 20, 10, 10, 10);
    this.add(p5);
    p5.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p6 = new Panel(6 * 20, 10, 10, 10);
    this.add(p6);
    p6.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p7 = new Panel(7 * 20, 10, 10, 10);
    this.add(p7);
    p7.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p8 = new Panel(8 * 20, 10, 10, 10);
    this.add(p8);
    p8.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
    Panel p9 = new Panel(9 * 20, 10, 10, 10);
    this.add(p9);
    p9.getListenerMap().addListener(FocusEvent.class, (FocusEventListener) System.out::println);
}
Also used : ScrollablePanel(com.spinyowl.legui.component.ScrollablePanel) SplitPanel(com.spinyowl.legui.component.SplitPanel) Panel(com.spinyowl.legui.component.Panel)

Aggregations

Panel (com.spinyowl.legui.component.Panel)9 SimpleLineBorder (com.spinyowl.legui.style.border.SimpleLineBorder)5 Button (com.spinyowl.legui.component.Button)4 Component (com.spinyowl.legui.component.Component)4 Label (com.spinyowl.legui.component.Label)4 Widget (com.spinyowl.legui.component.Widget)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ScrollablePanel (com.spinyowl.legui.component.ScrollablePanel)2 SplitPanel (com.spinyowl.legui.component.SplitPanel)2 TabbedPanel (com.spinyowl.legui.component.TabbedPanel)2 Tab (com.spinyowl.legui.component.TabbedPanel.Tab)2 TabStripPosition (com.spinyowl.legui.component.TabbedPanel.TabStripPosition)2 CursorEnterEvent (com.spinyowl.legui.event.CursorEnterEvent)2 KeyEvent (com.spinyowl.legui.event.KeyEvent)2 MouseClickEvent (com.spinyowl.legui.event.MouseClickEvent)2 CursorEnterEventListener (com.spinyowl.legui.listener.CursorEnterEventListener)2 MouseClickEventListener (com.spinyowl.legui.listener.MouseClickEventListener)2 PositionType (com.spinyowl.legui.style.Style.PositionType)2 ColorConstants (com.spinyowl.legui.style.color.ColorConstants)2 List (java.util.List)2