diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index 19d8b4a2d..bf7535e9c 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -96,10 +96,15 @@ \li The "tabs" subcategory will show a tab bar. behaviour is same as normal ribbon, only looks are different. Orientation of tabs (up or down) is automatically inferred from on-screen position - \note Ribbon widgets are of spawn type (\ ... \) and may contain icon-buttons or buttons as children. - \note Property PROP_SQUARE can be set to tell the engine if the ribbon's contents are rectangular or not (this will - affect the type of highlighting used) + \note Ribbon widgets are of spawn type (\ ... \) and may contain icon-buttons or buttons + as children. + \note Property PROP_SQUARE can be set to tell the engine if the ribbon's contents are rectangular or not + (this will affect the type of highlighting used) \note All elements within a ribbon must have an 'ID' property + \note Text-only ribbons (e.g. tabs) can have their elements dynamically added at runtime, too. Just add + no children to the ribbon in the XML file, and add them at runtime through the method for this. + Dynamic contents creation for other types RibbonWidget is currently NOT implemented because we had + no need for it. It can be added as needed. \n \subsection widget2 WTYPE_SPINNER diff --git a/src/guiengine/widgets/ribbon_widget.cpp b/src/guiengine/widgets/ribbon_widget.cpp index ca958cc63..14d4eddf0 100644 --- a/src/guiengine/widgets/ribbon_widget.cpp +++ b/src/guiengine/widgets/ribbon_widget.cpp @@ -248,6 +248,18 @@ void RibbonWidget::add() } // ----------------------------------------------------------------------------- + +void RibbonWidget::addTextChild(const wchar_t* text, const std::string id) +{ + ButtonWidget* item = new ButtonWidget(); + item->m_text = text; + item->m_properties[PROP_ID] = id; + + m_children.push_back(item); +} + +// ----------------------------------------------------------------------------- + void RibbonWidget::select(std::string item, const int mousePlayerID) { const int subbuttons_amount = m_children.size(); diff --git a/src/guiengine/widgets/ribbon_widget.hpp b/src/guiengine/widgets/ribbon_widget.hpp index 3c3fd5bb9..9465904e2 100644 --- a/src/guiengine/widgets/ribbon_widget.hpp +++ b/src/guiengine/widgets/ribbon_widget.hpp @@ -118,6 +118,12 @@ namespace GUIEngine /** Returns the ID of the item, or -1 if not found */ int findItemNamed(const char* internalName); + + /** \brief dynamically (at runtime) add a text item to this ribbon + * \precondition this must be called before RibbonWidget::add, while the widget is not yet displayed + * \precondition only valid for ribbons that take text-only contents (e.g. tab bars) + */ + void addTextChild(const wchar_t* text, const std::string id); }; } diff --git a/src/states_screens/arenas_screen.cpp b/src/states_screens/arenas_screen.cpp index 9415a1bf1..29dfa542b 100644 --- a/src/states_screens/arenas_screen.cpp +++ b/src/states_screens/arenas_screen.cpp @@ -51,19 +51,14 @@ ArenasScreen::ArenasScreen() : Screen("arenas.stkgui") const int group_amount = groups.size(); for (int n=0; nm_text = groups[n].c_str(); // FIXME: i18n ? - item->m_properties[PROP_ID] = groups[n]; - tabs->m_children.push_back(item); + //FIXME: group name not translated + tabs->addTextChild( stringw(groups[n].c_str()).c_str(), groups[n]); } if (group_amount > 1) { - ButtonWidget* item = new ButtonWidget(); - //I18N: name of the tab that will show tracks from all groups - item->m_text = _("All"); - item->m_properties[PROP_ID] = ALL_ARENA_GROUPS_ID; - tabs->m_children.push_back(item); + //I18N: name of the tab that will show arenas from all groups + tabs->addTextChild( _("All") , ALL_ARENA_GROUPS_ID); } } // ArenasScreen diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 4bb3bc965..d5035100e 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -713,7 +713,6 @@ KartSelectionScreen::KartSelectionScreen() : Screen("karts.stkgui") m_player_confirmed = false; // Dynamically add tabs - // FIXME: it's not very well documented that RibbonWidgets can have dynamically generated contents RibbonWidget* tabs = this->getWidget("kartgroups"); assert( tabs != NULL ); @@ -724,19 +723,14 @@ KartSelectionScreen::KartSelectionScreen() : Screen("karts.stkgui") const int group_amount = groups.size(); for (int n=0; nm_text = groups[n].c_str(); // FIXME: i18n ? - item->m_properties[PROP_ID] = groups[n]; - tabs->m_children.push_back(item); + //FIXME: group name not translated + tabs->addTextChild( stringw(groups[n].c_str()).c_str() , groups[n]); } if (group_amount > 1) { - ButtonWidget* item = new ButtonWidget(); //I18N: name of the tab that will show tracks from all groups - item->m_text = _("All"); - item->m_properties[PROP_ID] = ALL_KART_GROUPS_ID; - tabs->m_children.push_back(item); + tabs->addTextChild( _("All") , ALL_KART_GROUPS_ID); } } diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index bb2f5216b..c054a54fc 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -41,7 +41,6 @@ DEFINE_SCREEN_SINGLETON( TracksScreen ); TracksScreen::TracksScreen() : Screen("tracks.stkgui") { // Dynamically add tabs - // FIXME: it's not very well documented that RibbonWidgets can have dynamically generated contents RibbonWidget* tabs = this->getWidget("trackgroups"); assert( tabs != NULL ); @@ -52,19 +51,14 @@ TracksScreen::TracksScreen() : Screen("tracks.stkgui") const int group_amount = groups.size(); for (int n=0; nm_text = groups[n].c_str(); // FIXME: i18n ? - item->m_properties[PROP_ID] = groups[n]; - tabs->m_children.push_back(item); + // FIXME: group name is not translated + tabs->addTextChild( stringw(groups[n].c_str()).c_str(), groups[n] ); } if (group_amount > 1) { - ButtonWidget* item = new ButtonWidget(); //I18N: name of the tab that will show tracks from all groups - item->m_text = _("All"); - item->m_properties[PROP_ID] = ALL_TRACK_GROUPS_ID; - tabs->m_children.push_back(item); + tabs->addTextChild(_("All"), ALL_TRACK_GROUPS_ID ); } }