From 7ead5f0f7541fc77e133d5061724710dc6b4ba74 Mon Sep 17 00:00:00 2001 From: lukflug Date: Mon, 15 Mar 2021 20:26:42 +0100 Subject: [PATCH] Continued with Layout adjustments --- .../lukflug/panelstudio/layout/ChildUtil.java | 66 +++++++++++++++++++ .../panelstudio/layout/PanelLayout.java | 66 ++++--------------- .../panelstudio/layout/StackedPanelAdder.java | 5 +- 3 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java new file mode 100644 index 0000000..45cb8c2 --- /dev/null +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java @@ -0,0 +1,66 @@ +package com.lukflug.panelstudio.layout; + +import java.util.function.BiFunction; +import java.util.function.Supplier; + +import com.lukflug.panelstudio.base.Animation; +import com.lukflug.panelstudio.base.Context; +import com.lukflug.panelstudio.base.IInterface; +import com.lukflug.panelstudio.base.IToggleable; +import com.lukflug.panelstudio.base.SimpleToggleable; +import com.lukflug.panelstudio.component.ComponentProxy; +import com.lukflug.panelstudio.component.DraggableComponent; +import com.lukflug.panelstudio.component.FixedComponent; +import com.lukflug.panelstudio.component.IComponent; +import com.lukflug.panelstudio.container.VerticalContainer; +import com.lukflug.panelstudio.setting.ILabeled; +import com.lukflug.panelstudio.setting.Labeled; +import com.lukflug.panelstudio.theme.ITheme; +import com.lukflug.panelstudio.widget.Button; +import com.lukflug.panelstudio.widget.ClosableComponent; +import com.lukflug.panelstudio.widget.ScrollBarComponent; + +public class ChildUtil { + protected final int width; + protected final Supplier animation; + protected final IPopupPositioner popupPos; + protected final BiFunction popupHeight; + + public ChildUtil (int width, Supplier animation, IPopupPositioner popupPos, BiFunction popupHeight) { + this.width=width; + this.animation=animation; + this.popupPos=popupPos; + this.popupHeight=popupHeight; + } + + protected void addContainer (ILabeled label, IComponent title, VerticalContainer container, Supplier state, Class stateClass, VerticalContainer parent, IComponentAdder gui, ITheme theme, int logicalLevel, int graphicalLevel, ChildMode mode) { + DraggableComponent,ScrollBarComponent>>> popup; + IToggleable toggle; + boolean drawTitle=mode==ChildMode.DRAG_POPUP; + switch (mode) { + case DOWN: + parent.addComponent(new ClosableComponent(title,container,state,new SimpleToggleable(false),animation.get(),theme.getPanelRenderer(stateClass,logicalLevel,graphicalLevel))); + break; + case POPUP: + case DRAG_POPUP: + toggle=new SimpleToggleable(false); + popup=ClosableComponent.createPopup(new Button(new Labeled(label.getDisplayName(),label.getDescription(),()->drawTitle&&label.isVisible().isOn()),theme.getButtonRenderer(Void.class,logicalLevel,graphicalLevel,true)),container,animation.get(),theme.getPanelRenderer(Void.class,logicalLevel,graphicalLevel),theme.getScrollBarRenderer(Void.class,logicalLevel,graphicalLevel),theme.getEmptySpaceRenderer(Void.class,logicalLevel,graphicalLevel),popupHeight,toggle,width,false); + parent.addComponent(new ComponentProxy(title) { + @Override + public void handleButton (Context context, int button) { + super.handleButton(context,button); + if (button==IInterface.RBUTTON && context.isHovered() && !context.getInterface().getButton(IInterface.RBUTTON)) { + context.getPopupDisplayer().displayPopup(popup,context.getRect(),toggle,popupPos); + context.releaseFocus(); + } + } + }); + gui.addPopup(popup); + break; + } + } + + public enum ChildMode { + DOWN,POPUP,DRAG_POPUP; + } +} diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java index 19db909..68c9401 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java @@ -10,32 +10,23 @@ import com.lukflug.panelstudio.base.Animation; import com.lukflug.panelstudio.base.Context; import com.lukflug.panelstudio.base.IBoolean; -import com.lukflug.panelstudio.base.IInterface; -import com.lukflug.panelstudio.base.IToggleable; -import com.lukflug.panelstudio.base.SimpleToggleable; -import com.lukflug.panelstudio.component.ComponentProxy; -import com.lukflug.panelstudio.component.DraggableComponent; -import com.lukflug.panelstudio.component.FixedComponent; import com.lukflug.panelstudio.component.FocusableComponent; import com.lukflug.panelstudio.component.IComponent; import com.lukflug.panelstudio.container.VerticalContainer; +import com.lukflug.panelstudio.layout.ChildUtil.ChildMode; import com.lukflug.panelstudio.setting.IBooleanSetting; import com.lukflug.panelstudio.setting.IClient; import com.lukflug.panelstudio.setting.IColorSetting; import com.lukflug.panelstudio.setting.IEnumSetting; import com.lukflug.panelstudio.setting.IKeybindSetting; -import com.lukflug.panelstudio.setting.ILabeled; import com.lukflug.panelstudio.setting.INumberSetting; import com.lukflug.panelstudio.setting.ISetting; -import com.lukflug.panelstudio.setting.Labeled; import com.lukflug.panelstudio.theme.ITheme; import com.lukflug.panelstudio.widget.Button; -import com.lukflug.panelstudio.widget.ClosableComponent; import com.lukflug.panelstudio.widget.ColorComponent; import com.lukflug.panelstudio.widget.CycleButton; import com.lukflug.panelstudio.widget.KeybindComponent; import com.lukflug.panelstudio.widget.NumberSlider; -import com.lukflug.panelstudio.widget.ScrollBarComponent; import com.lukflug.panelstudio.widget.ToggleButton; public class PanelLayout implements ILayout { @@ -45,11 +36,10 @@ public class PanelLayout implements ILayout { protected final Supplier animation; protected final IntPredicate deleteKey; protected final IntFunction layoutType; - protected final Supplier colorType; - protected final IPopupPositioner popupPos; - protected final BiFunction popupHeight; + protected final ChildMode colorType; + protected final ChildUtil util; - public PanelLayout (int width, Point start, int skipX, int skipY, Supplier animation, IntPredicate deleteKey, IntFunction layoutType, Supplier colorType, IPopupPositioner popupPos, BiFunction popupHeight) { + public PanelLayout (int width, Point start, int skipX, int skipY, Supplier animation, IntPredicate deleteKey, IntFunction layoutType, ChildMode colorType, IPopupPositioner popupPos, BiFunction popupHeight) { this.width=width; this.start=start; this.skipX=skipX; @@ -58,8 +48,7 @@ public PanelLayout (int width, Point start, int skipX, int skipY, Suppliernull,Void.class,categoryContent,gui,theme,1,graphicalLevel,layoutType.apply(0)); - else addContainer(module,moduleTitle,moduleContainer,()->module.isEnabled(),IBoolean.class,categoryContent,gui,theme,1,graphicalLevel,layoutType.apply(0)); + if (module.isEnabled()==null) util.addContainer(module,moduleTitle,moduleContainer,()->null,Void.class,categoryContent,gui,theme,1,graphicalLevel,layoutType.apply(0)); + else util.addContainer(module,moduleTitle,moduleContainer,()->module.isEnabled(),IBoolean.class,categoryContent,gui,theme,1,graphicalLevel,layoutType.apply(0)); module.getSettings().forEach(setting->addSettingsComponent(setting,moduleContainer,gui,theme,2,graphicalLevel+1)); }); }); } - protected void addContainer (ILabeled label, IComponent title, VerticalContainer container, Supplier state, Class stateClass, VerticalContainer parent, IComponentAdder gui, ITheme theme, int logicalLevel, int graphicalLevel, ChildMode mode) { - DraggableComponent,ScrollBarComponent>>> popup; - IToggleable toggle; - boolean drawTitle=mode==ChildMode.DRAG_POPUP; - switch (mode) { - case DOWN: - parent.addComponent(new ClosableComponent(title,container,state,new SimpleToggleable(false),animation.get(),theme.getPanelRenderer(stateClass,logicalLevel,graphicalLevel))); - break; - case POPUP: - case DRAG_POPUP: - toggle=new SimpleToggleable(false); - popup=ClosableComponent.createPopup(new Button(new Labeled(label.getDisplayName(),label.getDescription(),()->drawTitle&&label.isVisible().isOn()),theme.getButtonRenderer(Void.class,logicalLevel,graphicalLevel,true)),container,animation.get(),theme.getPanelRenderer(Void.class,logicalLevel,graphicalLevel),theme.getScrollBarRenderer(Void.class,logicalLevel,graphicalLevel),theme.getEmptySpaceRenderer(Void.class,logicalLevel,graphicalLevel),popupHeight,toggle,width,false); - parent.addComponent(new ComponentProxy(title) { - @Override - public void handleButton (Context context, int button) { - super.handleButton(context,button); - if (button==IInterface.RBUTTON && context.isHovered() && !context.getInterface().getButton(IInterface.RBUTTON)) { - context.getPopupDisplayer().displayPopup(popup,context.getRect(),toggle,popupPos); - context.releaseFocus(); - } - } - }); - gui.addPopup(popup); - break; - } - } - protected void addSettingsComponent (ISetting setting, VerticalContainer container, IComponentAdder gui, ITheme theme, int logicalLevel, int graphicalLevel) { int nextLevel=(layoutType.apply(logicalLevel-1)==ChildMode.DOWN)?graphicalLevel:0; IComponent component; @@ -124,10 +86,10 @@ protected void addSettingsComponent (ISetting setting, VerticalContainer } else if (setting instanceof IEnumSetting) { component=new CycleButton((IEnumSetting)setting,theme.getButtonRenderer(String.class,logicalLevel,graphicalLevel,isContainer)); } else if (setting instanceof IColorSetting) { - int colorLevel=(colorType.get()==ChildMode.DOWN)?graphicalLevel:0; - VerticalContainer colorContainer=new ColorComponent((IColorSetting)setting,animation.get(),theme,logicalLevel,nextLevel); - addContainer(setting,new Button(setting,theme.getButtonRenderer(Void.class,logicalLevel,graphicalLevel,true)),colorContainer,()->setting.getSettingState(),setting.getSettingClass(),container,gui,theme,logicalLevel,colorLevel,colorType.get()); - if (isContainer) setting.getSubSettings().forEach(subSetting->addSettingsComponent(subSetting,colorContainer,gui,theme,logicalLevel+1,nextLevel+1)); + int colorLevel=(colorType==ChildMode.DOWN)?graphicalLevel:0; + VerticalContainer colorContainer=new ColorComponent((IColorSetting)setting,animation.get(),theme,logicalLevel,colorLevel); + util.addContainer(setting,new Button(setting,theme.getButtonRenderer(Void.class,logicalLevel,graphicalLevel,true)),colorContainer,()->setting.getSettingState(),setting.getSettingClass(),container,gui,theme,logicalLevel,colorLevel,colorType); + if (isContainer) setting.getSubSettings().forEach(subSetting->addSettingsComponent(subSetting,colorContainer,gui,theme,logicalLevel+1,colorLevel+1)); return; } else if (setting instanceof IKeybindSetting) { component=new KeybindComponent((IKeybindSetting)setting,theme.getKeybindRenderer(logicalLevel,graphicalLevel,isContainer)) { @@ -141,14 +103,10 @@ public int transformKey (int scancode) { } if (isContainer) { VerticalContainer settingContainer=new VerticalContainer(setting,theme.getContainerRenderer(logicalLevel,nextLevel,false)); - addContainer(setting,component,settingContainer,()->setting.getSettingState(),setting.getSettingClass(),container,gui,theme,logicalLevel,nextLevel,layoutType.apply(logicalLevel-1)); + util.addContainer(setting,component,settingContainer,()->setting.getSettingState(),setting.getSettingClass(),container,gui,theme,logicalLevel,nextLevel,layoutType.apply(logicalLevel-1)); setting.getSubSettings().forEach(subSetting->addSettingsComponent(subSetting,settingContainer,gui,theme,logicalLevel+1,nextLevel+1)); } else { container.addComponent(component); } } - - public enum ChildMode { - DOWN,POPUP,DRAG_POPUP; - } } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java index bd9df44..a15f692 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java @@ -18,16 +18,19 @@ public class StackedPanelAdder implements IComponentAdder { protected final IContainer container; protected VerticalContainer content; + protected final ChildUtil util; - public StackedPanelAdder (IContainer container, ILabeled label, ITheme theme, Point position, int width, Supplier animation) { + public StackedPanelAdder (IContainer container, ILabeled label, ITheme theme, Point position, int width, Supplier animation, IPopupPositioner popupPos) { this.container=container; content=new VerticalContainer(label,theme.getContainerRenderer(-1,-1,true)); container.addComponent(ClosableComponent.createDraggableComponent(new Button(label,theme.getButtonRenderer(Void.class,-1,-1,true)),content,()->null,new SimpleToggleable(true),animation.get(),theme.getPanelRenderer(Void.class,-1,-1),theme.getScrollBarRenderer(Void.class,-1,-1),theme.getEmptySpaceRenderer(Void.class,-1,-1),this::getScrollHeight,this::getComponentWidth,position,width,false)); + util=new ChildUtil(width,animation,popupPos,this::getScrollHeight); } @Override public void addComponent(S title, T content, ITheme theme, int logicalLevel, int graphicalLevel, Point position, int width, Supplier animation) { this.content.addComponent(new ClosableComponent(title,content,()->null,new SimpleToggleable(false),animation.get(),theme.getPanelRenderer(Void.class,logicalLevel,graphicalLevel))); + //util.addContainer(title, title, null, null, null, null, null, theme, logicalLevel, graphicalLevel, null); } @Override