diff --git a/changelog b/changelog index 9260d607bc2..a7a5982432c 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,8 @@ Version 1.5.11+svn: * Miscellaneous and bug fixes: * Removed last binaryWML references by making the save_index gzip compressed. (We can still receive binaryWML via the network.) + * User interface: + * Listbox columns have the same width again Version 1.5.11: * Campaigns: diff --git a/players_changelog b/players_changelog index 5eb284b2fed..d2e74105740 100644 --- a/players_changelog +++ b/players_changelog @@ -6,6 +6,8 @@ Version 1.5.11+svn: * Language and translations * updated translations: Chinese (Simplified), Czech, French, Polish, Portuguese (Brazil), Spanish, Turkish. + * User interface + * Listbox columns have the same width again. Version 1.5.11: * Graphics diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 90ad091147d..1cfbf7456af 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -44,6 +44,15 @@ void tlistbox::add_row(const string_map& item) assert(generator_); generator_->create_item( -1, list_builder_, item, callback_list_item_clicked); + + tgrid& grid = generator_->get_item(get_item_count() - 1); + twindow* window = get_window(); + assert(window); + + if(get_item_count() == 1) { + init_linked_size_widets(*window, grid.begin(), grid.end()); + } + add_linked_size_widgets(*window, grid.begin(), grid.end()); } void tlistbox::add_row( @@ -52,6 +61,15 @@ void tlistbox::add_row( assert(generator_); generator_->create_item( -1, list_builder_, data, callback_list_item_clicked); + + tgrid& grid = generator_->get_item(get_item_count() - 1); + twindow* window = get_window(); + assert(window); + + if(get_item_count() == 1) { + init_linked_size_widets(*window, grid.begin(), grid.end()); + } + add_linked_size_widgets(*window, grid.begin(), grid.end()); } unsigned tlistbox::get_item_count() const @@ -190,6 +208,48 @@ void tlistbox::handle_key_right_arrow(SDLMod modifier, bool& handled) } } +void tlistbox::init_linked_size_widets(twindow& window, + const tgrid::iterator& begin, const tgrid::iterator& end) +{ + for(tgrid::iterator itor = begin; itor != end; ++itor) { + + assert(*itor); + + // Add to list. + if(!itor->id().empty()) { + window.init_linked_size_group(itor->id(), true, false); + } + + // Recurse though the children. + tcontainer_* container = dynamic_cast(*itor); + if(container) { + init_linked_size_widets(window, + container->begin(), container->end()); + } + } +} + +void tlistbox::add_linked_size_widgets(twindow& window, + const tgrid::iterator& begin, const tgrid::iterator& end) +{ + for(tgrid::iterator itor = begin; itor != end; ++itor) { + + assert(*itor); + + // Add to list. + if(!itor->id().empty()) { + window.add_linked_widget(itor->id(), *itor); + } + + // Recurse though the children. + tcontainer_* container = dynamic_cast(*itor); + if(container) { + add_linked_size_widgets(window, + container->begin(), container->end()); + } + } +} + namespace { /** diff --git a/src/gui/widgets/listbox.hpp b/src/gui/widgets/listbox.hpp index fb0529f924e..86d524c8782 100644 --- a/src/gui/widgets/listbox.hpp +++ b/src/gui/widgets/listbox.hpp @@ -153,6 +153,49 @@ protected: private: + /** + * @todo A listbox must have the following config parameters in the + * instanciation: + * - fixed row height? + * - fixed column width? + * and if so the following ways to set them + * - fixed depending on header ids + * - fixed depending on footer ids + * - fixed depending on first row ids + * - fixed depending on list (the user has to enter a list of ids) + * + * For now it's always fixed width depending on the first row. + */ + + /** + * Initializes the linked size list. + * + * The routine goes from begin to end through the widgets and if the widget + * has an id it's used to initialize the linked size list of the parent + * window. If the widget is a container all it's children are also + * initialized. + * + * @param window The parent window. + * @param begin Begin iterator. + * @param end End iterator. + */ + void init_linked_size_widets(twindow& window, + const tgrid::iterator& begin, const tgrid::iterator& end); + + /** + * Adds widgets to the linked size list. + * + * The routine goes from begin to end through the widgets and if the widget + * has an id it's added to the linked size list of the parent window. If + * the widget is a container all it's children are also added. + * + * @param window The parent window. + * @param begin Begin iterator. + * @param end End iterator. + */ + void add_linked_size_widgets(twindow& window, + const tgrid::iterator& begin, const tgrid::iterator& end); + /** * Finishes the building initialization of the widget. *