diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-03-01 05:21:19 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-03-01 05:21:19 +0100 |
commit | ed3e39886aaaa119b62c87f21b6c5ea4bf360a93 (patch) | |
tree | 3afb05c972c5e5694ce085eca0ac89db5782af8c | |
parent | 608a24a42836dd1b5dfa43c1607b41170242d864 (diff) |
Add search icon
-rw-r--r-- | images/search_icon.png | bin | 0 -> 1021 bytes | |||
-rw-r--r-- | include/SearchBar.hpp | 1 | ||||
-rw-r--r-- | src/SearchBar.cpp | 14 |
3 files changed, 13 insertions, 2 deletions
diff --git a/images/search_icon.png b/images/search_icon.png Binary files differnew file mode 100644 index 0000000..c2579ce --- /dev/null +++ b/images/search_icon.png diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index 9170f7a..19cd121 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -57,6 +57,7 @@ namespace QuickMedia { 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; diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 71e662e..070b763 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -22,6 +22,7 @@ namespace QuickMedia { static const float padding_bottom_default = floor(15.0f * get_config().scale * get_config().spacing_scale); static const float background_margin_vertical = floor(4.0f * get_config().scale * get_config().spacing_scale); static const int character_size = get_config().search.font_size * get_config().scale * get_config().font_scale; + static const int search_icon_padding_x = 10 * get_config().scale; SearchBar::SearchBar(mgl::Texture *plugin_logo, mgl::Shader *rounded_rectangle_shader, const std::string &placeholder, bool input_masked) : onTextUpdateCallback(nullptr), @@ -31,6 +32,7 @@ namespace QuickMedia { caret_visible(true), text(placeholder, *FontLoader::get_font(FontLoader::FontType::LATIN, character_size)), background(mgl::vec2f(1.0f, 1.0f), 10.0f * get_config().scale, get_theme().selected_color, rounded_rectangle_shader), + search_icon_sprite(TextureLoader::get_texture("images/search_icon.png")), placeholder_str(placeholder), show_placeholder(true), updated_search(false), @@ -49,6 +51,7 @@ namespace QuickMedia { shade.set_color(get_theme().shade_color); if(plugin_logo && plugin_logo->is_valid()) plugin_logo_sprite.set_texture(plugin_logo); + search_icon_sprite.set_color(get_theme().text_color); } void SearchBar::draw(mgl::Window &window, mgl::vec2f size, bool draw_background) { @@ -86,6 +89,8 @@ namespace QuickMedia { if(draw_logo) window.draw(plugin_logo_sprite); + + window.draw(search_icon_sprite); } void SearchBar::on_event(mgl::Window &window, mgl::Event &event) { @@ -182,8 +187,13 @@ namespace QuickMedia { background.set_position(mgl::vec2f(pos.x + offset_x, pos.y + padding_top)); shade.set_position(pos); - mgl::vec2f font_position(floor(pos.x + offset_x + background_margin_horizontal), floor(pos.y + padding_top + background_margin_vertical - character_size * 0.3f)); + mgl::vec2f font_position(floor(pos.x + offset_x + background_margin_horizontal + search_icon_padding_x + search_icon_padding_x), floor(pos.y + padding_top + background_margin_vertical - character_size * 0.3f)); text.set_position(font_position); + + mgl::vec2f texture_size = search_icon_sprite.get_texture()->get_size().to_vec2f(); + mgl::vec2f new_size = wrap_to_size_y(texture_size, character_size); + search_icon_sprite.set_scale(get_ratio(texture_size, new_size)); + search_icon_sprite.set_position(background.get_position() + mgl::vec2f(search_icon_padding_x, background.get_size().y * 0.5f - new_size.y * 0.5f).floor()); } void SearchBar::onTextEntered(const mgl::Event::TextEvent &text_event) { @@ -253,7 +263,7 @@ namespace QuickMedia { if(show_placeholder) { show_placeholder = false; text.set_string(""); - text.set_color(mgl::Color(255, 255, 255, 255)); + text.set_color(get_theme().text_color); } text.append_string(text_to_add); |