UI clean-up

This commit is contained in:
2025-01-03 16:15:48 +01:00
parent 03b84515e7
commit e6c7b2ab0c
6 changed files with 73 additions and 44 deletions

View File

@@ -3,6 +3,7 @@ MAX_BOXES :: 4096;
MAX_WINDOWS :: 128;
SCROLL_SPEED :: 5;
DEFAULT_PADDING :: 5;
WINDOW_TITLE_BAR_HEIGHT :: 20.0;
WINDOW_BORDER_WIDTH :: 3;
@@ -109,7 +110,7 @@ UI_Child_Axis :: enum {
UI_Child_Alignment :: enum {
LEFT;
RIGHT;
CENTERED;
CENTERED_VERTICALLY;
}
UI_Text_Alignment_Flags :: enum_flags u8 {
@@ -664,8 +665,9 @@ ui_set_rect_recursively :: (parent: *UI_Box) {
while child != null {
defer child = child.next;
if parent.layout.alignment == .CENTERED {
if parent.layout.alignment == .CENTERED_VERTICALLY {
child.rect.x = starting_offset_x;
child.rect.y = parent.rect.y + parent.rect.h / 2 - child.rect.h / 2;
} else {
child.rect.x = starting_offset_x;
child.rect.y = starting_offset_y;
@@ -851,11 +853,12 @@ ui_render :: () {
{
if window.title.count > 0 {
font_handle := ui_state.fonts.regular;
x : float = cast(float)(xx window.actual_position.x + cast(u32)WINDOW_BORDER_WIDTH + 2);
x : float = cast(float)(xx window.actual_position.x + cast(u32)WINDOW_BORDER_WIDTH + DEFAULT_PADDING);
y : float = (cast(float)engine.renderer.render_target_height - (window.actual_position.y + WINDOW_BORDER_WIDTH + 2.0));
text_size := get_text_size(engine.renderer, window.title, font_handle);
y -= text_size.y;
y -= text_size.y / 2 + (WINDOW_TITLE_BAR_HEIGHT - WINDOW_BORDER_WIDTH) / 2;
y = round(y);
render_data := bake_text(engine.renderer, x, y, window.title, font_handle, .{1,1,1,1});
font := *engine.renderer.fonts[font_handle - 1];

View File

@@ -23,7 +23,7 @@ ui_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> cli
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
@@ -34,7 +34,6 @@ ui_checkbox :: (checked: *bool, identifier: s64 = 0, loc := #caller_location) ->
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PIXELS, 12);
ui_set_next_size_y(.PIXELS, 12);
ui_set_next_padding(5);
//ui_set_next_padding(5);
//ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
@@ -61,11 +60,11 @@ ui_checkbox_field :: (label: string, value: *bool, identifier: s64 = 0, loc := #
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(2.0);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
{
ui_label(label);
ui_label_half_parent_x(label);
ui_checkbox(value, identifier);
}
ui_pop_parent();
@@ -87,7 +86,7 @@ ui_button_no_bg :: (text: string, identifier: s64 = 0, loc := #caller_location)
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
@@ -99,7 +98,7 @@ ui_button_no_border :: (text: string, identifier: s64 = 0, loc := #caller_locati
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
@@ -128,7 +127,7 @@ ui_label_animated :: (text: string, text_color: Color = .{1,1,1,1}, identifier:
ui_set_next_text_color(text_color);
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
box := ui_box_make(.DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
}
@@ -143,12 +142,22 @@ ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0,
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
ui_label_half_parent_x :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_text(text);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_text_color(text_color);
ui_set_next_size_x(.PCT, 0.5);
ui_set_next_size_y(.TEXT_DIM);
//ui_set_next_padding(5);
ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
}
ui_field_label :: (label: string, value: Any, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_size_x(.PCT, 1.0);
text_size := get_text_size(engine.renderer, label, ui_state.fonts.button);
ui_set_next_size_y(.PIXELS, text_size.y);
//ui_set_next_padding(2.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
@@ -176,13 +185,13 @@ ui_field_label :: (label: string, value: Any, identifier: s64 = 0, loc := #calle
ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(2.0);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_background_color(.{1,1,1,1});
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
ui_push_parent(ui_state.last_box, .CENTERED_VERTICALLY, .HORIZONTAL);
{
ui_label(label);
ui_label_half_parent_x(label);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
@@ -358,11 +367,11 @@ ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #ca
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(2.0);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
ui_push_parent(container, .CENTERED_VERTICALLY, .HORIZONTAL);
{
ui_label(label);
ui_label_half_parent_x(label);
changed |= ui_float_field(value, identifier);
}
ui_pop_parent();
@@ -379,7 +388,7 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
text_size := get_text_size(engine.renderer, "0.00", ui_state.fonts.button);
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
@@ -498,11 +507,11 @@ ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc :=
changed := false;
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_padding(2.0);
ui_set_next_padding(DEFAULT_PADDING);
container := ui_box_make(0, hash=get_hash(loc, identifier));
ui_push_parent(container, .LEFT, .HORIZONTAL);
ui_push_parent(container, .CENTERED_VERTICALLY, .HORIZONTAL);
{
ui_label(label);
ui_label_half_parent_x(label);
//ui_set_next_size_x(.PCT, 0.5);
//ui_set_next_size_y(.CHILDREN_SUM);
@@ -511,10 +520,15 @@ ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc :=
//ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
ui_label("X");
ui_space(5,0);
changed |= ui_float_field(*value.x);
ui_space(5,0);
ui_label("Y");
ui_space(5,0);
changed |= ui_float_field(*value.y);
ui_space(5,0);
ui_label("Z");
ui_space(5,0);
changed |= ui_float_field(*value.z);
//ui_pop_parent();
@@ -534,7 +548,7 @@ ui_clickable_label :: (text: string, selected: bool = false, identifier: s64 = 0
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER | .CLICKABLE, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
@@ -549,7 +563,7 @@ ui_toolbar :: (identifier: s64 = 0, loc := #caller_location) {
ui_tab_title_bar :: (title: string, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.03, 0.03, 0.03, 1.0});
ui_set_next_padding(5);
ui_set_next_padding(DEFAULT_PADDING);
ui_set_next_size_y(.CHILDREN_SUM);
parent := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
ui_push_parent(parent, alignment=.LEFT, axis=.VERTICAL);