Skip to content

Commit

Permalink
Continued with Layout adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
lukflug committed Mar 15, 2021
1 parent 39c0613 commit 7ead5f0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -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> animation;
protected final IPopupPositioner popupPos;
protected final BiFunction<Context,Integer,Integer> popupHeight;

public ChildUtil (int width, Supplier<Animation> animation, IPopupPositioner popupPos, BiFunction<Context,Integer,Integer> popupHeight) {
this.width=width;
this.animation=animation;
this.popupPos=popupPos;
this.popupHeight=popupHeight;
}

protected <T> void addContainer (ILabeled label, IComponent title, VerticalContainer container, Supplier<T> state, Class<T> stateClass, VerticalContainer parent, IComponentAdder gui, ITheme theme, int logicalLevel, int graphicalLevel, ChildMode mode) {
DraggableComponent<FixedComponent<ClosableComponent<ComponentProxy<IComponent>,ScrollBarComponent<Void,VerticalContainer>>>> popup;
IToggleable toggle;
boolean drawTitle=mode==ChildMode.DRAG_POPUP;
switch (mode) {
case DOWN:
parent.addComponent(new ClosableComponent<IComponent,VerticalContainer>(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<IComponent>(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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,11 +36,10 @@ public class PanelLayout implements ILayout {
protected final Supplier<Animation> animation;
protected final IntPredicate deleteKey;
protected final IntFunction<ChildMode> layoutType;
protected final Supplier<ChildMode> colorType;
protected final IPopupPositioner popupPos;
protected final BiFunction<Context,Integer,Integer> popupHeight;
protected final ChildMode colorType;
protected final ChildUtil util;

public PanelLayout (int width, Point start, int skipX, int skipY, Supplier<Animation> animation, IntPredicate deleteKey, IntFunction<ChildMode> layoutType, Supplier<ChildMode> colorType, IPopupPositioner popupPos, BiFunction<Context,Integer,Integer> popupHeight) {
public PanelLayout (int width, Point start, int skipX, int skipY, Supplier<Animation> animation, IntPredicate deleteKey, IntFunction<ChildMode> layoutType, ChildMode colorType, IPopupPositioner popupPos, BiFunction<Context,Integer,Integer> popupHeight) {
this.width=width;
this.start=start;
this.skipX=skipX;
Expand All @@ -58,8 +48,7 @@ public PanelLayout (int width, Point start, int skipX, int skipY, Supplier<Anima
this.deleteKey=deleteKey;
this.layoutType=layoutType;
this.colorType=colorType;
this.popupPos=popupPos;
this.popupHeight=popupHeight;
util=new ChildUtil(width,animation,popupPos,popupHeight);
}

@Override
Expand All @@ -79,40 +68,13 @@ public void populateGUI(IComponentAdder gui, IClient client, ITheme theme) {
if (module.isEnabled()==null) moduleTitle=new Button(module,theme.getButtonRenderer(Void.class,1,1,mode==ChildMode.DOWN));
else moduleTitle=new ToggleButton(module,module.isEnabled(),theme.getButtonRenderer(IBoolean.class,1,1,mode==ChildMode.DOWN));
VerticalContainer moduleContainer=new VerticalContainer(module,theme.getContainerRenderer(1,graphicalLevel,false));
if (module.isEnabled()==null) addContainer(module,moduleTitle,moduleContainer,()->null,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 <T> void addContainer (ILabeled label, IComponent title, VerticalContainer container, Supplier<T> state, Class<T> stateClass, VerticalContainer parent, IComponentAdder gui, ITheme theme, int logicalLevel, int graphicalLevel, ChildMode mode) {
DraggableComponent<FixedComponent<ClosableComponent<ComponentProxy<IComponent>,ScrollBarComponent<Void,VerticalContainer>>>> popup;
IToggleable toggle;
boolean drawTitle=mode==ChildMode.DRAG_POPUP;
switch (mode) {
case DOWN:
parent.addComponent(new ClosableComponent<IComponent,VerticalContainer>(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<IComponent>(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 <T> void addSettingsComponent (ISetting<T> setting, VerticalContainer container, IComponentAdder gui, ITheme theme, int logicalLevel, int graphicalLevel) {
int nextLevel=(layoutType.apply(logicalLevel-1)==ChildMode.DOWN)?graphicalLevel:0;
IComponent component;
Expand All @@ -124,10 +86,10 @@ protected <T> void addSettingsComponent (ISetting<T> 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)) {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
public class StackedPanelAdder implements IComponentAdder {
protected final IContainer<? super IFixedComponent> container;
protected VerticalContainer content;
protected final ChildUtil util;

public StackedPanelAdder (IContainer<? super IFixedComponent> container, ILabeled label, ITheme theme, Point position, int width, Supplier<Animation> animation) {
public StackedPanelAdder (IContainer<? super IFixedComponent> container, ILabeled label, ITheme theme, Point position, int width, Supplier<Animation> 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 <S extends IComponent,T extends IComponent> void addComponent(S title, T content, ITheme theme, int logicalLevel, int graphicalLevel, Point position, int width, Supplier<Animation> animation) {
this.content.addComponent(new ClosableComponent<S,T>(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
Expand Down

0 comments on commit 7ead5f0

Please sign in to comment.