diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index d4dcbe3c95baf..42228fbf5f8cd 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -465,7 +465,7 @@ class cataimgui::window_impl class cataimgui::filter_box_impl { public: - char text[255]; // NOLINT(modernize-avoid-c-arrays) + std::array text; ImGuiID id; }; @@ -627,9 +627,9 @@ void cataimgui::window::draw_filter( const input_context &ctxt, bool filtering_a action_button( "TEXT.CONFIRM", ctxt.get_button_text( "TEXT.CONFIRM", _( "OK" ) ) ); ImGui::SameLine(); } - ImGui::BeginDisabled( filtering_active ); - ImGui::InputText( "##FILTERBOX", filter_impl->text, - std::extent_v < decltype( filter_impl->text ) > ); + ImGui::BeginDisabled( !filtering_active ); + ImGui::InputText( "##FILTERBOX", filter_impl->text.data(), + filter_impl->text.size() ); ImGui::EndDisabled(); if( !filter_impl->id ) { filter_impl->id = GImGui->LastItemData.ID; @@ -639,7 +639,7 @@ void cataimgui::window::draw_filter( const input_context &ctxt, bool filtering_a std::string cataimgui::window::get_filter() { if( filter_impl ) { - return std::string( filter_impl->text ); + return std::string( filter_impl->text.data() ); } else { return std::string(); } @@ -655,12 +655,3 @@ void cataimgui::window::clear_filter() } } } - -//void cataimgui::window::set_filter( const std::string &filter ) -//{ -// // doesnt currently work, relies on API only available in newer ImGUi, because I can't have nice things -// //ImGuiInputTextState* input_state = ImGui::GetInputTextState( p_impl->id ); -// //if( input_state ) { -// // input_state->ReloadUserBufAndSelectAll(); -// //} -//} diff --git a/src/cata_imgui.h b/src/cata_imgui.h index 25da9eea3f43b..50db9dbe4e519 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -105,7 +105,6 @@ class window size_t str_width_to_pixels( size_t len ); size_t str_height_to_pixels( size_t len ); std::string get_filter(); - //void set_filter( const std::string &filter ); void clear_filter(); void mark_resized(); diff --git a/src/input_context.cpp b/src/input_context.cpp index 1271bb258504c..ce36e2caf2220 100644 --- a/src/input_context.cpp +++ b/src/input_context.cpp @@ -698,10 +698,10 @@ void keybindings_ui::draw_controls() for( ; legend_idx < legend.size(); legend_idx++ ) { draw_colored_text( legend[legend_idx], c_white ); } + draw_filter( *ctxt, status == kb_menu_status::filter ); if( last_status != status && status == kb_menu_status::filter ) { - ImGui::SetKeyboardFocusHere( 0 ); + ImGui::SetKeyboardFocusHere( -1 ); } - draw_filter( *ctxt, status == kb_menu_status::filter ); ImGui::Separator(); if( last_status != status && status == kb_menu_status::show ) { @@ -1452,9 +1452,6 @@ action_id input_context::display_menu_imgui( const bool permit_execute_action ) } else { break; } - } else if( action == "TEXT.INPUT_FROM_FILE" ) { - //kb_menu.set_filter( kb_menu.get_filter() + get_input_string_from_file() ); - continue; } else if( action == "HELP_KEYBINDINGS" ) { // update available hotkeys in case they've changed kb_menu.hotkeys = ctxt.get_available_single_char_hotkeys( display_help_hotkeys );