From 6208faf754b76a7c9a806220c97484ea2e9c0a2e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 14 Sep 2020 16:16:36 +0200 Subject: Add caret to search bar --- src/SearchBar.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index d96172a..803eaee 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -20,14 +20,14 @@ namespace QuickMedia { onAutocompleteRequestCallback(nullptr), text_autosearch_delay(0), autocomplete_search_delay(0), - text(placeholder, font, 18), + text(placeholder, font, 18), autocomplete_text("", font, 18), placeholder_str(placeholder), show_placeholder(true), updated_search(false), updated_autocomplete(false), draw_logo(false), - needs_update(false) + needs_update(true) { text.setFillColor(text_placeholder_color); autocomplete_text.setFillColor(text_placeholder_color); @@ -54,6 +54,12 @@ namespace QuickMedia { // TODO: Render starting from the character after text length window.draw(autocomplete_text); window.draw(text); + if(show_placeholder || text.getString().isEmpty()) + caret.setPosition(text.getPosition() - sf::Vector2f(2.0f, 0.0f)); + else + caret.setPosition(text.findCharacterPos(text.getString().getSize())); + + window.draw(caret); if(draw_logo) window.draw(plugin_logo_sprite); } @@ -105,6 +111,7 @@ namespace QuickMedia { background.setSize(sf::Vector2f(width, rect_height)); shade.setSize(sf::Vector2f(window_size.x, padding_vertical + rect_height + padding_vertical)); + caret.setSize(sf::Vector2f(2.0f, text.getLocalBounds().height + 12.0f)); background_shadow.setSize(sf::Vector2f(window_size.x, 5.0f)); background.setPosition(offset_x, padding_vertical); -- cgit v1.2.3