aboutsummaryrefslogtreecommitdiff
path: root/src/SearchBar.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-09 00:08:53 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-09 00:08:53 +0100
commit4af367373f6f92b0fc1d79b2871fa942e1eb86fa (patch)
treedcf40ea78a8973069e3cbd5889c7a379a217b453 /src/SearchBar.cpp
parentf8748d14ea11d6d53ad46aee2832180daf05fb77 (diff)
Matrix: update user display name/avatar when updated in /sync; fix backspace search delay
Diffstat (limited to 'src/SearchBar.cpp')
-rw-r--r--src/SearchBar.cpp22
1 files changed, 13 insertions, 9 deletions
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;
}