From 3465acd673aff4a1daa9558785240eeaebd2ecba Mon Sep 17 00:00:00 2001 From: Daniel Bross Date: Tue, 31 Dec 2024 00:37:45 +0100 Subject: [PATCH] UI fixes --- core/entity.jai | 3 +- editor/editor.jai | 1 + editor/editor_ui.jai | 86 +++++++++++++++++++++++--------------------- ui/ui.jai | 27 ++++++++------ ui/widgets.jai | 2 +- 5 files changed, 66 insertions(+), 53 deletions(-) diff --git a/core/entity.jai b/core/entity.jai index 9115220..219b58f 100644 --- a/core/entity.jai +++ b/core/entity.jai @@ -53,12 +53,13 @@ Renderable :: struct { MAX_CHILDREN :: 16; Entity :: struct { + name: string; + id: Entity_Id; @Hide @DontSerialize type : Type; enabled: bool = true; - name: string; parent: *Entity; @DontSerialize children: [MAX_CHILDREN] *Entity; @DontSerialize diff --git a/editor/editor.jai b/editor/editor.jai index 065d29a..8a6cee3 100644 --- a/editor/editor.jai +++ b/editor/editor.jai @@ -119,6 +119,7 @@ Editor :: struct { last_right_mouse_click_time: float; menu_position: Vector2; + hide_ui: bool; icons : struct { play: Texture_Handle; diff --git a/editor/editor_ui.jai b/editor/editor_ui.jai index 88a6b02..f9215cc 100644 --- a/editor/editor_ui.jai +++ b/editor/editor_ui.jai @@ -121,21 +121,19 @@ editor_ui :: () { entity := engine.editor.selected_entities[0]; //ui_slider(*slider_value, 0.0, 1.0); - ui_textfield("Name", *entity.name); - ui_label(tprint("Id: %", entity.id)); - updated := ui_vector_field("Position", *entity.transform.position); - euler_rotation := quaternion_to_euler_v3(entity.transform.orientation); - euler_rotation *= RADIANS_TO_DEGREES; - updated |= ui_vector_field("Rotation", *euler_rotation); - euler_rotation *= DEGREES_TO_RADIANS; - entity.transform.orientation = euler_to_quaternion(euler_rotation); - updated |= ui_vector_field("Scale", *entity.transform.scale); + //updated := ui_vector_field("Position", *entity.transform.position); + //euler_rotation := quaternion_to_euler_v3(entity.transform.orientation); + //euler_rotation *= RADIANS_TO_DEGREES; + //updated |= ui_vector_field("Rotation", *euler_rotation); + //euler_rotation *= DEGREES_TO_RADIANS; + //entity.transform.orientation = euler_to_quaternion(euler_rotation); + //updated |= ui_vector_field("Scale", *entity.transform.scale); - if updated { - update_matrix(*entity.transform); - } + //if updated { + // update_matrix(*entity.transform); + //} entity_ui(entity); } @@ -148,7 +146,9 @@ text_fun : string; slider_value : float = 0.0; base_editor_update :: () { - editor_ui(); + if !engine.editor.hide_ui { + editor_ui(); + } camera := *engine.editor.camera; @@ -173,37 +173,39 @@ base_editor_update :: () { } } } - - if key_pressed(.CTRL) && key_down(.Z) { - undo(); - } - - if key_pressed(.CTRL) && key_down(.S) { - save_scene(engine.current_scene, "../assets/scenes/"); - //show_message("Saved scene"); - } - - if key_down(.DELETE) || key_down(.BACKSPACE) { - for engine.editor.selected_entities { - mark_entity_deleted(it); + + if !engine.editor.focused_widget { + if key_pressed(.CTRL) && key_down(.Z) { + undo(); } - engine.editor.transform_gizmo.selected_axis = .NONE; - engine.editor.selected_entities.count = 0; - } - - if key_pressed(.CTRL) && key_down(.D) { - duplicated_entities: [..] *Entity; - duplicated_entities.allocator = temp; - - for e: engine.editor.selected_entities { - array_add(*duplicated_entities, duplicate_entity(e)); + if key_pressed(.CTRL) && key_down(.S) { + save_scene(engine.current_scene, "../assets/scenes/"); + //show_message("Saved scene"); } - engine.editor.selected_entities.count = 0; + if key_down(.DELETE) || key_down(.BACKSPACE) { + for engine.editor.selected_entities { + mark_entity_deleted(it); + } - for e: duplicated_entities { - array_add(*engine.editor.selected_entities, e); + engine.editor.transform_gizmo.selected_axis = .NONE; + engine.editor.selected_entities.count = 0; + } + + if key_pressed(.CTRL) && key_down(.D) { + duplicated_entities: [..] *Entity; + duplicated_entities.allocator = temp; + + for e: engine.editor.selected_entities { + array_add(*duplicated_entities, duplicate_entity(e)); + } + + engine.editor.selected_entities.count = 0; + + for e: duplicated_entities { + array_add(*engine.editor.selected_entities, e); + } } } } @@ -260,7 +262,7 @@ base_editor_update :: () { engine.editor.menu_position.y = cast(float)engine.renderer.render_target_height - mouse_position.y; } - if !key_pressed(.CTRL) { + if !engine.editor.focused_widget && !key_pressed(.CTRL) { if key_down(.W) { engine.editor.transform_gizmo.transform_type = .TRANSLATION; } @@ -278,6 +280,10 @@ base_editor_update :: () { update_view_matrix(camera); } + if key_pressed(.CTRL) && key_down(.U) { + engine.editor.hide_ui = !engine.editor.hide_ui; + } + if key_pressed(.CTRL) && key_down(.E) { new_mode := ifx engine.mode == .EDITING then Engine_Mode.PLAYING else .EDITING; switch_engine_mode(new_mode); diff --git a/ui/ui.jai b/ui/ui.jai index 3db1b45..24e42e5 100644 --- a/ui/ui.jai +++ b/ui/ui.jai @@ -480,6 +480,21 @@ ui_init :: () { // # BEGIN # LAYOUT ALGORITHM ui_figure_out_sizes :: () { + if ui_state.currently_moving_window { + ui_state.currently_moving_window.offset.x += xx engine.input.mouse.delta_x; + ui_state.currently_moving_window.offset.y += xx engine.input.mouse.delta_y; + ui_state.currently_moving_window.offset.x -= xx min(0, ui_state.currently_moving_window.position.x + ui_state.currently_moving_window.offset.x); + ui_state.currently_moving_window.offset.y -= xx min(0, ui_state.currently_moving_window.position.y + ui_state.currently_moving_window.offset.y); + + if !key_pressed(.MOUSE_LEFT) ui_state.currently_moving_window = null; + + } + + for *window: ui_state.windows { + if window.last_used_frame_index != ui_state.frame_index continue; + window.actual_position = window.position + window.offset; + } + // SET ALL PIXEL AND TEXT SIZES for *box : ui_state.boxes { if box.semantic_size[0].size_kind == { @@ -1206,17 +1221,7 @@ ui_update_input :: () { } } } else { - ui_state.currently_moving_window.offset.x += xx engine.input.mouse.delta_x; - ui_state.currently_moving_window.offset.y += xx engine.input.mouse.delta_y; - ui_state.currently_moving_window.offset.x -= xx min(0, ui_state.currently_moving_window.position.x + ui_state.currently_moving_window.offset.x); - ui_state.currently_moving_window.offset.y -= xx min(0, ui_state.currently_moving_window.position.y + ui_state.currently_moving_window.offset.y); - - if !key_pressed(.MOUSE_LEFT) ui_state.currently_moving_window = null; - } - - for *window: ui_state.windows { - if window.last_used_frame_index != ui_state.frame_index continue; - window.actual_position = window.position + window.offset; + } for *box: ui_state.boxes { diff --git a/ui/widgets.jai b/ui/widgets.jai index 2639e25..127f2dd 100644 --- a/ui/widgets.jai +++ b/ui/widgets.jai @@ -128,7 +128,7 @@ ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #call 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, <