Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8648c4a
added a 'padding' value to avoid 'magic numbers' (see comments)
shvaich Jul 18, 2026
6ab5d07
added a getLeftPadding method to give inheritors more control (mostly…
shvaich Jul 18, 2026
c2b4824
added an abstract method that each inheritor must implemenet, at this…
shvaich Jul 18, 2026
ab60fab
added a helper method to get the width of a 'main button'
shvaich Jul 18, 2026
386763e
added a helper method to get a 'main button'
shvaich Jul 18, 2026
226cd81
added a shared value for inheritors who use a 'main button'
shvaich Jul 18, 2026
72abc29
added a shared helper method to get 'boolean text' (enabled/disabled)
shvaich Jul 18, 2026
5f19c98
added a value for inheritors to use to position their content (button…
shvaich Jul 18, 2026
bc848ae
fixed typo
shvaich Jul 18, 2026
59aec13
updated to use the new methods and values, implement 'getRightSideCon…
shvaich Jul 19, 2026
0d7eac3
fill in track before slider button for better ui
shvaich Jul 19, 2026
354bb1d
shortened the vertical distance between property name and commet start
shvaich Jul 19, 2026
712b17c
fixed a mistake where i added 1px to plusButtonX
shvaich Jul 19, 2026
2ce9609
Merge branch 'master' into config_button_ui_edits
shvaich Jul 19, 2026
994569e
Merge branch 'master' into config_button_ui_edits
shvaich Jul 24, 2026
3188b94
it is better to use 'mousePressed' in clicks event
shvaich Jul 26, 2026
08abb7d
use generics for cleaner code
shvaich Jul 27, 2026
dd1f5b0
send default color to button
shvaich Jul 27, 2026
8d05384
added margins
shvaich Jul 27, 2026
f539076
added hovering text lines getter to allow ui elements to render hover…
shvaich Jul 27, 2026
5c3ba16
modified method to accept a boolean to fix bug where elements appear …
shvaich Jul 27, 2026
ad3d765
modified to use added functionalities and slightly changed the gap be…
shvaich Jul 27, 2026
5d2536c
updated to use declared margin values
shvaich Jul 27, 2026
0c3dcaa
modified to fix bug where buttons appear hovered when they aren't mea…
shvaich Jul 27, 2026
adc9bdf
added to variables to help rendering. these variables are important a…
shvaich Jul 27, 2026
3184713
modified to support new functionalities. this version in my opinion m…
shvaich Jul 27, 2026
06f564b
added more functionality to work cleanly with the ConfigGuiScreen and…
shvaich Jul 27, 2026
4b2e8a9
added this method to cleanly close the currently open overlay
shvaich Jul 27, 2026
9ffbd9a
added this method for use instead of separate methods to get the heig…
shvaich Jul 27, 2026
9bbad98
modified handleMouseInput to support currentlyOpenOverlay
shvaich Jul 27, 2026
304725f
modified keyTyped to also handle currentlyOpenOverlay's keyTyped
shvaich Jul 27, 2026
609ab2f
modified to handle currentlyOpenOverlay mouse released
shvaich Jul 27, 2026
2cfe064
fix invalid hovering bug, correctly render open overlay and added hov…
shvaich Jul 27, 2026
c95ec91
modified mouseClicked to correctly and cleanly handle the currentlyOp…
shvaich Jul 27, 2026
978f285
modified forEachVisible to use elements margins
shvaich Jul 27, 2026
5fd26f5
override keyTyped to close this overlay when escape is pressed, other…
shvaich Jul 27, 2026
e56b761
updated to to use new functionality
shvaich Jul 27, 2026
33dee08
comment for explanation
shvaich Aug 7, 2026
0c3ccc0
changed to also add padding when needed. (this change was to fix scro…
shvaich Aug 7, 2026
d596886
made private since it is no longer used outside of this class (as it …
shvaich Aug 7, 2026
79c79f5
always close an overlay before config box wheel scrolling. (this wont…
shvaich Aug 7, 2026
8f66539
categoryContentHeight now already includes screen padding
shvaich Aug 7, 2026
65aaff1
fixed scrollbar code
shvaich Aug 7, 2026
af39acf
cleaned up 'getContentHeight' method
shvaich Aug 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ private void loadConfigValueToField() throws IllegalAccessException {
break;
}
case ENUM_COLOR: {
EnumChatFormatting value = (EnumChatFormatting) this.getEnumValue(this.getProp().getString());
EnumChatFormatting value = this.getEnumValue(this.getProp().getString());
if (value == null || !value.isColor()) {
value = (EnumChatFormatting) this.getEnumValue(this.getProp().getDefault());
value = this.getEnumValue(this.getProp().getDefault());
}
field.set(null, value);
break;
Expand Down Expand Up @@ -280,7 +280,8 @@ public ConfigUIElement getConfigButton(ConfigGuiScreen configGuiScreen, Renderer
}
}
case ENUM_COLOR: {
return new ColorEnumGuiButton(configGuiScreen, field, event, annotation);
final EnumChatFormatting defaultColor = getEnumValue(this.getProp().getDefault());
return new ColorEnumGuiButton(configGuiScreen, field, event, annotation, defaultColor);
}
case ENUM: {
return new EnumGuiButton(field, event, annotation);
Expand All @@ -294,13 +295,13 @@ public ConfigProperty getAnnotation() {
}

@Nullable
private Enum<?> getEnumValue(@NotNull String valueName) {
private <T extends Enum<T>> T getEnumValue(@NotNull String valueName) {
if (!Enum.class.isAssignableFrom(field.getType())) {
throw new IllegalArgumentException();
}
try {
//noinspection rawtypes,unchecked
return Enum.valueOf((Class<? extends Enum>) field.getType(), valueName);
//noinspection unchecked
return Enum.valueOf((Class<T>) field.getType(), valueName);
} catch (IllegalArgumentException ignored) {}
return null;
}
Expand Down
187 changes: 116 additions & 71 deletions src/configlib/java/fr/alexdoru/configlib/lib/gui/ConfigGuiScreen.java

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions src/configlib/java/fr/alexdoru/configlib/lib/gui/Scrollbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,28 @@ public void updateScrollPos(int contentHeight, int boxHeight) {
}

public void drawScrollbar(ColorPalette colorPalette, Box box, int mouseY, int contentHeight) {
final int categoryBoxHeight = box.getHeight() - 2;
final boolean renderCategoryScrollbar = contentHeight > categoryBoxHeight;
if (renderCategoryScrollbar) {
final int scrollBarSize = categoryBoxHeight * categoryBoxHeight / contentHeight;
final int minScrollBarY = box.TOP + 1 + 1;
final int maxScrollBarY = box.BOTTOM - 1 - scrollBarSize - 1;
if (dragging) {
final int relativeMouseY = mouseY - minScrollBarY - grabbedAtY;
if (maxScrollBarY != minScrollBarY) {
final int newScroll = relativeMouseY * (contentHeight - box.getHeight()) / (maxScrollBarY - minScrollBarY);
this.scroll(this.scroll - newScroll, contentHeight, box.getHeight());
}
final int REAL_BOX_HEIGHT = box.getHeight();
if (contentHeight <= REAL_BOX_HEIGHT) return;
final int VERTICAL_MARGIN = 2;
final int AVAILABLE_BOX_HEIGHT = REAL_BOX_HEIGHT - VERTICAL_MARGIN * 2;
final int thumbHeight = AVAILABLE_BOX_HEIGHT * REAL_BOX_HEIGHT / contentHeight;
final int minY = box.TOP + VERTICAL_MARGIN;
final int maxY = box.BOTTOM - thumbHeight - VERTICAL_MARGIN;
final int scrollRange = contentHeight - REAL_BOX_HEIGHT;
final int trackRange = maxY - minY;
if (dragging) {
final int relativeMouseY = mouseY - minY - grabbedAtY;
if (trackRange != 0) {
final int newScroll = relativeMouseY * scrollRange / trackRange;
this.scroll(this.scroll - newScroll, contentHeight, REAL_BOX_HEIGHT);
}
this.thumb.LEFT = box.RIGHT - 5;
this.thumb.TOP = ((maxScrollBarY - minScrollBarY) * this.scroll) / (contentHeight - categoryBoxHeight) + minScrollBarY;
this.thumb.RIGHT = this.thumb.LEFT + 3;
this.thumb.BOTTOM = this.thumb.TOP + scrollBarSize;
GuiUtil.drawVerticalLine(box.RIGHT - 4, box.TOP + 4, box.BOTTOM - 4, colorPalette.SCROLLBAR_TRACK);
GuiUtil.drawRect(this.thumb, colorPalette.SCROLLBAR_THUMB);
}
this.thumb.LEFT = box.RIGHT - 5;
this.thumb.TOP = minY + (int) ((float)this.scroll / scrollRange * trackRange);
this.thumb.RIGHT = this.thumb.LEFT + 3;
this.thumb.BOTTOM = this.thumb.TOP + thumbHeight;
GuiUtil.drawVerticalLine(box.RIGHT - 4, box.TOP + 4, box.BOTTOM - 4, colorPalette.SCROLLBAR_TRACK);
GuiUtil.drawRect(this.thumb, colorPalette.SCROLLBAR_THUMB);
}

public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) {
Expand All @@ -74,8 +76,8 @@ public void mouseReleased(MouseButton mouseButton) {

private void scroll(int amount, int contentHeight, int boxHeight) {
this.scroll = this.scroll - amount;
if (this.scroll > contentHeight + 2 * ConfigGuiScreen.PADDING - boxHeight) {
this.scroll = contentHeight + 2 * ConfigGuiScreen.PADDING - boxHeight;
if (this.scroll > contentHeight - boxHeight) {
this.scroll = contentHeight - boxHeight;
this.amountToScroll = 0;
}
if (this.scroll <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import fr.alexdoru.configlib.api.ColorPalette;
import fr.alexdoru.configlib.api.ConfigProperty;
import fr.alexdoru.configlib.lib.gui.MouseButton;
import net.minecraft.util.EnumChatFormatting;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand All @@ -16,22 +15,24 @@ public class BooleanGuiButton extends ConfigGuiButton {
public BooleanGuiButton(Field field, Method event, ConfigProperty annotation) throws IllegalAccessException {
super(field, event, annotation);
this.toggled = (boolean) this.field.get(null);
this.button = new ClickGuiButton(0, 0, 0, mc.fontRendererObj.getStringWidth(" Disabled "), 20, getButtonText());
this.button = getMainButton(getBooleanText(toggled));
this.rightSideContentWidth = button.width + BUTTON_RIGHT_MARGIN;
this.rightSideContentHeight = button.height;
}

@Override
public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) {
super.draw(colorPalette, drawX, drawY, mouseX, mouseY);
button.xPosition = drawX + boxWidth - button.width - 20;
button.yPosition = drawY + (this.hasComment() ? 8 + mc.fontRendererObj.FONT_HEIGHT / 2 : (getHeight() - button.height) / 2);
button.drawButton(colorPalette, mc, mouseX, mouseY);
public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) {
super.draw(colorPalette, drawX, drawY, mouseX, mouseY, canMouseBeVisuallyOverElement);
button.xPosition = contentLeft;
button.yPosition = drawY + getCenterYOffset(button.height);
button.drawButton(colorPalette, mc, mouseX, mouseY, canMouseBeVisuallyOverElement);
}

@Override
public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) throws IllegalAccessException {
if (mouseButton.isLeft() && button.mousePressed(mc, mouseX, mouseY)) {
flipBooleanConfig();
button.displayString = getButtonText();
button.displayString = getBooleanText(toggled);
button.playPressSound(mc.getSoundHandler());
return true;
}
Expand All @@ -43,9 +44,4 @@ private void flipBooleanConfig() throws IllegalAccessException {
toggled = (boolean) this.field.get(null);
invokeConfigEvent();
}

private String getButtonText() {
return toggled ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) {
}

private boolean isMouseHovering(int mouseX, int mouseY) {
final int extraY = ConfigGuiScreen.ELEMENT_GAP / 2;
return mouseX >= posX && mouseY >= posY - extraY && mouseX < posX + getWidth() && mouseY < posY + extraY + getHeight();
return mouseX >= posX && mouseY >= posY - getTopMargin() && mouseX < posX + getWidth() && mouseY < posY + getHeight() + getBottomMargin();
}

public int getWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

public class CategoryHeader implements ConfigUIElement {

private static final int COMMENT_TOP_MARGIN = 4;

private final Minecraft mc = Minecraft.getMinecraft();
private final String name;
private final String displayname;
Expand Down Expand Up @@ -44,15 +46,15 @@ public void setBoxWidth(int boxWidth) {
}

@Override
public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY) {
public void draw(ColorPalette colorPalette, int drawX, int drawY, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) {
final int textX = drawX + (boxWidth - mc.fontRendererObj.getStringWidth(displayname) * 2) / 2;
GlStateManager.translate(textX, drawY, 0);
GlStateManager.scale(2, 2, 2);
mc.fontRendererObj.drawStringWithShadow(displayname, 0, 0, colorPalette.CATEGORY_HEADER_TITLE_TEXT);
GlStateManager.scale(0.5, 0.5, 0.5);
GlStateManager.translate(-textX, -drawY, 0);
if (hasComment) {
int commentY = drawY + mc.fontRendererObj.FONT_HEIGHT * 2 + 8;
int commentY = drawY + mc.fontRendererObj.FONT_HEIGHT * 2 + COMMENT_TOP_MARGIN;
for (final String line : commentToRender) {
final int lineX = drawX + (boxWidth - mc.fontRendererObj.getStringWidth(line)) / 2;
mc.fontRendererObj.drawStringWithShadow(line, lineX, commentY, colorPalette.CATEGORY_HEADER_COMMENT_TEXT);
Expand All @@ -69,9 +71,9 @@ public boolean mouseClicked(int mouseX, int mouseY, MouseButton mouseButton) {
@Override
public int getHeight() {
if (hasComment) {
return mc.fontRendererObj.FONT_HEIGHT * 2 + 8 + mc.fontRendererObj.FONT_HEIGHT * commentToRender.size() + 8;
return mc.fontRendererObj.FONT_HEIGHT * 2 + COMMENT_TOP_MARGIN + mc.fontRendererObj.FONT_HEIGHT * commentToRender.size();
}
return mc.fontRendererObj.FONT_HEIGHT * 2 + 8;
return mc.fontRendererObj.FONT_HEIGHT * 2;
}

@Override
Expand All @@ -89,4 +91,8 @@ public boolean matchSearch(String search) {
return false;
}

@Override
public int getBottomMargin() {
return 8;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public void setTexture(ResourceLocation texture) {
}

public void drawButton(ColorPalette colorPalette, Minecraft mc, int mouseX, int mouseY) {
this.hovered = this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
drawButton(colorPalette, mc, mouseX, mouseY, true);
}

public void drawButton(ColorPalette colorPalette, Minecraft mc, int mouseX, int mouseY, boolean canMouseBeVisuallyOverElement) {
this.hovered = canMouseBeVisuallyOverElement && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
if (this.visible) {
this.mouseDragged(mc, mouseX, mouseY);
GuiUtil.drawBoxWithOutline(
Expand Down
Loading