From b709805cfac4d1fe1bfe28e497a3e48e224372a8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Aug 2024 20:32:59 +0200 Subject: Move settings ui to SettingsPage class, show different widgets for different settings page, show different widgets depending on combobox selections --- src/gui/ComboBox.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/gui/ComboBox.cpp') 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; } } -- cgit v1.2.3