aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SearchBar.cpp14
1 files changed, 12 insertions, 2 deletions
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);