From b145d957e3809fd6c2d814c34c58234ade983bb0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 8 Sep 2024 17:07:22 +0200 Subject: More --- src/gui/Button.cpp | 6 +- src/gui/ComboBox.cpp | 28 ++++++---- src/gui/CustomRendererWidget.cpp | 4 ++ src/gui/List.cpp | 20 ++++--- src/gui/ScrollablePage.cpp | 1 + src/gui/SettingsPage.cpp | 115 +++++++++++++++++++++++---------------- src/gui/Subsection.cpp | 60 ++++++++++++++++++++ 7 files changed, 167 insertions(+), 67 deletions(-) create mode 100644 src/gui/Subsection.cpp (limited to 'src/gui') diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp index 0cf5bee..bccf7b0 100644 --- a/src/gui/Button.cpp +++ b/src/gui/Button.cpp @@ -48,8 +48,10 @@ namespace gsr { window.draw(text); const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(window.get_mouse_position().to_vec2f()) && !has_parent_with_selected_child_widget(); - if(mouse_inside) - draw_rectangle_outline(window, draw_pos, item_size, get_theme().tint_color, std::max(1.0f, border_scale * get_theme().window_height)); + if(mouse_inside) { + const mgl::Color outline_color = (bg_color == get_theme().tint_color) ? mgl::Color(255, 255, 255) : get_theme().tint_color; + draw_rectangle_outline(window, draw_pos, item_size, outline_color, std::max(1.0f, border_scale * get_theme().window_height)); + } } mgl::vec2f Button::get_size() { diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp index b344c4e..760ddae 100644 --- a/src/gui/ComboBox.cpp +++ b/src/gui/ComboBox.cpp @@ -22,6 +22,9 @@ namespace gsr { if(!visible) return true; + if(items.empty()) + return true; + 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; @@ -73,9 +76,6 @@ namespace gsr { update_if_dirty(); - if(items.empty()) - return; - 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; @@ -106,15 +106,17 @@ namespace gsr { const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(window.get_mouse_position().to_vec2f()) && !has_parent_with_selected_child_widget(); mgl::vec2f pos = draw_pos + mgl::vec2f(padding_left, padding_top); - Item &item = items[selected_item]; - item.text.set_position(pos.floor()); - if(show_dropdown || 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; - draw_rectangle_outline(window, pos - mgl::vec2f(padding_left, padding_top), item_size.floor(), border_color, border_size); + if(selected_item < items.size()) { + Item &selected_item_widget = items[selected_item]; + selected_item_widget.text.set_position(pos.floor()); + if(show_dropdown || 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; + draw_rectangle_outline(window, pos - mgl::vec2f(padding_left, padding_top), item_size.floor(), border_color, border_size); + } + window.draw(selected_item_widget.text); + pos.y += selected_item_widget.text.get_bounds().size.y + padding_top + padding_bottom; } - window.draw(item.text); - pos.y += item.text.get_bounds().size.y + padding_top + padding_bottom; for(size_t i = 0; i < items.size(); ++i) { Item &item = items[i]; @@ -185,6 +187,10 @@ namespace gsr { max_size.x = std::max(max_size.x, bounds.x + padding_left + padding_right); max_size.y += bounds.y + padding_top + padding_bottom; } + + if(max_size.x <= 0.001f) + max_size.x = 50.0f; + max_size.x += padding_left + get_dropdown_arrow_height(); dirty = false; } diff --git a/src/gui/CustomRendererWidget.cpp b/src/gui/CustomRendererWidget.cpp index 98b7caf..cfb113b 100644 --- a/src/gui/CustomRendererWidget.cpp +++ b/src/gui/CustomRendererWidget.cpp @@ -38,4 +38,8 @@ namespace gsr { return size; } + + void CustomRendererWidget::set_size(mgl::vec2f size) { + this->size = size; + } } \ No newline at end of file diff --git a/src/gui/List.cpp b/src/gui/List.cpp index 849329f..81f0e80 100644 --- a/src/gui/List.cpp +++ b/src/gui/List.cpp @@ -52,6 +52,9 @@ namespace gsr { if(!widget->visible) continue; + if(i > 0) + draw_pos.y += spacing; + const auto widget_size = widget->get_size(); // TODO: Do this parent widget alignment for horizontal alignment and for other types of widget alignment // and other widgets. @@ -67,8 +70,6 @@ namespace gsr { if(widget.get() != selected_widget) widget->draw(window, mgl::vec2f(0.0f, 0.0f)); draw_pos.y += widget_size.y; - if(widget_size.y > 0.001f && i + 1 < widgets.size()) - draw_pos.y += spacing; } break; } @@ -78,6 +79,9 @@ namespace gsr { if(!widget->visible) continue; + if(i > 0) + draw_pos.x += spacing; + const auto widget_size = widget->get_size(); if(content_alignment == Alignment::CENTER) offset.y = floor(size.y * 0.5f - widget_size.y * 0.5f); @@ -88,8 +92,6 @@ namespace gsr { if(widget.get() != selected_widget) widget->draw(window, mgl::vec2f(0.0f, 0.0f)); draw_pos.x += widget_size.x; - if(widget_size.x > 0.001f && i + 1 < widgets.size()) - draw_pos.x += spacing; } break; } @@ -146,11 +148,12 @@ namespace gsr { if(!widget->visible) continue; + if(i > 0) + size.y += spacing; + const auto widget_size = widget->get_size(); size.x = std::max(size.x, widget_size.x); size.y += widget_size.y; - if(widget_size.y > 0.001f && i + 1 < widgets.size()) - size.y += spacing; } break; } @@ -160,10 +163,11 @@ namespace gsr { if(!widget->visible) continue; + if(i > 0) + size.x += spacing; + const auto widget_size = widget->get_size(); size.x += widget_size.x; - if(widget_size.x > 0.001f && i + 1 < widgets.size()) - size.x += spacing; size.y = std::max(size.y, widget_size.y); } break; diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp index a791d75..7e15edf 100644 --- a/src/gui/ScrollablePage.cpp +++ b/src/gui/ScrollablePage.cpp @@ -140,6 +140,7 @@ namespace gsr { } void ScrollablePage::add_widget(std::unique_ptr widget) { + widget->parent_widget = this; widgets.push_back(std::move(widget)); } diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index 259df6c..12d1d99 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -3,8 +3,10 @@ #include "../../include/gui/Label.hpp" #include "../../include/gui/PageStack.hpp" #include "../../include/gui/FileChooser.hpp" +#include "../../include/gui/Subsection.hpp" #include "../../include/Theme.hpp" #include "../../include/GsrInfo.hpp" +#include "../../include/Utils.hpp" #include #include @@ -61,9 +63,9 @@ namespace gsr { return record_area_box; } - std::unique_ptr SettingsPage::create_record_area(const GsrInfo &gsr_info) { + std::unique_ptr SettingsPage::create_record_area(const GsrInfo &gsr_info) { auto record_area_list = std::make_unique(List::Orientation::VERTICAL); - record_area_list->add_widget(std::make_unique