From 837c9a29dc72dc42a160d6777f1935f1f272d072 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 3 Jul 2020 04:38:39 +0200 Subject: Fix being able to submit text while searching, filter not cleared when exiting images view --- src/SearchBar.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/SearchBar.cpp') diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 2008447..f9b6d0e 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -14,6 +14,7 @@ namespace QuickMedia { SearchBar::SearchBar(sf::Font &font, sf::Texture &plugin_logo) : onTextUpdateCallback(nullptr), onTextSubmitCallback(nullptr), + onTextBeginTypingCallback(nullptr), text_autosearch_delay(0), text("Search...", font, 18), show_placeholder(true), @@ -105,13 +106,15 @@ namespace QuickMedia { text.setString("Search..."); text.setFillColor(text_placeholder_color); } + if(!updated_search && onTextBeginTypingCallback) + onTextBeginTypingCallback(); updated_search = true; time_since_search_update.restart(); } } else if(codepoint == 13) { // Return bool clear_search = true; if(onTextSubmitCallback) - clear_search = onTextSubmitCallback(text.getString()); + clear_search = onTextSubmitCallback(show_placeholder ? "" : text.getString()); if(clear_search) clear(); @@ -124,6 +127,8 @@ namespace QuickMedia { sf::String str = text.getString(); str += codepoint; text.setString(str); + if(!updated_search && onTextBeginTypingCallback) + onTextBeginTypingCallback(); updated_search = true; time_since_search_update.restart(); } else if(codepoint == '\n') @@ -137,6 +142,7 @@ namespace QuickMedia { text.setString("Search..."); text.setFillColor(text_placeholder_color); needs_update = true; + updated_search = false; } void SearchBar::append_text(const std::string &text_to_add) { @@ -148,6 +154,8 @@ namespace QuickMedia { sf::String str = text.getString(); str += text_to_add; text.setString(str); + if(!updated_search && onTextBeginTypingCallback) + onTextBeginTypingCallback(); updated_search = true; time_since_search_update.restart(); needs_update = true; -- cgit v1.2.3