margins, ui fixes

This commit is contained in:
Sen 2025-03-20 01:14:54 +01:00
parent 3d1c68210c
commit 80cf16ada5
8 changed files with 46 additions and 34 deletions

View file

@ -33,7 +33,11 @@ public class Bar extends Fill {
Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label); Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label);
} }
protected int getMargin() { protected int getMarginX() {
return 0;
}
protected int getMarginY() {
return 0; return 0;
} }

View file

@ -19,7 +19,7 @@ public class Dropdown<T> extends Element {
sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString()); sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
} }
this.setText(sb.toString()); this.setText(sb.toString());
this.visible = this.r_dirty = false; this.visible = /* this.r_dirty = */ false;
} }
public void updateText() { public void updateText() {
@ -39,7 +39,7 @@ public class Dropdown<T> extends Element {
public void deselect() { public void deselect() {
this.visible = false; this.visible = false;
this.r_dirty = true; // this.r_dirty = true;
} }
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
@ -53,7 +53,7 @@ public class Dropdown<T> extends Element {
this.playSound(); this.playSound();
} }
this.visible = false; this.visible = false;
this.r_dirty = true; // this.r_dirty = true;
} }
public void drawHover() { public void drawHover() {
@ -113,7 +113,7 @@ public class Dropdown<T> extends Element {
else if(this.gui != null) { else if(this.gui != null) {
Handle drop = this.handle; Handle drop = this.handle;
drop.visible = true; drop.visible = true;
drop.r_dirty = true; // drop.r_dirty = true;
this.gui.selected = drop; this.gui.selected = drop;
this.playSound(); this.playSound();
} }

View file

@ -20,11 +20,6 @@ public abstract class Element {
protected Formatter format; protected Formatter format;
protected String text = ""; protected String text = "";
// String format_text;
// Object aux_data;
// String[] format_data;
// CVar cv_data;
protected int pos_x; protected int pos_x;
protected int pos_y; protected int pos_y;
protected int size_x; protected int size_x;
@ -32,14 +27,13 @@ public abstract class Element {
protected int text_x = 0; protected int text_x = 0;
protected int text_y = 0; protected int text_y = 0;
protected final int margin_x1 = this.getMargin(); protected final int margin_x1 = this.getMarginX();
protected final int margin_y1 = this.getMargin(); protected final int margin_y1 = this.getMarginY();
protected final int margin_x2 = this.getMargin(); protected final int margin_x2 = this.getMarginX();
protected final int margin_y2 = this.getMargin(); protected final int margin_y2 = this.getMarginY();
public boolean visible = true; public boolean visible = true;
public boolean enabled = true; public boolean enabled = true;
public boolean r_dirty = true;
public Element(int x, int y, int w, int h, Formatter formatter) { public Element(int x, int y, int w, int h, Formatter formatter) {
@ -63,7 +57,11 @@ public abstract class Element {
this.gui = gui; this.gui = gui;
} }
protected int getMargin() { protected int getMarginX() {
return 1;
}
protected int getMarginY() {
return 1; return 1;
} }

View file

@ -22,7 +22,11 @@ public class Label extends Fill {
Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label); Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label);
} }
protected int getMargin() { protected int getMarginX() {
return 0;
}
protected int getMarginY() {
return 0; return 0;
} }
} }

View file

@ -127,8 +127,8 @@ public class Slider extends Element {
public void reformat() { public void reformat() {
this.position = gui_slider_pixel(); this.position = gui_slider_pixel();
if(this.visible) // if(this.visible)
this.r_dirty = true; // this.r_dirty = true;
super.reformat(); super.reformat();
} }

View file

@ -97,6 +97,10 @@ public class Textbox extends Element {
return false; return false;
} }
protected int getMarginX() {
return 4;
}
public void setText(String str) { public void setText(String str) {
if(this.validator != null) if(this.validator != null)
str = this.validator.filter(str); str = this.validator.filter(str);
@ -115,7 +119,7 @@ public class Textbox extends Element {
this.text_y = ExtMath.clampi(this.text_y, -limit, 0); this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
if(this.sel_start >= 0) if(this.sel_start >= 0)
this.cursorY += (this.text_y - prev); this.cursorY += (this.text_y - prev);
this.r_dirty = true; // this.r_dirty = true;
} }
else if(scr_y != 0 || scr_x != 0) { else if(scr_y != 0 || scr_x != 0) {
int limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2)); int limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2));
@ -125,7 +129,7 @@ public class Textbox extends Element {
this.text_x = ExtMath.clampi(this.text_x, -limit, 0); this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
if(this.sel_start >= 0) if(this.sel_start >= 0)
this.cursorX += (this.text_x - prev); this.cursorX += (this.text_x - prev);
this.r_dirty = true; // this.r_dirty = true;
} }
} }
@ -134,7 +138,7 @@ public class Textbox extends Element {
if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) { if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) {
this.sel_start = this.sel_drag = 0; this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length(); this.sel_end = this.text.length();
this.r_dirty = true; // this.r_dirty = true;
} }
else { else {
gui_text_select(x, y, shift); gui_text_select(x, y, shift);
@ -168,7 +172,7 @@ public class Textbox extends Element {
if(ctrl && key == Keysym.A) { if(ctrl && key == Keysym.A) {
this.sel_start = this.sel_drag = 0; this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length(); this.sel_end = this.text.length();
this.r_dirty = true; // this.r_dirty = true;
} }
else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) { else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) {
if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty
@ -293,7 +297,7 @@ public class Textbox extends Element {
public void deselect() { public void deselect() {
this.sel_start = this.sel_end = this.sel_drag = -1; this.sel_start = this.sel_end = this.sel_drag = -1;
this.tmr_leftmb = 0L; this.tmr_leftmb = 0L;
this.r_dirty = true; // this.r_dirty = true;
if(this.func != null) { if(this.func != null) {
this.func.use(this, Action.UNFOCUS); this.func.use(this, Action.UNFOCUS);
} }
@ -308,7 +312,7 @@ public class Textbox extends Element {
this.text_y += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrolly))); this.text_y += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrolly)));
if(n != 0) { if(n != 0) {
gui_text_clamp_scroll(); gui_text_clamp_scroll();
this.r_dirty = true; // this.r_dirty = true;
} }
if((((long)n) * 1000000L) <= this.tmr_scroll) if((((long)n) * 1000000L) <= this.tmr_scroll)
this.tmr_scroll -= ((long)n) * 1000000L; this.tmr_scroll -= ((long)n) * 1000000L;
@ -359,9 +363,9 @@ public class Textbox extends Element {
this.text_x -= (this.cursorX + Font.XGLYPH) - (x1 + x2); this.text_x -= (this.cursorX + Font.XGLYPH) - (x1 + x2);
gui_text_update_cur(offset, false); gui_text_update_cur(offset, false);
} }
else { // else {
this.r_dirty = true; // this.r_dirty = true;
} // }
} }
public void insertText(String str) { public void insertText(String str) {
@ -410,7 +414,7 @@ public class Textbox extends Element {
this.sel_end = this.sel_drag; this.sel_end = this.sel_drag;
} }
// logd("tst", "@S %d . %d . %d", this.sel_start, this.sel_drag, this.sel_end); // logd("tst", "@S %d . %d . %d", this.sel_start, this.sel_drag, this.sel_end);
this.r_dirty = true; // this.r_dirty = true;
if(x < x1) if(x < x1)
this.scrollx = x1 - x; this.scrollx = x1 - x;
else if(x >= (x1 + x2)) else if(x >= (x1 + x2))

View file

@ -36,7 +36,7 @@ public class Toggle extends Element {
if((this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : !this.value) != prev) { if((this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : !this.value) != prev) {
// this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF; // this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF;
// gui_update_style(this, 1); // gui_update_style(this, 1);
this.r_dirty = true; // this.r_dirty = true;
this.func.use(this, this.value); this.func.use(this, this.value);
this.formatText(); this.formatText();
this.playSound(); this.playSound();

View file

@ -1,12 +1,14 @@
package game.gui.element; package game.gui.element;
import game.renderer.Drawing;
public class TransparentBox extends Textbox { public class TransparentBox extends Textbox {
public TransparentBox(int x, int y, int w, int h, String text) { public TransparentBox(int x, int y, int w, int h, String text) {
super(x, y, w, h, text); super(x, y, w, h, text);
} }
protected void drawBackground() { protected void drawBackground() {
// Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, if(this.gm.theWorld != null)
// this.gm.style.field_top & 0x80ffffff, this.gm.style.field_btm & 0x80ffffff, this.gm.style.brdr_top & 0x80ffffff, this.gm.style.brdr_btm & 0x80ffffff); Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000);
} }
} }