Upload files to "src/openonyx/ui/internal"
This commit is contained in:
1 parent
1385f8abb3
commit
3de4562ef6
5 files changed
+367
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
package openonyx.ui.internal;
|
||||||
|
|
||||||
|
record TextEditorData(String text, int caret, int anchor) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package openonyx.ui.internal;
|
||||||
|
|
||||||
|
public interface TextEditorListener {
|
||||||
|
float L(String string);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package openonyx.ui.internal;
|
||||||
|
|
||||||
|
enum TextEditorMode {
|
||||||
|
INSERT,
|
||||||
|
DELETE,
|
||||||
|
NONE;
|
||||||
|
|
||||||
|
private static TextEditorMode[] L() {
|
||||||
|
TextEditorMode[] textEditorModes = new TextEditorMode[3];
|
||||||
|
boolean bl = true;
|
||||||
|
textEditorModes[0] = NONE;
|
||||||
|
textEditorModes[1] = INSERT;
|
||||||
|
textEditorModes[2] = DELETE;
|
||||||
|
return textEditorModes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
package openonyx.ui.internal;
|
||||||
|
|
||||||
|
import openonyx.input.CharInput;
|
||||||
|
import openonyx.input.KeyInput;
|
||||||
|
import openonyx.render.Render2D;
|
||||||
|
import openonyx.render.group_d.Animation;
|
||||||
|
import openonyx.render.group_d.Easings;
|
||||||
|
import openonyx.render.group_e.FontStyle;
|
||||||
|
import openonyx.theme.ThemeManager;
|
||||||
|
import openonyx.ui.RenderContext;
|
||||||
|
import openonyx.ui.UiComponent;
|
||||||
|
|
||||||
|
public abstract class TextInput extends UiComponent {
|
||||||
|
private Render2D render2D;
|
||||||
|
private boolean c;
|
||||||
|
protected final Animation animation;
|
||||||
|
protected final TextEditor textEditor = new TextEditor();
|
||||||
|
private float g;
|
||||||
|
private long M;
|
||||||
|
private int L;
|
||||||
|
private static final float j = 3.0F;
|
||||||
|
private float m;
|
||||||
|
private static final long h = 320L;
|
||||||
|
private static final float l = 0.32F;
|
||||||
|
private static final float I = 1.2F;
|
||||||
|
protected boolean f;
|
||||||
|
private static TextInput INSTANCE;
|
||||||
|
|
||||||
|
public String L() {
|
||||||
|
return this.textEditor.L();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int L(float f) {
|
||||||
|
return this.textEditor.L(fx - this.l() + this.m, this.L());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean charTyped(CharInput charInput) {
|
||||||
|
return this.f && this.textEditor.L(charInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract float l();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(RenderContext renderContext) {
|
||||||
|
super.update(renderContext);
|
||||||
|
this.render2D = renderContext.render2D;
|
||||||
|
this.animation.update(renderContext.i);
|
||||||
|
this.textEditor.L(renderContext.i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean h() {
|
||||||
|
return INSTANCE != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(float f, float g, int i) {
|
||||||
|
if (i != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (!this.contains(fx, gx)) {
|
||||||
|
this.D(false);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.L(fx, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void D(boolean bl) {
|
||||||
|
if (this.f != bl) {
|
||||||
|
this.f = bl;
|
||||||
|
this.c = false;
|
||||||
|
TextInput textInput1;
|
||||||
|
if (bl) {
|
||||||
|
if (INSTANCE != null && INSTANCE != this) {
|
||||||
|
INSTANCE.D(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
textInput1 = INSTANCE = this;
|
||||||
|
} else {
|
||||||
|
if (INSTANCE == this) {
|
||||||
|
INSTANCE = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
textInput1 = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
textInput1.textEditor.D();
|
||||||
|
if (!bl) {
|
||||||
|
this.textEditor.L();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.animation.animateTo(bl ? 1.0F : 0.0F, 200.0F, Easings.EASING6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean I() {
|
||||||
|
return this.textEditor.i();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract float h();
|
||||||
|
|
||||||
|
public TextInput() {
|
||||||
|
this.animation = new Animation(0.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void L(String string) {
|
||||||
|
this.textEditor.L(string);
|
||||||
|
this.m = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseDragged(float f, float g, int i, float h, float j) {
|
||||||
|
if (this.c && i == 0) {
|
||||||
|
this.textEditor.L(this.L(fx), true);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void D() {
|
||||||
|
if (INSTANCE != null) {
|
||||||
|
INSTANCE.D(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean L(float f, boolean bl) {
|
||||||
|
long lx = System.currentTimeMillis();
|
||||||
|
boolean bl1 = Math.abs(fx - this.g) <= 3.0F;
|
||||||
|
this.L = lx - this.M <= 320L && bl1 ? this.L + 1 : 0;
|
||||||
|
this.M = lx;
|
||||||
|
this.g = fx;
|
||||||
|
this.D(true);
|
||||||
|
if (this.L == 1) {
|
||||||
|
this.textEditor.L(this.L(fx));
|
||||||
|
return true;
|
||||||
|
} else if (this.L >= 2) {
|
||||||
|
this.textEditor.d();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.textEditor.L(this.L(fx), bl);
|
||||||
|
this.c = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean i() {
|
||||||
|
return this.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float I() {
|
||||||
|
return Math.max(0.0F, this.h() - this.l());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void d() {
|
||||||
|
this.textEditor.d();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract FontStyle L();
|
||||||
|
|
||||||
|
public void d(boolean bl) {
|
||||||
|
this.textEditor.L(bl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(KeyInput keyInput) {
|
||||||
|
return this.f && this.textEditor.L(keyInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TextEditorListener L() {
|
||||||
|
TextInput textInput1 = this;
|
||||||
|
Render2D render2Dx = textInput1.render2D;
|
||||||
|
FontStyle fontStyle = textInput1.L();
|
||||||
|
return render2Dx == null ? string -> 0.0F : string -> render2Dx.getTextWidth(fontStyle, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseReleased(float f, float g, int i) {
|
||||||
|
return this.c = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void L(RenderContext renderContext, float f, float g, int i) {
|
||||||
|
TextInput textInput1 = this;
|
||||||
|
Render2D render2Dx = renderContext.render2D;
|
||||||
|
TextEditorListener textEditorListener = textInput1.L();
|
||||||
|
String string = textInput1.textEditor.D();
|
||||||
|
float k = textInput1.I();
|
||||||
|
float hx;
|
||||||
|
if ((hx = textInput1.textEditor.L(textEditorListener)) - textInput1.m > k) {
|
||||||
|
textInput1.m = hx - k;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hx - textInput1.m < 0.0F) {
|
||||||
|
textInput1.m = hx;
|
||||||
|
}
|
||||||
|
|
||||||
|
textInput1.m = Math.clamp(textInput1.m, 0.0F, Math.max(0.0F, textEditorListener.L(string) - k));
|
||||||
|
float jx = textInput1.l() - textInput1.m;
|
||||||
|
render2Dx.pushScissor(textInput1.l(), textInput1.d, k, textInput1.i);
|
||||||
|
if (textInput1.textEditor.D()) {
|
||||||
|
float lx = jx + textInput1.textEditor.L(textInput1.textEditor.L(), textEditorListener);
|
||||||
|
float mx = jx + textInput1.textEditor.L(textInput1.textEditor.d(), textEditorListener);
|
||||||
|
render2Dx.roundedRect(lx, fx - gx / 2.0F, mx - lx, gx, 0.0F, ThemeManager.withAlpha(renderContext.palette().primary(), 0.32F));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.isEmpty()) {
|
||||||
|
render2Dx.drawTextVCentered(textInput1.L(), string, jx, fx, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textInput1.f && textInput1.textEditor.l()) {
|
||||||
|
render2Dx.roundedRect(jx + hx, fx - gx / 2.0F, 1.2F, gx, Float.MAX_VALUE, renderContext.palette().primary());
|
||||||
|
}
|
||||||
|
|
||||||
|
render2Dx.popScissor();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package openonyx.ui.internal;
|
||||||
|
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import openonyx.render.Render2D;
|
||||||
|
import openonyx.render.group_d.Animation;
|
||||||
|
import openonyx.render.group_d.ColorAnimation;
|
||||||
|
import openonyx.render.group_d.Easings;
|
||||||
|
import openonyx.theme.ThemeManager;
|
||||||
|
import openonyx.ui.RenderContext;
|
||||||
|
import openonyx.ui.UiComponent;
|
||||||
|
|
||||||
|
public class ToggleSwitch extends UiComponent {
|
||||||
|
private static final float k = 10.0F;
|
||||||
|
private final ColorAnimation colorAnimation;
|
||||||
|
public static final float M = 22.0F;
|
||||||
|
private final ColorAnimation colorAnimation2;
|
||||||
|
private final Animation animation;
|
||||||
|
public static final float m = 38.0F;
|
||||||
|
private final Animation animation2 = new Animation(0.0F);
|
||||||
|
private static final float l = 6.0F;
|
||||||
|
private static final float I = 8.5F;
|
||||||
|
private boolean d;
|
||||||
|
private final Consumer<Boolean> booleanConsumer;
|
||||||
|
private boolean f;
|
||||||
|
private final BooleanSupplier booleanSupplier;
|
||||||
|
|
||||||
|
public ToggleSwitch(BooleanSupplier booleanSupplier, Consumer<Boolean> consumer) {
|
||||||
|
this.animation = new Animation(6.0F);
|
||||||
|
this.colorAnimation = new ColorAnimation(0);
|
||||||
|
this.colorAnimation2 = new ColorAnimation(0);
|
||||||
|
this.booleanSupplier = booleanSupplierx;
|
||||||
|
this.booleanConsumer = consumer;
|
||||||
|
this.e = 38.0F;
|
||||||
|
this.i = 22.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(RenderContext renderContext) {
|
||||||
|
ToggleSwitch toggleSwitch1 = this;
|
||||||
|
Render2D render2D = renderContext.render2D;
|
||||||
|
Render2D render2D1 = renderContext.render2D;
|
||||||
|
float fx = toggleSwitch1.d + toggleSwitch1.i / 2.0F;
|
||||||
|
float h = toggleSwitch1.e - 22.0F;
|
||||||
|
float i = toggleSwitch1.f + 11.0F + h * toggleSwitch1.animation2.getValue();
|
||||||
|
float g = toggleSwitch1.animation.getValue();
|
||||||
|
render2D1.roundedRect(toggleSwitch1.f, toggleSwitch1.d, toggleSwitch1.e, toggleSwitch1.i, Float.MAX_VALUE, toggleSwitch1.colorAnimation.L());
|
||||||
|
if (toggleSwitch1.animation2.getValue() < 0.999F) {
|
||||||
|
render2D.roundedOutline(
|
||||||
|
toggleSwitch1.f,
|
||||||
|
toggleSwitch1.d,
|
||||||
|
toggleSwitch1.e,
|
||||||
|
toggleSwitch1.i,
|
||||||
|
Float.MAX_VALUE,
|
||||||
|
1.5F,
|
||||||
|
ThemeManager.withAlpha(renderContext.palette().outline(), 1.0F - toggleSwitch1.animation2.getValue())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toggleSwitch1.h) {
|
||||||
|
int j;
|
||||||
|
ToggleSwitch toggleSwitch2;
|
||||||
|
if (toggleSwitch1.booleanSupplier.getAsBoolean()) {
|
||||||
|
j = renderContext.palette().primary();
|
||||||
|
toggleSwitch2 = toggleSwitch1;
|
||||||
|
} else {
|
||||||
|
j = renderContext.palette().onSurface();
|
||||||
|
toggleSwitch2 = toggleSwitch1;
|
||||||
|
}
|
||||||
|
|
||||||
|
render2D.circle(i, fx, 14.0F, ThemeManager.withAlpha(j, toggleSwitch2.H ? 0.1F : 0.08F));
|
||||||
|
}
|
||||||
|
|
||||||
|
render2D.circle(i, fx, g, toggleSwitch1.colorAnimation2.L());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(float f, float g, int i) {
|
||||||
|
if (i == 0 && this.contains(fx, g)) {
|
||||||
|
this.H = true;
|
||||||
|
this.booleanConsumer.accept(!this.booleanSupplier.getAsBoolean());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseReleased(float f, float g, int i) {
|
||||||
|
return this.H = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(RenderContext renderContext) {
|
||||||
|
ToggleSwitch toggleSwitch1 = this;
|
||||||
|
toggleSwitch1.update(renderContext);
|
||||||
|
boolean bl;
|
||||||
|
int i = (bl = toggleSwitch1.booleanSupplier.getAsBoolean()) ? renderContext.palette().primary() : renderContext.palette().surfaceContainerHighest();
|
||||||
|
int j = bl ? renderContext.palette().onPrimary() : renderContext.palette().outline();
|
||||||
|
if (!toggleSwitch1.d) {
|
||||||
|
toggleSwitch1.d = true;
|
||||||
|
toggleSwitch1.f = bl;
|
||||||
|
toggleSwitch1.animation2.set(bl ? 1.0F : 0.0F);
|
||||||
|
toggleSwitch1.animation.set(bl ? 8.5F : 6.0F);
|
||||||
|
toggleSwitch1.colorAnimation.L(i);
|
||||||
|
toggleSwitch1.colorAnimation2.L(j);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bl != toggleSwitch1.f) {
|
||||||
|
toggleSwitch1.f = bl;
|
||||||
|
toggleSwitch1.animation2.animateTo(bl ? 1.0F : 0.0F, 300.0F, Easings.EASING2);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleSwitch1.colorAnimation.L(i, 300.0F, Easings.EASING6);
|
||||||
|
toggleSwitch1.colorAnimation2.L(j, 300.0F, Easings.EASING6);
|
||||||
|
float fx = toggleSwitch1.H ? 10.0F : (bl ? 8.5F : 6.0F);
|
||||||
|
if (toggleSwitch1.animation.getTarget() != fx) {
|
||||||
|
toggleSwitch1.animation.animateTo(fx, 150.0F, Easings.EASING6);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleSwitch1.animation2.update(renderContext.i);
|
||||||
|
toggleSwitch1.animation.update(renderContext.i);
|
||||||
|
toggleSwitch1.colorAnimation.L(renderContext.i);
|
||||||
|
toggleSwitch1.colorAnimation2.L(renderContext.i);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user