aboutsummaryrefslogtreecommitdiff
path: root/src/gui/Entry.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/Entry.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/Entry.cpp')
-rw-r--r--src/gui/Entry.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/gui/Entry.cpp b/src/gui/Entry.cpp
index a8a521b..e853bc8 100644
--- a/src/gui/Entry.cpp
+++ b/src/gui/Entry.cpp
@@ -9,11 +9,12 @@
#include <optional>
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;
static const float border_scale = 0.0015f;
+ static const float caret_width_scale = 0.001f;
Entry::Entry(mgl::Font *font, const char *text, float max_width) : text("", *font), max_width(max_width) {
this->text.set_color(get_theme().text_color);
@@ -41,17 +42,20 @@ namespace gsr {
void Entry::draw(mgl::Window &window, mgl::vec2f offset) {
const mgl::vec2f draw_pos = position + offset;
+ const int padding_top = padding_top_scale * get_theme().window_height;
+ const int padding_left = padding_left_scale * get_theme().window_height;
+
mgl::Rectangle background(get_size());
background.set_position(draw_pos.floor());
background.set_color(selected ? mgl::Color(0, 0, 0, 255) : mgl::Color(0, 0, 0, 120));
window.draw(background);
if(selected) {
- const int border_size = border_scale * gsr::get_theme().window_height;
+ const int border_size = border_scale * get_theme().window_height;
draw_rectangle_outline(window, draw_pos.floor(), get_size().floor(), get_theme().tint_color, border_size);
- const int caret_width = 2;
- mgl::Rectangle caret({caret_width, text.get_bounds().size.y});
+ const int caret_width = std::max(1.0f, caret_width_scale * get_theme().window_height);
+ mgl::Rectangle caret({(float)caret_width, text.get_bounds().size.y});
caret.set_position((draw_pos + mgl::vec2f(padding_left + caret_offset_x, padding_top)).floor());
caret.set_color(mgl::Color(255, 255, 255));
window.draw(caret);
@@ -62,6 +66,8 @@ namespace gsr {
}
mgl::vec2f Entry::get_size() {
+ const int padding_top = padding_top_scale * get_theme().window_height;
+ const int padding_bottom = padding_bottom_scale * get_theme().window_height;
return { max_width, text.get_bounds().size.y + padding_top + padding_bottom };
}