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);
}
protected int getMargin() {
protected int getMarginX() {
return 0;
}
protected int getMarginY() {
return 0;
}

View file

@ -19,7 +19,7 @@ public class Dropdown<T> extends Element {
sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
}
this.setText(sb.toString());
this.visible = this.r_dirty = false;
this.visible = /* this.r_dirty = */ false;
}
public void updateText() {
@ -39,7 +39,7 @@ public class Dropdown<T> extends Element {
public void deselect() {
this.visible = false;
this.r_dirty = true;
// this.r_dirty = true;
}
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.visible = false;
this.r_dirty = true;
// this.r_dirty = true;
}
public void drawHover() {
@ -113,7 +113,7 @@ public class Dropdown<T> extends Element {
else if(this.gui != null) {
Handle drop = this.handle;
drop.visible = true;
drop.r_dirty = true;
// drop.r_dirty = true;
this.gui.selected = drop;
this.playSound();
}

View file

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

View file

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

View file

@ -97,6 +97,10 @@ public class Textbox extends Element {
return false;
}
protected int getMarginX() {
return 4;
}
public void setText(String str) {
if(this.validator != null)
str = this.validator.filter(str);
@ -115,7 +119,7 @@ public class Textbox extends Element {
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
if(this.sel_start >= 0)
this.cursorY += (this.text_y - prev);
this.r_dirty = true;
// this.r_dirty = true;
}
else if(scr_y != 0 || scr_x != 0) {
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);
if(this.sel_start >= 0)
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))) {
this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length();
this.r_dirty = true;
// this.r_dirty = true;
}
else {
gui_text_select(x, y, shift);
@ -168,7 +172,7 @@ public class Textbox extends Element {
if(ctrl && key == Keysym.A) {
this.sel_start = this.sel_drag = 0;
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))) {
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() {
this.sel_start = this.sel_end = this.sel_drag = -1;
this.tmr_leftmb = 0L;
this.r_dirty = true;
// this.r_dirty = true;
if(this.func != null) {
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)));
if(n != 0) {
gui_text_clamp_scroll();
this.r_dirty = true;
// this.r_dirty = true;
}
if((((long)n) * 1000000L) <= this.tmr_scroll)
this.tmr_scroll -= ((long)n) * 1000000L;
@ -359,9 +363,9 @@ public class Textbox extends Element {
this.text_x -= (this.cursorX + Font.XGLYPH) - (x1 + x2);
gui_text_update_cur(offset, false);
}
else {
this.r_dirty = true;
}
// else {
// this.r_dirty = true;
// }
}
public void insertText(String str) {
@ -410,7 +414,7 @@ public class Textbox extends Element {
this.sel_end = this.sel_drag;
}
// 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)
this.scrollx = x1 - x;
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) {
// this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF;
// gui_update_style(this, 1);
this.r_dirty = true;
// this.r_dirty = true;
this.func.use(this, this.value);
this.formatText();
this.playSound();

View file

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