#pragma once #include "RoundedRectangle.hpp" #include #include #include #include #include namespace sf { class Font; class RenderWindow; class Event; class Shader; } namespace QuickMedia { using TextUpdateCallback = std::function; using TextSubmitCallback = std::function; using TextBeginTypingCallback = std::function; class SearchBar { public: SearchBar(sf::Texture *plugin_logo, sf::Shader *rounded_rectangle_shader, const std::string &placeholder, bool input_masked = false); void draw(sf::RenderWindow &window, sf::Vector2f size, bool draw_background); void on_event(sf::Event &event); void update(); void onWindowResize(const sf::Vector2f &window_size); void clear(); void set_text(const std::string &text, bool update_search = true); void append_text(const std::string &text_to_add); void set_position(sf::Vector2f pos); void set_editable(bool editable); bool is_editable() const; float getBottom() const; float getBottomWithoutShadow() const; std::string get_text() const; bool is_empty() const; TextUpdateCallback onTextUpdateCallback; TextSubmitCallback onTextSubmitCallback; TextBeginTypingCallback onTextBeginTypingCallback; int text_autosearch_delay; bool caret_visible; float padding_top = 0.0f; float padding_bottom = 0.0f; float padding_x = 10.0f; private: void onTextEntered(sf::Uint32 codepoint); private: sf::Text text; RoundedRectangle background; sf::RectangleShape shade; sf::RectangleShape caret; sf::Sprite plugin_logo_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; sf::Vector2f pos; sf::Clock time_since_search_update; sf::Vector2f prev_size; bool editable = true; }; }