aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-07 20:32:59 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-07 20:32:59 +0200
commitb709805cfac4d1fe1bfe28e497a3e48e224372a8 (patch)
tree82f4bb638805dd58017d933fafd2143eb8019637 /src/gui
parent2ea32e11093a4d057338c02abbff4807446ff8de (diff)
Move settings ui to SettingsPage class, show different widgets for different settings page, show different widgets depending on combobox selections
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/ComboBox.cpp15
-rw-r--r--src/gui/List.cpp6
-rw-r--r--src/gui/RadioButton.cpp10
-rw-r--r--src/gui/ScrollablePage.cpp9
4 files changed, 32 insertions, 8 deletions
diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp
index 0b232f2..6aff979 100644
--- a/src/gui/ComboBox.cpp
+++ b/src/gui/ComboBox.cpp
@@ -39,9 +39,14 @@ namespace gsr {
Item &item = items[i];
const mgl::FloatRect text_bounds = item.text.get_bounds();
if(mgl::FloatRect(pos - mgl::vec2f(padding_left, padding_top), item_size).contains(mouse_pos)) {
+ const size_t prev_selected_item = selected_item;
selected_item = i;
show_dropdown = false;
remove_widget_as_selected_in_parent();
+
+ if(selected_item != prev_selected_item && on_selection_changed)
+ on_selection_changed(item.text.get_string(), item.id);
+
return false;
}
pos.y += text_bounds.size.y + padding_top + padding_bottom;
@@ -141,10 +146,16 @@ namespace gsr {
dirty = true;
}
- void ComboBox::set_selected_item(const std::string &id) {
+ void ComboBox::set_selected_item(const std::string &id, bool trigger_event) {
for(size_t i = 0; i < items.size(); ++i) {
- if(items[i].id == id) {
+ auto &item = items[i];
+ if(item.id == id) {
+ const size_t prev_selected_item = selected_item;
selected_item = i;
+
+ if(trigger_event && selected_item != prev_selected_item && on_selection_changed)
+ on_selection_changed(item.text.get_string(), item.id);
+
break;
}
}
diff --git a/src/gui/List.cpp b/src/gui/List.cpp
index 5e5a172..039842d 100644
--- a/src/gui/List.cpp
+++ b/src/gui/List.cpp
@@ -67,7 +67,7 @@ namespace gsr {
// TODO: Handle start/end alignment
const mgl::vec2f size = get_size();
- const mgl::vec2f parent_size = parent_widget ? parent_widget->get_size() : mgl::vec2f(0.0f, 0.0f);
+ const mgl::vec2f parent_inner_size = parent_widget ? parent_widget->get_inner_size() : mgl::vec2f(0.0f, 0.0f);
const mgl::vec2f spacing = (spacing_scale * get_theme().window_height).floor();
switch(orientation) {
@@ -80,8 +80,8 @@ namespace gsr {
// TODO: Do this parent widget alignment for horizontal alignment and for other types of widget alignment
// and other widgets.
// Also take this widget alignment into consideration in get_size.
- if(widget->get_horizontal_alignment() == Widget::Alignment::CENTER && parent_size.x > 0.001f)
- offset.x = floor(parent_size.x * 0.5f - widget_size.x * 0.5f);
+ if(widget->get_horizontal_alignment() == Widget::Alignment::CENTER && parent_inner_size.x > 0.001f)
+ offset.x = floor(parent_inner_size.x * 0.5f - widget_size.x * 0.5f);
else if(content_alignment == Alignment::CENTER)
offset.x = floor(size.x * 0.5f - widget_size.x * 0.5f);
else
diff --git a/src/gui/RadioButton.cpp b/src/gui/RadioButton.cpp
index b3e9a4e..15b0989 100644
--- a/src/gui/RadioButton.cpp
+++ b/src/gui/RadioButton.cpp
@@ -121,10 +121,16 @@ namespace gsr {
dirty = true;
}
- void RadioButton::set_selected_item(const std::string &id) {
+ void RadioButton::set_selected_item(const std::string &id, bool trigger_event) {
for(size_t i = 0; i < items.size(); ++i) {
- if(items[i].id == id) {
+ auto &item = items[i];
+ if(item.id == id) {
+ const size_t prev_selected_item = selected_item;
selected_item = i;
+
+ if(trigger_event && selected_item != prev_selected_item && on_selection_changed)
+ on_selection_changed(item.text.get_string(), item.id);
+
break;
}
}
diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp
index 2c1143a..a0977ce 100644
--- a/src/gui/ScrollablePage.cpp
+++ b/src/gui/ScrollablePage.cpp
@@ -57,7 +57,7 @@ namespace gsr {
mgl_scissor prev_scissor;
mgl_window_get_scissor(window.internal_window(), &prev_scissor);
- const mgl::vec2f content_size = get_size();
+ const mgl::vec2f content_size = get_inner_size();
mgl_scissor new_scissor = {
mgl_vec2i{(int)offset.x, (int)offset.y},
mgl_vec2i{(int)content_size.x, (int)content_size.y}
@@ -81,6 +81,13 @@ namespace gsr {
if(!visible)
return {0.0f, 0.0f};
+ return size;
+ }
+
+ mgl::vec2f ScrollablePage::get_inner_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;