From 29d3f495e3b3be801cbb8c8dbd3f7250ec22415a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 1 Mar 2022 11:15:53 +0100 Subject: SearchBar refactor. Dont show search icon if searchbar is not used for search --- include/SearchBar.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index 19cd121..514b33e 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -20,9 +20,15 @@ namespace QuickMedia { using TextSubmitCallback = std::function; using TextBeginTypingCallback = std::function; + enum class SearchBarType { + Search, + Text, + Password + }; + class SearchBar { public: - SearchBar(mgl::Texture *plugin_logo, mgl::Shader *rounded_rectangle_shader, const std::string &placeholder, bool input_masked = false); + SearchBar(mgl::Texture *plugin_logo, mgl::Shader *rounded_rectangle_shader, const std::string &placeholder, SearchBarType type); void draw(mgl::Window &window, mgl::vec2f size, bool draw_background); void on_event(mgl::Window &window, mgl::Event &event); void update(); @@ -37,7 +43,7 @@ namespace QuickMedia { float getBottom() const; float getBottomWithoutShadow() const; - std::string get_text() const; + const std::string& get_text() const; bool is_empty() const; TextUpdateCallback onTextUpdateCallback; @@ -53,17 +59,15 @@ namespace QuickMedia { void onTextEntered(const mgl::Event::TextEvent &text_event); private: mgl::Text text; + mgl::Text placeholder_text; RoundedRectangle background; mgl::Rectangle shade; mgl::Rectangle caret; mgl::Sprite plugin_logo_sprite; mgl::Sprite search_icon_sprite; - std::string placeholder_str; - bool show_placeholder; bool updated_search; bool draw_logo; bool needs_update; - bool input_masked; bool typing; bool backspace_pressed; bool mouse_left_inside; @@ -71,5 +75,6 @@ namespace QuickMedia { mgl::Clock time_since_search_update; mgl::vec2f prev_size; bool editable = true; + SearchBarType type; }; } \ No newline at end of file -- cgit v1.2.3