From c01391c12399081eb3c418142c59885f76011145 Mon Sep 17 00:00:00 2001 From: that Date: Thu, 9 Jul 2015 00:19:58 +0200 Subject: gui: allow listbox to be used as menu and as read-only list Also enable string insertion for list items. Example how to make a menu item: 255 If no element and no actions on any items exist, the list is read only and no item selection is possible. Change-Id: Ib2668a982df2514484d44faa0396dd17550f39f3 --- gui/listbox.cpp | 23 +++++++++++++++++------ gui/objects.hpp | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gui/listbox.cpp b/gui/listbox.cpp index a60769979..4c9a68ac8 100644 --- a/gui/listbox.cpp +++ b/gui/listbox.cpp @@ -58,6 +58,8 @@ GUIListBox::GUIListBox(xml_node<>* node) : GUIScrollList(node) // Get the currently selected value for the list DataManager::GetValue(mVariable, currentValue); } + else + allowSelection = false; // allows using listbox as a read-only list // Get the data for the list child = FindNode(node, "listitem"); @@ -66,15 +68,21 @@ GUIListBox::GUIListBox(xml_node<>* node) : GUIScrollList(node) ListData data; attr = child->first_attribute("name"); - if (!attr) return; - data.displayName = attr->value(); - - data.variableValue = child->value(); + if (!attr) + continue; + data.displayName = gui_parse_text(attr->value()); + data.variableValue = gui_parse_text(child->value()); if (child->value() == currentValue) { data.selected = 1; } else { data.selected = 0; } + data.action = NULL; + xml_node<>* action = child->first_node("action"); + if (action) { + data.action = new GUIAction(action); + allowSelection = true; + } mList.push_back(data); @@ -157,9 +165,12 @@ void GUIListBox::NotifySelect(size_t item_selected) mList.at(i).selected = 0; } if (item_selected < mList.size()) { - mList.at(item_selected).selected = 1; - string str = mList.at(item_selected).variableValue; + ListData& data = mList.at(item_selected); + data.selected = 1; + string str = data.variableValue; // [check] should this set currentValue instead? DataManager::SetValue(mVariable, str); + if (data.action) + data.action->doActions(); } mUpdate = 1; } diff --git a/gui/objects.hpp b/gui/objects.hpp index be1f9734f..f8569d6ea 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -634,6 +634,7 @@ protected: std::string displayName; std::string variableValue; unsigned int selected; + GUIAction* action; }; protected: -- cgit v1.2.3