aboutsummaryrefslogtreecommitdiff
path: root/src/gui/CheckBox.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/CheckBox.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/CheckBox.cpp')
-rw-r--r--src/gui/CheckBox.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/gui/CheckBox.cpp b/src/gui/CheckBox.cpp
index db2764d..b337d5f 100644
--- a/src/gui/CheckBox.cpp
+++ b/src/gui/CheckBox.cpp
@@ -18,11 +18,8 @@ namespace gsr {
bool CheckBox::on_event(mgl::Event &event, mgl::Window&, mgl::vec2f offset) {
if(event.type == mgl::Event::MouseButtonPressed && event.mouse_button.button == mgl::Mouse::Left) {
const bool clicked_inside = mgl::FloatRect(position + offset, get_size()).contains({ (float)event.mouse_button.x, (float)event.mouse_button.y });
- if(clicked_inside) {
+ if(clicked_inside)
checked = !checked;
- if(on_click)
- on_click();
- }
}
return true;
}
@@ -40,7 +37,7 @@ namespace gsr {
const float side_margin = checked_margin_scale * get_theme().window_height;
mgl::Rectangle background(get_checkbox_size() - mgl::vec2f(side_margin, side_margin).floor() * 2.0f);
background.set_position(draw_pos.floor() + mgl::vec2f(side_margin, side_margin).floor());
- background.set_color(gsr::get_theme().tint_color);
+ background.set_color(get_theme().tint_color);
window.draw(background);
}
@@ -50,8 +47,8 @@ namespace gsr {
const bool mouse_inside = mgl::FloatRect(draw_pos, get_size()).contains(window.get_mouse_position().to_vec2f());
if(mouse_inside) {
- const int border_size = border_scale * gsr::get_theme().window_height;
- const mgl::Color border_color = gsr::get_theme().tint_color;
+ const int border_size = std::max(1.0f, border_scale * get_theme().window_height);
+ const mgl::Color border_color = get_theme().tint_color;
draw_rectangle_outline(window, draw_pos, checkbox_size, border_color, border_size);
}
}
@@ -68,4 +65,8 @@ namespace gsr {
const mgl::vec2f text_bounds = text.get_bounds().size;
return mgl::vec2f(text_bounds.y, text_bounds.y).floor();
}
+
+ bool CheckBox::is_checked() const {
+ return checked;
+ }
} \ No newline at end of file