aboutsummaryrefslogtreecommitdiff
path: root/src/gui/Button.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-06 08:59:38 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-06 08:59:38 +0200
commitb229b060add5f66bd5532698c4a790285095e98a (patch)
treeb93a1993370b263245c1ead33dd6985429b0eba9 /src/gui/Button.cpp
parentb3f5a53ecec329538de7ee18f9f5201c4a37f323 (diff)
Make sure all sizes are scaled by window size, make sure all elements are visible for very low resolutions and text doesn't get too small
Diffstat (limited to 'src/gui/Button.cpp')
-rw-r--r--src/gui/Button.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp
index a0dd8e9..1849737 100644
--- a/src/gui/Button.cpp
+++ b/src/gui/Button.cpp
@@ -7,10 +7,10 @@
#include <mglpp/system/FloatRect.hpp>
namespace gsr {
- static const float padding_top = 10.0f;
- static const float padding_bottom = 10.0f;
- static const float padding_left = 10.0f;
- static const float padding_right = 10.0f;
+ static const float padding_top_scale = 0.004629f;
+ static const float padding_bottom_scale = 0.004629f;
+ static const float padding_left_scale = 0.007f;
+ static const float padding_right_scale = 0.007f;
Button::Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color) : size(size), bg_color(bg_color), text(text, *font) {
@@ -40,10 +40,15 @@ namespace gsr {
const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(window.get_mouse_position().to_vec2f());
if(mouse_inside)
- draw_rectangle_outline(window, draw_pos, item_size, gsr::get_theme().tint_color, border_scale * gsr::get_theme().window_height);
+ draw_rectangle_outline(window, draw_pos, item_size, get_theme().tint_color, border_scale * get_theme().window_height);
}
mgl::vec2f Button::get_size() {
+ const int padding_top = padding_top_scale * get_theme().window_height;
+ const int padding_bottom = padding_bottom_scale * get_theme().window_height;
+ const int padding_left = padding_left_scale * get_theme().window_height;
+ const int padding_right = padding_right_scale * get_theme().window_height;
+
const mgl::vec2f text_bounds = text.get_bounds().size;
mgl::vec2f s = size;
if(s.x < 0.0001f)