Skip to content

Commit

Permalink
Added a root button
Browse files Browse the repository at this point in the history
  • Loading branch information
TomB-134 committed Dec 19, 2021
1 parent e1dc582 commit fa7453a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/main/java/minimalmenu/screens/FolderScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ public void init() {
String[] directories = file.list((dir, name) -> new File(dir, name).isDirectory());

int y = (directories.length * 24) / 2;
for (int i = 0; i < directories.length; i++) {
int x = i;
ButtonWidget buttonWidget = new ButtonWidget(this.width / 2 - 100, (this.height / 2 + i*24) - y, 200, 20, new LiteralText(directories[x]), (button -> {
File fileToOpen = new File(file.getAbsolutePath() + File.separator + directories[x]);
System.out.println(fileToOpen.getAbsolutePath());
Util.getOperatingSystem().open(fileToOpen);
}));

this.addDrawableChild(buttonWidget);
for (int i = 0; i <= directories.length; i++) {
if (i < directories.length) {
int x = i;
ButtonWidget buttonWidget = new ButtonWidget(this.width / 2 - 100, (this.height / 2 + i * 24) - y, 200, 20, new LiteralText(directories[x]), (button -> {
File fileToOpen = new File(file.getAbsolutePath() + File.separator + directories[x]);
System.out.println(fileToOpen.getAbsolutePath());
Util.getOperatingSystem().open(fileToOpen);
}));
this.addDrawableChild(buttonWidget);
} else {
ButtonWidget rootButton = new ButtonWidget(this.width / 2 - 100, (this.height / 2 + (i+1) * 24) - y, 200, 20, new LiteralText(file.getName()), button -> {
Util.getOperatingSystem().open(file);
});
this.addDrawableChild(rootButton);
}
}

}

public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
Expand Down

0 comments on commit fa7453a

Please sign in to comment.