Skip to content

Commit 8e403e6

Browse files
author
s.kushnirenko
committed
debug: avoid tilda symbol on open console
1 parent 5b9e357 commit 8e403e6

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

src/dev/imgui_qconsole.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ struct IMGUIInputLine
188188

189189
/// Renders the contorl in whatever the surrounding IMGUI context is. Returns true if new user input is available.
190190
bool render(int width);
191+
bool reclaim_focus = false;
191192
};
192193

193194
/// GUI Ostream pane with ANSI Color Code Support
@@ -235,6 +236,7 @@ class imgui_qconsole : public MultiStream
235236
int HistoryPos = -1; ///< index into the console history buffer, for when we press up/down arrow to scroll previous commands
236237

237238
float fontScale = 1.2f; ///< text scale for the console widget window
239+
bool skip_event = false;
238240

239241
void clear(); ///< Clear the ostream
240242

@@ -914,12 +916,12 @@ inline bool IMGUIInputLine::render(int width)
914916
{
915917
bool rval = false;
916918

917-
// Command-line
918-
bool reclaim_focus = false;
919-
920919
ImGui::SetNextWindowSize(ImVec2(width, 0));
921-
if (ImGui::InputText("##Input", &InputBuf, input_text_flags, &TextEditCallbackStub, (void*)(&textCallbacks)))
922-
{
920+
if (reclaim_focus) {
921+
ImGui::SetKeyboardFocusHere(0); // Auto focus previous widget
922+
reclaim_focus = false;
923+
}
924+
if (ImGui::InputText("##Input", &InputBuf, input_text_flags, &TextEditCallbackStub, (void*)(&textCallbacks))) {
923925
reclaim_focus = true;
924926

925927
char* s = InputBuf.data();
@@ -939,9 +941,7 @@ inline bool IMGUIInputLine::render(int width)
939941
}
940942

941943
// Auto-focus on window apparition
942-
ImGui::SetItemDefaultFocus();
943-
if (reclaim_focus)
944-
ImGui::SetKeyboardFocusHere(-1); // Auto focus previous widget
944+
ImGui::SetItemDefaultFocus();
945945

946946
return rval;
947947
}

src/game/game.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,6 @@ void game_draw_frame_warning() {
253253
warning_draw();
254254
}
255255

256-
void game_toggle_debug_console() {
257-
game.console = !game.console;
258-
}
259-
260256
void game_handle_input_after() {
261257
OZZY_PROFILER_SECTION("Input/Frame/After");
262258
window_update_input_after();

src/game/game.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ void game_sound_frame();
1717
void game_handle_input_frame();
1818
void game_draw_frame_warning();
1919
void game_handle_input_after();
20-
void game_toggle_debug_console();
2120
void game_exit_editor();
2221

2322
void game_exit();

src/scripts/building_info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ building_physician = {
132132

133133
building_conservatory = {
134134
animations : {
135-
work : { pos : [82, 14], anim_id: IMG_MUSICIAN_SHOW_SN }
135+
work : { pos : [82, 18], anim_id: IMG_MUSICIAN_SHOW_SN }
136136
},
137137
labor_category : LABOR_CATEGORY_ENTERTAINMENT,
138138
}

src/widget/debug_console.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,30 @@ bool game_imgui_overlay_handle_event(void *e) {
8585
}
8686
}
8787

88+
if (event->type == SDL_TEXTINPUT && *event->text.text == '`') {
89+
debug_console().skip_event = true;
90+
}
91+
8892
if (!game.console) {
8993
return false;
9094
}
9195

96+
if (debug_console().skip_event) {
97+
debug_console().skip_event = false;
98+
return false;
99+
}
100+
92101
ImGui_ImplSDL2_ProcessEvent(event);
93102
return false;
94103
}
95104

105+
void game_toggle_debug_console() {
106+
game.console = !game.console;
107+
if (game.console) {
108+
debug_console().is.reclaim_focus = true;
109+
}
110+
}
111+
96112
void bind_debug_command(pcstr cmd, std::function<void(std::istream &, std::ostream &)> f) {
97113
debug_console().con.bind_command(cmd, f);
98114
}

src/widget/debug_console.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ void game_imgui_overlay_destroy();
1212
void game_imgui_overlay_begin_frame();
1313
void game_imgui_overlay_draw();
1414
bool game_imgui_overlay_handle_event(void *event);
15+
void game_toggle_debug_console();
1516
void bind_debug_command(pcstr cmd, std::function<void(std::istream &, std::ostream &)> f);
1617
void bind_debug_console_var_int(pcstr var, int &ref);

0 commit comments

Comments
 (0)