From 0a64acc3d68fecf5e7f23c6b0a013272f9288af8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 5 Mar 2022 07:45:14 +0100 Subject: Make ui behavior nicer with spacing_scale less than 1.0 --- src/SearchBar.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/SearchBar.cpp') diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 4ec1056..2393823 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -15,7 +15,7 @@ namespace QuickMedia { return (int)v; } - static const float background_margin_horizontal = floor(15.0f * get_config().scale); + static const float background_margin_horizontal = floor(5.0f * get_config().scale + 10.0f * get_config().spacing_scale); static const float padding_top_default = floor(10.0f * get_config().scale * get_config().spacing_scale); 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); @@ -68,20 +68,22 @@ namespace QuickMedia { background.draw(window); + const int caret_offset_y = character_size * 0.4f; + const bool show_placeholder = text.get_string().empty(); if(type == SearchBarType::Password && !show_placeholder) { std::string masked_str(text.get_string().size(), '*'); mgl::Text masked_text(std::move(masked_str), *text.get_font()); masked_text.set_position(text.get_position()); window.draw(masked_text); - caret.set_position(masked_text.get_position() + mgl::vec2f(masked_text.get_bounds().size.x, 0.0f).floor() + mgl::vec2f(0.0f, character_size * 0.4f)); + caret.set_position(masked_text.get_position() + mgl::vec2f(masked_text.get_bounds().size.x, 0.0f).floor() + mgl::vec2f(0.0f, caret_offset_y)); } else { if(show_placeholder) { window.draw(placeholder_text); - caret.set_position(placeholder_text.get_position() + mgl::vec2f(-caret.get_size().x, character_size * 0.4f)); + caret.set_position(placeholder_text.get_position() + mgl::vec2f(-caret.get_size().x, caret_offset_y)); } else { window.draw(text); - caret.set_position(text.get_position() + mgl::vec2f(text.get_bounds().size.x, 0.0f).floor() + mgl::vec2f(0.0f, character_size * 0.4f)); + caret.set_position(text.get_position() + mgl::vec2f(text.get_bounds().size.x, 0.0f).floor() + mgl::vec2f(0.0f, caret_offset_y)); } } @@ -165,6 +167,8 @@ namespace QuickMedia { float font_height = character_size + 7.0f; float rect_height = floor(font_height + background_margin_vertical * 2.0f); + const int x_pad = padding_x * get_config().scale * get_config().spacing_scale; + float offset_x; if(draw_logo) { float one_line_height = floor(character_size + 8.0f + background_margin_vertical * 2.0f); @@ -172,13 +176,13 @@ namespace QuickMedia { mgl::vec2f texture_size_f(texture_size.x, texture_size.y); mgl::vec2f new_size = wrap_to_size(texture_size_f, mgl::vec2f(200.0f, one_line_height)); plugin_logo_sprite.set_scale(get_ratio(texture_size_f, new_size)); - plugin_logo_sprite.set_position(mgl::vec2f(pos.x + padding_x, pos.y + padding_top + rect_height * 0.5f - plugin_logo_sprite.get_texture()->get_size().y * plugin_logo_sprite.get_scale().y * 0.5f)); - offset_x = padding_x + new_size.x + floor(10.0f * get_config().spacing_scale); + plugin_logo_sprite.set_position(vec2f_floor(pos.x + x_pad, pos.y + padding_top + rect_height * 0.5f - plugin_logo_sprite.get_texture()->get_size().y * plugin_logo_sprite.get_scale().y * 0.5f)); + offset_x = x_pad + new_size.x + floor(10.0f * get_config().spacing_scale); } else { - offset_x = padding_x; + offset_x = x_pad; } - const float width = floor(size.x - offset_x - padding_x); + const float width = floor(size.x - offset_x - x_pad); background.set_size(mgl::vec2f(width, rect_height)); shade.set_size(mgl::vec2f(size.x, padding_top + rect_height + padding_bottom)); -- cgit v1.2.3