From fa7453a44c37ab374ef3fbcaa8587edbf3103dd7 Mon Sep 17 00:00:00 2001 From: TomB_134 Date: Mon, 20 Dec 2021 01:34:57 +1100 Subject: [PATCH] Added a root button --- .../minimalmenu/screens/FolderScreen.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/minimalmenu/screens/FolderScreen.java b/src/main/java/minimalmenu/screens/FolderScreen.java index ed9ea94..e7698ae 100644 --- a/src/main/java/minimalmenu/screens/FolderScreen.java +++ b/src/main/java/minimalmenu/screens/FolderScreen.java @@ -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) {