From 4af367373f6f92b0fc1d79b2871fa942e1eb86fa Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 9 Nov 2020 00:08:53 +0100 Subject: Matrix: update user display name/avatar when updated in /sync; fix backspace search delay --- src/SearchBar.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/SearchBar.cpp') diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 0c72805..dea9951 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -37,7 +37,7 @@ namespace QuickMedia { needs_update(true), input_masked(input_masked), typing(false), - backspace_seq_count(0), + backspace_pressed(false), vertical_pos(0.0f) { text.setFillColor(text_placeholder_color); @@ -88,15 +88,20 @@ namespace QuickMedia { } void SearchBar::on_event(sf::Event &event) { - if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::V && event.key.control) { + if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Backspace) + backspace_pressed = true; + else if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Backspace) + backspace_pressed = false; + if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::V && event.key.control) append_text(sf::Clipboard::getString()); - } + if(event.type == sf::Event::TextEntered) + onTextEntered(event.text.unicode); } void SearchBar::update() { sf::Int32 elapsed_time = time_since_search_update.getElapsedTime().asMilliseconds(); int timeout = text_autosearch_delay; - if(backspace_seq_count == 1) + if(backspace_pressed) timeout = 750; if(updated_search && elapsed_time >= timeout) { updated_search = false; @@ -125,7 +130,7 @@ namespace QuickMedia { draw_logo = false; } - float font_height = text.getLocalBounds().height + 12.0f; + float font_height = text.getCharacterSize() + 7.0f; float rect_height = std::floor(font_height + background_margin_vertical * 2.0f); float offset_x = padding_horizontal; @@ -177,11 +182,10 @@ namespace QuickMedia { } updated_search = true; updated_autocomplete = true; - ++backspace_seq_count; time_since_search_update.restart(); } } else if(codepoint == 13) { // Return - backspace_seq_count = 0; + backspace_pressed = false; if(onTextSubmitCallback) { auto u8 = text.getString().toUtf8(); std::string *u8_str = (std::string*)&u8; @@ -205,7 +209,7 @@ namespace QuickMedia { needs_update = true; updated_search = false; updated_autocomplete = false; - backspace_seq_count = 0; + backspace_pressed = false; } void SearchBar::append_text(const std::string &text_to_add) { @@ -231,7 +235,7 @@ namespace QuickMedia { updated_search = true; updated_autocomplete = true; time_since_search_update.restart(); - backspace_seq_count = 0; + backspace_pressed = false; if(str[str.getSize() - 1] == '\n') needs_update = true; } -- cgit v1.2.3