UI fun
This commit is contained in:
@@ -523,6 +523,7 @@ ui_figure_out_sizes :: () {
|
|||||||
if box.semantic_size[0].size_kind == .PCT {
|
if box.semantic_size[0].size_kind == .PCT {
|
||||||
if box.parent != null {
|
if box.parent != null {
|
||||||
box.size.x = box.parent.size.x * box.semantic_size[0].value - (box.parent.padding_left + box.parent.padding_right);
|
box.size.x = box.parent.size.x * box.semantic_size[0].value - (box.parent.padding_left + box.parent.padding_right);
|
||||||
|
//print("Box PCT % and final size %\n", box.semantic_size[0].value, box.size.x);
|
||||||
} else if box.root_in_window {
|
} else if box.root_in_window {
|
||||||
box.size.x = cast(float)box.window.size.x * box.semantic_size[0].value - (cast(float)WINDOW_BORDER_WIDTH);
|
box.size.x = cast(float)box.window.size.x * box.semantic_size[0].value - (cast(float)WINDOW_BORDER_WIDTH);
|
||||||
} else {
|
} else {
|
||||||
@@ -589,6 +590,8 @@ ui_figure_out_sizes :: () {
|
|||||||
window := box.window;
|
window := box.window;
|
||||||
box.rect.x = xx (window.actual_position.x + window.scroll_offset.x) + cast(float)WINDOW_BORDER_WIDTH;
|
box.rect.x = xx (window.actual_position.x + window.scroll_offset.x) + cast(float)WINDOW_BORDER_WIDTH;
|
||||||
box.rect.y = xx (window.actual_position.y + window.scroll_offset.y) + cast(float)WINDOW_BORDER_WIDTH + WINDOW_TITLE_BAR_HEIGHT;
|
box.rect.y = xx (window.actual_position.y + window.scroll_offset.y) + cast(float)WINDOW_BORDER_WIDTH + WINDOW_TITLE_BAR_HEIGHT;
|
||||||
|
box.size.x = xx (window.size.x - WINDOW_BORDER_WIDTH * 2);
|
||||||
|
box.size.y = xx (window.size.y - WINDOW_BORDER_WIDTH * 2 - WINDOW_TITLE_BAR_HEIGHT);
|
||||||
} else {
|
} else {
|
||||||
box.rect.x = 0.0;
|
box.rect.x = 0.0;
|
||||||
box.rect.y = 0.0;
|
box.rect.y = 0.0;
|
||||||
|
|||||||
@@ -59,10 +59,13 @@ ui_checkbox :: (checked: *bool, identifier: s64 = 0, loc := #caller_location) ->
|
|||||||
|
|
||||||
ui_checkbox_field :: (label: string, value: *bool, identifier: s64 = 0, loc := #caller_location) -> bool {
|
ui_checkbox_field :: (label: string, value: *bool, identifier: s64 = 0, loc := #caller_location) -> bool {
|
||||||
changed := false;
|
changed := false;
|
||||||
ui_container_layout(identifier=identifier, loc=loc);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
ui_set_next_size_y(.CHILDREN_SUM);
|
||||||
|
ui_set_next_padding(5.0);
|
||||||
|
container := ui_box_make(0, hash=get_hash(loc, identifier));
|
||||||
|
ui_push_parent(container, .LEFT, .HORIZONTAL);
|
||||||
{
|
{
|
||||||
ui_label(label);
|
ui_label_half_parent(label);
|
||||||
ui_checkbox(value, identifier);
|
ui_checkbox(value, identifier);
|
||||||
}
|
}
|
||||||
ui_pop_parent();
|
ui_pop_parent();
|
||||||
@@ -139,6 +142,16 @@ ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0,
|
|||||||
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui_label_half_parent :: (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);
|
||||||
|
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||||
|
}
|
||||||
|
|
||||||
ui_label_for_fields :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
|
ui_label_for_fields :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
|
||||||
ui_set_next_text(text);
|
ui_set_next_text(text);
|
||||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
||||||
@@ -161,16 +174,19 @@ ui_label_fill_parent_x :: (text: string, identifier: s64 = 0, loc := #caller_loc
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
|
ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
|
||||||
container := ui_container_layout();
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
|
ui_set_next_size_y(.CHILDREN_SUM);
|
||||||
|
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, .LEFT, .HORIZONTAL);
|
||||||
{
|
{
|
||||||
ui_label(label);
|
ui_label_half_parent(label);
|
||||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
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});
|
ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
|
||||||
ui_set_next_size_x(.PCT, 1);
|
|
||||||
|
|
||||||
text_size := get_text_size(engine.renderer, "E", ui_state.fonts.button);
|
text_size := get_text_size(engine.renderer, "E", ui_state.fonts.button);
|
||||||
|
|
||||||
|
ui_set_next_size_x(.PCT, 0.5);
|
||||||
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
|
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
|
||||||
ui_set_next_padding(5);
|
ui_set_next_padding(5);
|
||||||
|
|
||||||
@@ -188,7 +204,7 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call
|
|||||||
ui_set_next_text_color(.{1,1,1,1});
|
ui_set_next_text_color(.{1,1,1,1});
|
||||||
ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
||||||
ui_set_next_text_color(.{1,1,1,1});
|
ui_set_next_text_color(.{1,1,1,1});
|
||||||
ui_set_next_size_x(.TEXT_DIM);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_set_next_size_y(.TEXT_DIM);
|
ui_set_next_size_y(.TEXT_DIM);
|
||||||
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
text_widget := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||||
}
|
}
|
||||||
@@ -237,16 +253,16 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call
|
|||||||
|
|
||||||
ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller_location) {
|
ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller_location) {
|
||||||
ui_container_layout(identifier=identifier, loc=loc);
|
ui_container_layout(identifier=identifier, loc=loc);
|
||||||
ui_set_next_size_x(.CHILDREN_SUM);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
||||||
{
|
{
|
||||||
ui_label(label);
|
ui_label_half_parent(label);
|
||||||
|
|
||||||
text_size := get_text_size(engine.renderer, tprint("%", <<value), ui_state.fonts.button);
|
text_size := get_text_size(engine.renderer, tprint("%", <<value), ui_state.fonts.button);
|
||||||
|
|
||||||
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
|
ui_set_next_size_y(.PIXELS, text_size.y); // TODO
|
||||||
ui_set_next_size_x(.CHILDREN_SUM);
|
ui_set_next_size_x(.PCT, 0.5);
|
||||||
ui_set_next_padding(5);
|
//ui_set_next_padding(5);
|
||||||
|
|
||||||
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
|
||||||
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
|
outer := ui_box_make(.ANIMATE_ON_HOVER | .CLICKABLE | .DRAW_BORDER, get_hash(loc, identifier));
|
||||||
@@ -475,7 +491,7 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
|
|||||||
|
|
||||||
ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc := #caller_location) -> bool {
|
ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc := #caller_location) -> bool {
|
||||||
changed := false;
|
changed := false;
|
||||||
ui_set_next_size_x(.TEXT_DIM);
|
ui_set_next_size_x(.PCT, 1.0);
|
||||||
ui_set_next_size_y(.TEXT_DIM);
|
ui_set_next_size_y(.TEXT_DIM);
|
||||||
ui_container_layout(identifier=identifier, loc=loc);
|
ui_container_layout(identifier=identifier, loc=loc);
|
||||||
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
|
||||||
|
|||||||
Reference in New Issue
Block a user