Skip to content

Commit

Permalink
fix: sidebar switch btn width #101
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Dec 6, 2023
1 parent 79140ea commit 42aef60
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/informatis/ui/fragments/SidebarSwitcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import arc.scene.actions.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.Log;
import mindustry.*;
import mindustry.game.EventType;
import mindustry.gen.*;
import mindustry.graphics.Pal;

Expand All @@ -16,39 +18,42 @@ public class SidebarSwitcher {
private final Table sidebarTable = new Table();
private final Table[] sidebars;

private final ImageButton switchButton = new ImageButton(style) {
private final ImageButton switchButton = new ImageButton() {
@Override
public void draw() {
super.draw();
Lines.stroke(5, Pal.gray);
Lines.line(this.x, this.y + this.height, this.x + this.width, this.y + this.height);
}
{
setStyle(new ImageButton.ImageButtonStyle() {{
up = Tex.buttonEdge4;
imageUp = Icon.right;
}});
clicked(() -> {
Table[] sidebars = getSidebars();
Element currentSidebar = sidebars[showIndex];
showIndex = (showIndex + 1) % sidebars.length;
Element nextSidebar = sidebars[showIndex];

Log.info(sidebars[showIndex].getWidth());
Log.info(sidebars[showIndex].getMinWidth());
Log.info(sidebars[showIndex].getPrefWidth());
actShowMoveX(currentSidebar, 0, -currentSidebar.getWidth());
actShowMoveX(nextSidebar, -nextSidebar.getWidth(),0);
actResizeWidth(this, nextSidebar.getWidth());
});
}};
private static final ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle() {{
up = Tex.buttonEdge4;
imageUp = Icon.right;
}};

public SidebarSwitcher(Table ...sidebars) {
this.sidebars = sidebars;
rebuildSidebarTable();

Vars.ui.hudGroup.fill(t -> {
t.name = "informatis sidebar";
t.left();
t.add(sidebarTable);
});
rebuildSidebarTable();
}

private static void actShowMoveX(Element element, float from, float to) {
Expand Down Expand Up @@ -90,13 +95,18 @@ public void rebuildSidebarTable() {
elem.visible = false;
}
sidebars[showIndex].visible = true;
actResizeWidth(switchButton, sidebars[showIndex].getWidth());

sidebarTable.clear();
sidebarTable.top().left();
sidebarTable.add(sidebarTables).grow();
sidebarTable.row();
sidebarTable.add(switchButton).growX();
Cell cell = sidebarTable.add(switchButton).left();

sidebars[showIndex].invalidate();
Log.info(sidebars[showIndex].getWidth());
Log.info(sidebars[showIndex].getMinWidth());
Log.info(sidebars[showIndex].getPrefWidth());
cell.minWidth(sidebars[showIndex].getPrefWidth());
}

private Table[] getSidebars() {
Expand Down

0 comments on commit 42aef60

Please sign in to comment.