aboutsummaryrefslogtreecommitdiff
path: root/src/gui/CheckBox.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-07 00:21:32 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-07 00:21:35 +0200
commita3e479d5b289166ff651fac4ff046656cf78cda0 (patch)
tree2ba345228acfe45acf9863bb122e163ed38db7db /src/gui/CheckBox.cpp
parentb229b060add5f66bd5532698c4a790285095e98a (diff)
Add radio button with simple/advanced view, add widget visibility
Diffstat (limited to 'src/gui/CheckBox.cpp')
-rw-r--r--src/gui/CheckBox.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gui/CheckBox.cpp b/src/gui/CheckBox.cpp
index b337d5f..94e5f9e 100644
--- a/src/gui/CheckBox.cpp
+++ b/src/gui/CheckBox.cpp
@@ -16,6 +16,9 @@ namespace gsr {
}
bool CheckBox::on_event(mgl::Event &event, mgl::Window&, mgl::vec2f offset) {
+ if(!visible)
+ return true;
+
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)
@@ -25,6 +28,9 @@ namespace gsr {
}
void CheckBox::draw(mgl::Window &window, mgl::vec2f offset) {
+ if(!visible)
+ return;
+
const mgl::vec2f draw_pos = position + offset;
const mgl::vec2f checkbox_size = get_checkbox_size();
@@ -45,7 +51,7 @@ namespace gsr {
text.set_position((draw_pos + mgl::vec2f(checkbox_size.x + spacing_scale * get_theme().window_height, checkbox_size.y * 0.5f - text_bounds.y * 0.5f)).floor());
window.draw(text);
- const bool mouse_inside = mgl::FloatRect(draw_pos, get_size()).contains(window.get_mouse_position().to_vec2f());
+ const bool mouse_inside = mgl::FloatRect(draw_pos, get_size()).contains(window.get_mouse_position().to_vec2f()) && !has_parent_with_selected_child_widget();
if(mouse_inside) {
const int border_size = std::max(1.0f, border_scale * get_theme().window_height);
const mgl::Color border_color = get_theme().tint_color;
@@ -54,6 +60,9 @@ namespace gsr {
}
mgl::vec2f CheckBox::get_size() {
+ if(!visible)
+ return {0.0f, 0.0f};
+
mgl::vec2f size = text.get_bounds().size;
const mgl::vec2f checkbox_size = get_checkbox_size();
size.x += checkbox_size.x + spacing_scale * get_theme().window_height;