UI: Added widget focus for regular input blocking | Physics: Trigger callbacks

This commit is contained in:
2024-11-02 02:25:24 +01:00
parent cb55590e03
commit 9ae08a9278
7 changed files with 65 additions and 36 deletions

View File

@@ -7,13 +7,14 @@ ui_full_size_background :: (color: Color = .{0,0,0,1}, identifier: s64 = 0, loc
background := ui_box_make(.DRAW_BACKGROUND, hash=get_hash(loc, identifier));
}
ui_container_layout :: (color: Color = .{0,0,0,0}, identifier: s64 = 0, loc := #caller_location) {
ui_container_layout :: (color: Color = .{0,0,0,0}, identifier: s64 = 0, loc := #caller_location) -> *UI_Box {
ui_set_next_size_x(.CHILDREN_SUM);
ui_set_next_size_y(.CHILDREN_SUM);
ui_set_next_background_color(color);
container := ui_box_make(.DRAW_BACKGROUND, hash=get_hash(loc, identifier));
return container;
}
ui_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
@@ -109,7 +110,7 @@ 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_container_layout();
container := ui_container_layout();
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
{
ui_label(label);
@@ -143,6 +144,12 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call
if outer.interaction.clicked {
outer.interaction.editing = true;
if engine.editor.focused_widget != null {
engine.editor.focused_widget.interaction.editing = false;
}
engine.editor.focused_widget = container;
}
if outer.interaction.editing {
@@ -154,6 +161,7 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call
if key_down(.RETURN) {
outer.interaction.editing = false;
engine.editor.focused_widget = null;
}
if engine.input.has_char {
@@ -223,6 +231,7 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
temp_str.count = text_widget._number_text.count;
<<value = parse_float(*temp_str);
outer.interaction.editing = false;
engine.editor.focused_widget = null;
}
if engine.input.has_char {
@@ -254,7 +263,12 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
}
if outer.interaction.clicked {
if engine.editor.focused_widget != null {
engine.editor.focused_widget.interaction.editing = false;
}
outer.interaction.editing = true;
engine.editor.focused_widget = outer;
formatted_text := copy_temporary_string(tprint("%", formatFloat(<<value, trailing_width = 2, zero_removal=.NO)));
memcpy(text_widget._number_text.data.data, formatted_text.data, formatted_text.count);
text_widget._number_text.count = formatted_text.count;