diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-07 00:21:32 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-07 00:21:35 +0200 |
commit | a3e479d5b289166ff651fac4ff046656cf78cda0 (patch) | |
tree | 2ba345228acfe45acf9863bb122e163ed38db7db /src/gui/ScrollablePage.cpp | |
parent | b229b060add5f66bd5532698c4a790285095e98a (diff) |
Add radio button with simple/advanced view, add widget visibility
Diffstat (limited to 'src/gui/ScrollablePage.cpp')
-rw-r--r-- | src/gui/ScrollablePage.cpp | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp index 73b445e..2c1143a 100644 --- a/src/gui/ScrollablePage.cpp +++ b/src/gui/ScrollablePage.cpp @@ -8,8 +8,14 @@ namespace gsr { ScrollablePage::ScrollablePage(mgl::vec2f size) : size(size) {} bool ScrollablePage::on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) { + if(!visible) + return true; + + const int margin_top = margin_top_scale * get_theme().window_height; + const int margin_left = margin_left_scale * get_theme().window_height; + const mgl::vec2f draw_pos = position + offset; - offset = draw_pos + mgl::vec2f(0.0f, get_border_size(window)).floor(); + offset = draw_pos + mgl::vec2f(margin_left, get_border_size() + margin_top).floor(); Widget *selected_widget = selected_child_widget; if(selected_widget) { @@ -29,29 +35,37 @@ namespace gsr { } void ScrollablePage::draw(mgl::Window &window, mgl::vec2f offset) { - const mgl::vec2f draw_pos = position + offset; - offset = draw_pos + mgl::vec2f(0.0f, get_border_size(window)).floor(); - Widget *selected_widget = selected_child_widget; + if(!visible) + return; - mgl_scissor prev_scissor; - mgl_window_get_scissor(window.internal_window(), &prev_scissor); + const int margin_top = margin_top_scale * get_theme().window_height; + const int margin_left = margin_left_scale * get_theme().window_height; - mgl_scissor new_scissor = { - mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y}, - mgl_vec2i{(int)size.x, (int)size.y} - }; - mgl_window_set_scissor(window.internal_window(), &new_scissor); + const mgl::vec2f draw_pos = position + offset; + offset = draw_pos + mgl::vec2f(margin_left, get_border_size() + margin_top).floor(); mgl::Rectangle background(size.floor()); background.set_position(draw_pos); background.set_color(get_theme().scrollable_page_bg_color); window.draw(background); - mgl::Rectangle border(mgl::vec2f(size.x, get_border_size(window)).floor()); + mgl::Rectangle border(mgl::vec2f(size.x, get_border_size()).floor()); border.set_position(draw_pos); border.set_color(get_theme().tint_color); window.draw(border); + mgl_scissor prev_scissor; + mgl_window_get_scissor(window.internal_window(), &prev_scissor); + + const mgl::vec2f content_size = get_size(); + mgl_scissor new_scissor = { + mgl_vec2i{(int)offset.x, (int)offset.y}, + mgl_vec2i{(int)content_size.x, (int)content_size.y} + }; + mgl_window_set_scissor(window.internal_window(), &new_scissor); + + Widget *selected_widget = selected_child_widget; + for(auto &widget : widgets) { if(widget.get() != selected_widget) widget->draw(window, offset); @@ -63,7 +77,25 @@ namespace gsr { mgl_window_set_scissor(window.internal_window(), &prev_scissor); } - float ScrollablePage::get_border_size(mgl::Window &window) const { - return window.get_size().y * 0.004f; + mgl::vec2f ScrollablePage::get_size() { + if(!visible) + return {0.0f, 0.0f}; + + const int margin_top = margin_top_scale * get_theme().window_height; + const int margin_bottom = margin_bottom_scale * get_theme().window_height; + const int margin_left = margin_left_scale * get_theme().window_height; + const int margin_right = margin_right_scale * get_theme().window_height; + return size - mgl::vec2f(margin_left + margin_right, margin_top + margin_bottom + get_border_size()); + } + + void ScrollablePage::set_margins(float top, float bottom, float left, float right) { + margin_top_scale = top; + margin_bottom_scale = bottom; + margin_left_scale = left; + margin_right_scale = right; + } + + float ScrollablePage::get_border_size() const { + return 0.004f * get_theme().window_height; } }
\ No newline at end of file |