aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl3/gui/tab
diff options
context:
space:
mode:
authorisxander <xander@isxander.dev>2024-04-11 18:43:06 +0100
committerisxander <xander@isxander.dev>2024-04-11 18:43:06 +0100
commit04fe933f4c24817100f3101f088accf55a621f8a (patch)
treefeff94ca3ab4484160e69a24f4ee38522381950e /common/src/main/java/dev/isxander/yacl3/gui/tab
parent831b894fdb7fe3e173d81387c8f6a2402b8ccfa9 (diff)
downloadYetAnotherConfigLib-04fe933f4c24817100f3101f088accf55a621f8a.tar.gz
YetAnotherConfigLib-04fe933f4c24817100f3101f088accf55a621f8a.tar.bz2
YetAnotherConfigLib-04fe933f4c24817100f3101f088accf55a621f8a.zip
Extremely fragile and broken multiversion build with stonecutter
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/gui/tab')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java116
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java115
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java14
3 files changed, 0 insertions, 245 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
deleted file mode 100644
index df28d27..0000000
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package dev.isxander.yacl3.gui.tab;
-
-import com.google.common.collect.ImmutableList;
-import dev.isxander.yacl3.gui.ElementListWidgetExt;
-import net.minecraft.client.gui.ComponentPath;
-import net.minecraft.client.gui.GuiGraphics;
-import net.minecraft.client.gui.components.AbstractWidget;
-import net.minecraft.client.gui.components.events.ContainerEventHandler;
-import net.minecraft.client.gui.components.events.GuiEventListener;
-import net.minecraft.client.gui.narration.NarrationElementOutput;
-import net.minecraft.client.gui.navigation.FocusNavigationEvent;
-import net.minecraft.client.gui.navigation.ScreenRectangle;
-import net.minecraft.network.chat.CommonComponents;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.List;
-import java.util.function.Supplier;
-
-public class ListHolderWidget<T extends ElementListWidgetExt<?>> extends AbstractWidget implements ContainerEventHandler {
- private final Supplier<ScreenRectangle> dimensions;
- private final T list;
-
- public ListHolderWidget(Supplier<ScreenRectangle> dimensions, T list) {
- super(0, 0, 100, 0, CommonComponents.EMPTY);
- this.dimensions = dimensions;
- this.list = list;
- }
-
- @Override
- public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float deltaTick) {
- ScreenRectangle dimensions = this.dimensions.get();
- this.setX(dimensions.left());
- this.setY(dimensions.top());
- this.width = dimensions.width();
- this.height = dimensions.height();
- this.list.updateDimensions(dimensions);
- this.list.render(guiGraphics, mouseX, mouseY, deltaTick);
- }
-
- @Override
- protected void updateWidgetNarration(NarrationElementOutput output) {
- this.list.updateNarration(output);
- }
-
- @Override
- public List<? extends GuiEventListener> children() {
- return ImmutableList.of(this.list);
- }
-
- public T getList() {
- return list;
- }
-
- @Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- return this.list.mouseClicked(mouseX, mouseY, button);
- }
-
- @Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- return this.list.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
- }
-
- @Override
- public boolean mouseReleased(double mouseX, double mouseY, int button) {
- return this.list.mouseReleased(mouseX, mouseY, button);
- }
-
- @Override
- public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
- return this.list.mouseScrolled(mouseX, mouseY, horizontal, vertical);
- }
-
- @Override
- public boolean keyPressed(int i, int j, int k) {
- return this.list.keyPressed(i, j, k);
- }
-
- @Override
- public boolean charTyped(char c, int i) {
- return this.list.charTyped(c, i);
- }
-
- @Override
- public boolean isDragging() {
- return this.list.isDragging();
- }
-
- @Override
- public void setDragging(boolean dragging) {
- this.list.setDragging(dragging);
- }
-
- @Nullable
- @Override
- public GuiEventListener getFocused() {
- return this.list.getFocused();
- }
-
- @Override
- public void setFocused(@Nullable GuiEventListener listener) {
- this.list.setFocused(listener);
- }
-
- @Nullable
- @Override
- public ComponentPath nextFocusPath(FocusNavigationEvent event) {
- return this.list.nextFocusPath(event);
- }
-
- @Nullable
- @Override
- public ComponentPath getCurrentFocusPath() {
- return this.list.getCurrentFocusPath();
- }
-}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
deleted file mode 100644
index 66ba6a3..0000000
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package dev.isxander.yacl3.gui.tab;
-
-import com.google.common.collect.ImmutableList;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.Font;
-import net.minecraft.client.gui.GuiGraphics;
-import net.minecraft.client.gui.components.AbstractWidget;
-import net.minecraft.client.gui.components.TabButton;
-import net.minecraft.client.gui.components.events.GuiEventListener;
-import net.minecraft.client.gui.components.tabs.Tab;
-import net.minecraft.client.gui.components.tabs.TabManager;
-import net.minecraft.client.gui.components.tabs.TabNavigationBar;
-import net.minecraft.util.Mth;
-import org.jetbrains.annotations.Nullable;
-
-public class ScrollableNavigationBar extends TabNavigationBar {
- private static final int NAVBAR_MARGIN = 28;
-
- private static final Font font = Minecraft.getInstance().font;
-
- private int scrollOffset;
- private int maxScrollOffset;
-
- public ScrollableNavigationBar(int width, TabManager tabManager, Iterable<? extends Tab> tabs) {
- super(width, tabManager, ImmutableList.copyOf(tabs));
-
- // add tab tooltips to the tab buttons
- for (TabButton tabButton : this.tabButtons) {
- if (tabButton.tab() instanceof TabExt tab) {
- tabButton.setTooltip(tab.getTooltip());
- }
- }
- }
-
- @Override
- public void arrangeElements() {
- int noScrollWidth = this.width - NAVBAR_MARGIN*2;
-
- int allTabsWidth = 0;
- // first pass: set the width of each tab button
- for (TabButton tabButton : this.tabButtons) {
- int buttonWidth = font.width(tabButton.getMessage()) + 20;
- allTabsWidth += buttonWidth;
- tabButton.setWidth(buttonWidth);
- }
-
- if (allTabsWidth < noScrollWidth) {
- int equalWidth = noScrollWidth / this.tabButtons.size();
- var smallTabs = this.tabButtons.stream().filter(btn -> btn.getWidth() < equalWidth).toList();
- var bigTabs = this.tabButtons.stream().filter(btn -> btn.getWidth() >= equalWidth).toList();
- int leftoverWidth = noScrollWidth - bigTabs.stream().mapToInt(AbstractWidget::getWidth).sum();
- int equalWidthForSmallTabs = leftoverWidth / smallTabs.size();
- for (TabButton tabButton : smallTabs) {
- tabButton.setWidth(equalWidthForSmallTabs);
- }
-
- allTabsWidth = noScrollWidth;
- }
-
- this.layout.arrangeElements();
- this.layout.setY(0);
- this.scrollOffset = 0;
-
- this.layout.setX(Math.max((this.width - allTabsWidth) / 2, NAVBAR_MARGIN));
- this.maxScrollOffset = Math.max(0, allTabsWidth - noScrollWidth);
- }
-
- @Override
- public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
- graphics.pose().pushPose();
- // render option list BELOW the navbar without need to scissor
- graphics.pose().translate(0, 0, 10);
-
- super.render(graphics, mouseX, mouseY, delta);
-
- graphics.pose().popPose();
- }
-
- @Override
- public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
- this.setScrollOffset(this.scrollOffset - (int)(vertical*15));
- return true;
- }
-
- @Override
- public boolean isMouseOver(double mouseX, double mouseY) {
- return mouseY <= 24;
- }
-
- public void setScrollOffset(int scrollOffset) {
- layout.setX(layout.getX() + this.scrollOffset);
- this.scrollOffset = Mth.clamp(scrollOffset, 0, maxScrollOffset);
- layout.setX(layout.getX() - this.scrollOffset);
- }
-
- public int getScrollOffset() {
- return scrollOffset;
- }
-
- @Override
- public void setFocused(@Nullable GuiEventListener child) {
- super.setFocused(child);
- if (child instanceof TabButton tabButton) {
- this.ensureVisible(tabButton);
- }
- }
-
- protected void ensureVisible(TabButton tabButton) {
- if (tabButton.getX() < NAVBAR_MARGIN) {
- this.setScrollOffset(this.scrollOffset - (NAVBAR_MARGIN - tabButton.getX()));
- } else if (tabButton.getX() + tabButton.getWidth() > this.width - NAVBAR_MARGIN) {
- this.setScrollOffset(this.scrollOffset + (tabButton.getX() + tabButton.getWidth() - (this.width - NAVBAR_MARGIN)));
- }
- }
-}
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
deleted file mode 100644
index 1b4b3e5..0000000
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package dev.isxander.yacl3.gui.tab;
-
-import net.minecraft.client.gui.GuiGraphics;
-import net.minecraft.client.gui.components.Tooltip;
-import net.minecraft.client.gui.components.tabs.Tab;
-import org.jetbrains.annotations.Nullable;
-
-public interface TabExt extends Tab {
- @Nullable Tooltip getTooltip();
-
- default void tick() {}
-
- default void renderBackground(GuiGraphics graphics) {}
-}