Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
fix text boxes eating tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Oct 11, 2023
1 parent c74530c commit 35cc3b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.wispforest.gadget.client.field;

import io.wispforest.gadget.client.gui.GuiUtil;
import io.wispforest.gadget.client.gui.TabTextBoxComponent;
import io.wispforest.gadget.desc.PrimitiveFieldObject;
import io.wispforest.gadget.desc.edit.PrimitiveEditData;
import io.wispforest.gadget.path.ObjectPath;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.component.TextBoxComponent;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.util.UISounds;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.lwjgl.glfw.GLFW;
Expand All @@ -21,7 +22,7 @@ public class PrimitiveFieldWidget extends FlowLayout {

private final LabelComponent contentsLabel;
private final LabelComponent editLabel;
private final TextFieldWidget editField;
private final TextBoxComponent editField;

protected PrimitiveFieldWidget(FieldDataIsland island, ObjectPath fieldPath, PrimitiveFieldObject pfo) {
super(Sizing.content(), Sizing.content(), Algorithm.HORIZONTAL);
Expand All @@ -33,7 +34,7 @@ protected PrimitiveFieldWidget(FieldDataIsland island, ObjectPath fieldPath, Pri
.formatted(Formatting.GRAY)
);
this.editLabel = Components.label(Text.literal(" ✎ "));
this.editField = Components.textBox(Sizing.fixed(100));
this.editField = new TabTextBoxComponent(Sizing.fixed(100));
this.editData = pfo.editData().orElseThrow();

GuiUtil.semiButton(this.editLabel, this::startEditing);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.wispforest.gadget.client.gui;

import io.wispforest.owo.ui.component.TextBoxComponent;
import io.wispforest.owo.ui.core.Sizing;
import org.lwjgl.glfw.GLFW;

public class TabTextBoxComponent extends TextBoxComponent {
public TabTextBoxComponent(Sizing horizontalSizing) {
super(horizontalSizing);
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_TAB) {
// Pass the event to the root component.
root().onKeyPress(keyCode, scanCode, modifiers);

return true;
}

return super.keyPressed(keyCode, scanCode, modifiers);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.wispforest.gadget.client.nbt;

import io.wispforest.gadget.client.gui.GuiUtil;
import io.wispforest.gadget.client.gui.TabTextBoxComponent;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.component.TextBoxComponent;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.Insets;
import io.wispforest.owo.ui.core.ParentComponent;
import io.wispforest.owo.ui.core.Sizing;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.nbt.*;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
Expand All @@ -20,8 +21,8 @@ public class KeyAdderWidget extends FlowLayout {
private final NbtType<?> type;
private final Predicate<String> nameVerifier;

private final TextFieldWidget nameField;
private final TextFieldWidget valueField;
private final TextBoxComponent nameField;
private final TextBoxComponent valueField;
private boolean wasMounted = false;

public KeyAdderWidget(NbtDataIsland island, NbtPath parentPath, NbtType<?> type, Predicate<String> nameVerifier) {
Expand All @@ -34,19 +35,19 @@ public KeyAdderWidget(NbtDataIsland island, NbtPath parentPath, NbtType<?> type,

child(Components.label(island.typeText(type, "")
.append(" ")));
child((this.nameField = Components.textBox(Sizing.fixed(75)))
child((this.nameField = new TabTextBoxComponent(Sizing.fixed(75)))
.verticalSizing(Sizing.fixed(8)));

if (typeNeedsValue(type)) {
child(Components.label(Text.of(" = ")));

child((this.valueField = Components.textBox(Sizing.fixed(75)))
child((this.valueField = new TabTextBoxComponent(Sizing.fixed(75)))
.verticalSizing(Sizing.fixed(8)));
} else if (typeNeedsSize(type)) {
child(Components.label(Text.of("["))
.margins(Insets.horizontal(2)));

child((this.valueField = Components.textBox(Sizing.fixed(50)))
child((this.valueField = new TabTextBoxComponent(Sizing.fixed(50)))
.verticalSizing(Sizing.fixed(8)));

child(Components.label(Text.of("]"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.wispforest.gadget.client.nbt;

import io.wispforest.gadget.client.gui.GuiUtil;
import io.wispforest.gadget.client.gui.TabTextBoxComponent;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.component.TextBoxComponent;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.util.UISounds;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.nbt.NbtElement;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand All @@ -22,7 +23,7 @@ public class PrimitiveEditorWidget extends FlowLayout {

private final LabelComponent contentsLabel;
private final LabelComponent editLabel;
private final TextFieldWidget editField;
private final TextBoxComponent editField;

protected PrimitiveEditorWidget(NbtDataIsland island, NbtPath path, Object value, Function<String, NbtElement> parser) {
super(Sizing.content(), Sizing.content(), Algorithm.HORIZONTAL);
Expand All @@ -36,7 +37,7 @@ protected PrimitiveEditorWidget(NbtDataIsland island, NbtPath path, Object value
this.value = value;
this.parser = parser;
this.editLabel = Components.label(Text.literal(" ✎ "));
this.editField = Components.textBox(Sizing.fixed(100));
this.editField = new TabTextBoxComponent(Sizing.fixed(100));

GuiUtil.semiButton(this.editLabel, this::startEditing);
this.editField.focusLost().subscribe(this::editFieldFocusLost);
Expand Down

0 comments on commit 35cc3b0

Please sign in to comment.