From e77241cd56d09ba9bb446d9320de512f27f53622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Sallai?= Date: Sat, 18 Feb 2023 21:05:30 +0200 Subject: [PATCH] improve command line appearance and autofocus --- src/live_debugger/mod.rs | 33 +++++++++++++++++++++++++++++++-- src/scene/game_scene.rs | 8 +++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/live_debugger/mod.rs b/src/live_debugger/mod.rs index 95e79bb..ed3d2f5 100644 --- a/src/live_debugger/mod.rs +++ b/src/live_debugger/mod.rs @@ -27,6 +27,7 @@ pub struct LiveDebugger { npc_inspector_visible: bool, hotkey_list_visible: bool, command_line_parser: CommandLineParser, + command_line_focused: bool, last_stage_id: usize, stages: Vec, selected_stage: i32, @@ -46,6 +47,7 @@ impl LiveDebugger { npc_inspector_visible: false, hotkey_list_visible: false, command_line_parser: CommandLineParser::new(), + command_line_focused: false, last_stage_id: usize::MAX, stages: Vec::new(), selected_stage: -1, @@ -83,11 +85,19 @@ impl LiveDebugger { .collapsible(false) .movable(false) .build(ui, || { - ui.text("Command:"); - ui.same_line(); + self.draw_left_label(ui, "Command:"); + + let iw = ui.push_item_width(state.screen_size.0 - 150.0); + + if !self.command_line_focused { + ui.set_keyboard_focus_here(); + self.command_line_focused = true; + } ui.input_text("", &mut self.command_line_parser.buffer).build(); + iw.pop(ui); + if ui.is_item_active() { state.control_flags.set_tick_world(false); } else { @@ -122,6 +132,8 @@ impl LiveDebugger { self.command_line_parser.last_feedback.clone(), ); }); + } else { + self.command_line_focused = false; } if !state.debugger { @@ -544,6 +556,23 @@ impl LiveDebugger { Ok(()) } + + fn draw_left_label(&mut self, ui: &imgui::Ui, text: &str) { + self.draw_text_with_top_padding(ui, text, 6.0); + } + + fn draw_text_with_top_padding(&mut self, ui: &imgui::Ui, text: &str, padding: f32) { + let previous_cursor_pos = ui.cursor_pos(); + let y = previous_cursor_pos[1] + padding; + + ui.set_cursor_pos([previous_cursor_pos[0], y]); + ui.text(text); + ui.same_line(); + + let mut current_cursor_pos = ui.cursor_pos(); + current_cursor_pos[1] = previous_cursor_pos[1]; + ui.set_cursor_pos(current_cursor_pos); + } } fn cond_flags(ui: &imgui::Ui, cond: &mut crate::common::Condition) { diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index 8c8502a..73ea93e 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -2337,7 +2337,13 @@ impl Scene for GameScene { ScanCode::F10 => state.settings.debug_outlines = !state.settings.debug_outlines, ScanCode::F11 => state.settings.fps_counter = !state.settings.fps_counter, ScanCode::F12 => state.debugger = !state.debugger, - ScanCode::Grave => state.command_line = !state.command_line, + ScanCode::Grave => { + state.command_line = !state.command_line; + + if !state.command_line { + state.control_flags.set_tick_world(true); + } + } _ => {} };