Skip to content

Commit

Permalink
Make overriding colors in text-boxes work
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Feb 4, 2025
1 parent d0e10bc commit c79375f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TextFieldBackground<T> {
public static final TextFieldBackground<GuiTexture> REGULAR_BACKGROUND = new TextFieldBackground<>(
GuiTexture.of("textures/gui/sprites/widget/text_field/normal.png", Size.of(200, 20)),
GuiTexture.of("textures/gui/sprites/widget/text_field/highlighted.png", Size.of(200, 20)),
new Colors(Color.GRAY, Color.BLUE, Color.WHITE, false));
new Colors(Color.BLUE, Color.WHITE, false));

private final T normal;
private final T highlighted;
Expand Down Expand Up @@ -40,29 +40,23 @@ public Colors colors() {
}

public static class Colors {
private final Color untyped;
private final Color normal;
private final Color highlighted;
private final Color hint;
private final Color typed;

private final boolean shadowed;

public Colors(Color untyped, Color normal, Color highlighted, boolean shadowed) {
this.untyped = untyped;
this.normal = normal;
this.highlighted = highlighted;
public Colors(Color hint, Color typed, boolean shadowed) {
this.hint = hint;
this.typed = typed;
this.shadowed = shadowed;
}

public Color untyped() {
return this.untyped;
public Color hint() {
return this.hint;
}

public Color normal() {
return this.normal;
}

public Color highlighted() {
return this.highlighted;
public Color typed() {
return this.typed;
}

public boolean shadowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@

public class TextFieldImpl extends EditBox implements TextField {
private final WidgetSprites background;
private final TextFieldBackground.Colors colors;
private final Style style;
private final Size size;

public TextFieldImpl(Font font, TextFieldBackground<GuiTexture> background, Component defaultText, int maxLength) {
super(font, background.normal().size().width(), background.normal().size().height(),
UICompatImpl.internalToMinecraftType(defaultText));
this.setHint(UICompatImpl.internalToMinecraftType(defaultText));
this.setFormatter((string, color) -> FormattedCharSequence.forward(string, Style.EMPTY.withColor(color)));

TextFieldBackground<ResourceLocation> background0 = background
.map(texture -> UICompatImpl.internalToMinecraftType(texture.path()));
this.background = new WidgetSprites(background0.normal(), background0.highlighted());

this.background = new WidgetSprites(background0.normal(), background0.highlighted());
this.size = background.normal().size();
this.style = Style.EMPTY.withColor(background.colors().typed().hex());

// Hint text
this.setTextColor(background.colors().hint().hex());
// Player text
this.setFormatter((string, color) -> FormattedCharSequence.forward(string, this.style));

this.setMaxLength(maxLength);
this.colors = background0.colors();
}

@Override
Expand All @@ -54,8 +58,4 @@ public void setPos(int x, int y) {
public WidgetSprites background() {
return this.background;
}

public TextFieldBackground.Colors colors() {
return this.colors;
}
}

0 comments on commit c79375f

Please sign in to comment.