diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-08-09 18:22:43 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-08-09 18:22:43 +0200 |
commit | 44bc399ccbd7e37107ae754db7da3d918229422d (patch) | |
tree | cf989a2699c7638328f292bcde49ed66ac013640 /src/SearchBar.cpp | |
parent | c2efd1e6587223cf9fff302fbc0ef80fcb4340e2 (diff) |
Youtube: show search suggestions instead of immediate search
Fix save file dialog not showing all files after navigating to another
directory if the search is not empty.
Fix matrix system message deletion reverting back to use message (for
avatar) and text color.
Diffstat (limited to 'src/SearchBar.cpp')
-rw-r--r-- | src/SearchBar.cpp | 86 |
1 files changed, 1 insertions, 85 deletions
diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 5909635..c1f9ceb 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -21,17 +21,13 @@ namespace QuickMedia { onTextUpdateCallback(nullptr), onTextSubmitCallback(nullptr), onTextBeginTypingCallback(nullptr), - onAutocompleteRequestCallback(nullptr), text_autosearch_delay(50), - autocomplete_search_delay(250), caret_visible(true), text(placeholder, *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(16 * get_ui_scale())), - autocomplete_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(16 * get_ui_scale())), background(sf::Vector2f(1.0f, 1.0f), 10.0f, get_current_theme().selected_color, rounded_rectangle_shader), placeholder_str(placeholder), show_placeholder(true), updated_search(false), - updated_autocomplete(false), draw_logo(false), needs_update(true), input_masked(input_masked), @@ -44,7 +40,6 @@ namespace QuickMedia { padding_top = padding_top_default; padding_bottom = padding_bottom_default; text.setFillColor(get_current_theme().placeholder_text_color); - autocomplete_text.setFillColor(get_current_theme().placeholder_text_color); shade.setFillColor(get_current_theme().shade_color); if(plugin_logo && plugin_logo->getNativeHandle() != 0) plugin_logo_sprite.setTexture(*plugin_logo, true); @@ -65,8 +60,7 @@ namespace QuickMedia { window.draw(shade); background.draw(window); - // TODO: Render starting from the character after text length - window.draw(autocomplete_text); + if(input_masked && !show_placeholder) { std::string masked_str(text.getString().getSize(), '*'); sf::Text masked_text(std::move(masked_str), *text.getFont(), text.getCharacterSize()); @@ -117,7 +111,6 @@ namespace QuickMedia { if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::D && event.key.control) { clear(); updated_search = true; - updated_autocomplete = true; time_since_search_update.restart(); } @@ -144,13 +137,6 @@ namespace QuickMedia { if(onTextUpdateCallback) onTextUpdateCallback(*u8_str); typing = false; - } else if(updated_autocomplete && elapsed_time >= autocomplete_search_delay) { - updated_autocomplete = false; - if(!show_placeholder && onAutocompleteRequestCallback) { - auto u8 = text.getString().toUtf8(); - std::string *u8_str = (std::string*)&u8; - onAutocompleteRequestCallback(*u8_str); - } } } @@ -184,7 +170,6 @@ namespace QuickMedia { background.set_position(sf::Vector2f(pos.x + offset_x, pos.y + padding_top)); shade.setPosition(pos); sf::Vector2f font_position(std::floor(pos.x + offset_x + background_margin_horizontal), std::floor(pos.y + padding_top + background_margin_vertical)); - autocomplete_text.setPosition(font_position); text.setPosition(font_position); } @@ -201,9 +186,6 @@ namespace QuickMedia { show_placeholder = true; text.setString(placeholder_str); text.setFillColor(get_current_theme().placeholder_text_color); - autocomplete_text.setString(""); - } else { - clear_autocomplete_if_text_not_substring(); } if(!updated_search) { typing = true; @@ -211,7 +193,6 @@ namespace QuickMedia { onTextBeginTypingCallback(); } updated_search = true; - updated_autocomplete = true; time_since_search_update.restart(); } } else if(codepoint == 13) { // Return @@ -235,10 +216,8 @@ namespace QuickMedia { show_placeholder = true; text.setString(placeholder_str); text.setFillColor(get_current_theme().placeholder_text_color); - autocomplete_text.setString(""); needs_update = true; updated_search = false; - updated_autocomplete = false; backspace_pressed = false; } @@ -256,51 +235,18 @@ namespace QuickMedia { str += text_to_add; text.setString(str); - clear_autocomplete_if_text_not_substring(); if(!updated_search) { typing = true; if(onTextBeginTypingCallback) onTextBeginTypingCallback(); } updated_search = true; - updated_autocomplete = true; time_since_search_update.restart(); backspace_pressed = false; if(text_to_add.find('\n') != std::string::npos) needs_update = true; } - bool SearchBar::is_cursor_at_start_of_line() const { - // TODO: When it's possible to move the cursor, then check at the cursor position instead of end of the string - const sf::String &str = text.getString(); - return show_placeholder || str.getSize() == 0 || str[str.getSize() - 1] == '\n'; - } - - void SearchBar::set_to_autocomplete() { - const sf::String &autocomplete_str = autocomplete_text.getString(); - if(!autocomplete_str.isEmpty()) { - if(show_placeholder) { - show_placeholder = false; - text.setString(""); - text.setFillColor(sf::Color::White); - } - text.setString(autocomplete_str); - if(!updated_search) { - typing = true; - if(onTextBeginTypingCallback) - onTextBeginTypingCallback(); - } - updated_search = true; - updated_autocomplete = true; - time_since_search_update.restart(); - needs_update = true; - } - } - - void SearchBar::set_autocomplete_text(const std::string &text) { - autocomplete_text.setString(text); - } - void SearchBar::set_position(sf::Vector2f pos) { if(std::abs(this->pos.x - pos.x) > 1.0f || std::abs(this->pos.y - pos.y) > 1.0f) { this->pos = pos; @@ -316,36 +262,6 @@ namespace QuickMedia { return editable; } - void SearchBar::clear_autocomplete_if_text_not_substring() { - const sf::String &text_str = text.getString(); - const sf::String &autocomplete_str = autocomplete_text.getString(); - if(text_str.getSize() > autocomplete_str.getSize()) { - autocomplete_text.setString(""); - return; - } - - for(size_t i = 0; i < autocomplete_str.getSize(); ++i) { - if(text_str[i] != autocomplete_str[i]) { - autocomplete_text.setString(""); - return; - } - } - } - - void SearchBar::clear_autocomplete_if_last_char_not_substr() { - const sf::String &text_str = text.getString(); - const sf::String &autocomplete_str = autocomplete_text.getString(); - if(text_str.isEmpty() || text_str.getSize() > autocomplete_str.getSize()) { - autocomplete_text.setString(""); - return; - } - - if(autocomplete_str[text_str.getSize() - 1] != text_str[text_str.getSize() - 1]) { - autocomplete_text.setString(""); - return; - } - } - float SearchBar::getBottom() const { return getBottomWithoutShadow() + 5.0f;//background_shadow.getSize().y; } |