Add a horizontal listbox.
This commit is contained in:
parent
70e0ce4400
commit
9d04c8500f
12 changed files with 260 additions and 4 deletions
|
@ -9,6 +9,7 @@ Version 1.7.3+svn:
|
|||
* Updated translations: Russian
|
||||
* User interface:
|
||||
* Removed the hotkey to enable/disable mouse scrolling
|
||||
* Added a horizontal listbox
|
||||
* WML Engine:
|
||||
* Support for [show_if] inside [message]
|
||||
* Miscellaneous and bugfixes:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of a listbox
|
||||
### Definition of a (horizontal) listbox
|
||||
###
|
||||
###
|
||||
### NOTE a listbox has multiple scroll button options, these aren't all used
|
||||
|
@ -132,7 +132,7 @@
|
|||
|
||||
[listbox_definition]
|
||||
id = "default"
|
||||
description = "Testing version."
|
||||
description = "Default listbox."
|
||||
|
||||
{_GUI_RESOLUTION
|
||||
({GUI_TINY__RESOLUTION})
|
||||
|
@ -153,5 +153,28 @@
|
|||
|
||||
[/listbox_definition]
|
||||
|
||||
[horizontal_listbox_definition]
|
||||
id = "default"
|
||||
description = "Default horizontal listbox."
|
||||
|
||||
{_GUI_RESOLUTION
|
||||
({GUI_TINY__RESOLUTION})
|
||||
({GUI_TINY__FONT_SIZE__DEFAULT})
|
||||
()
|
||||
({GUI__FONT_COLOUR_ENABLED__DEFAULT})
|
||||
({GUI__FONT_COLOUR_DISABLED__DEFAULT})
|
||||
}
|
||||
|
||||
|
||||
{_GUI_RESOLUTION
|
||||
({GUI_NORMAL__RESOLUTION})
|
||||
({GUI_NORMAL__FONT_SIZE__DEFAULT})
|
||||
()
|
||||
({GUI__FONT_COLOUR_ENABLED__DEFAULT})
|
||||
({GUI__FONT_COLOUR_DISABLED__DEFAULT})
|
||||
}
|
||||
|
||||
[/horizontal_listbox_definition]
|
||||
|
||||
#undef _GUI_RESOLUTION
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ src/gui/auxiliary/window_builder/button.cpp
|
|||
src/gui/auxiliary/window_builder/control.cpp
|
||||
src/gui/auxiliary/window_builder.cpp
|
||||
src/gui/auxiliary/window_builder/helper.cpp
|
||||
src/gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||
src/gui/auxiliary/window_builder/horizontal_scrollbar.cpp
|
||||
src/gui/auxiliary/window_builder/image.cpp
|
||||
src/gui/auxiliary/window_builder/label.cpp
|
||||
|
|
|
@ -281,6 +281,7 @@ SET(wesnoth-main_SRC
|
|||
gui/auxiliary/window_builder/button.cpp
|
||||
gui/auxiliary/window_builder/control.cpp
|
||||
gui/auxiliary/window_builder/helper.cpp
|
||||
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||
gui/auxiliary/window_builder/horizontal_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/image.cpp
|
||||
gui/auxiliary/window_builder/label.cpp
|
||||
|
|
|
@ -102,6 +102,7 @@ wesnoth_source = \
|
|||
gui/auxiliary/window_builder/button.cpp \
|
||||
gui/auxiliary/window_builder/control.cpp \
|
||||
gui/auxiliary/window_builder/helper.cpp \
|
||||
gui/auxiliary/window_builder/horizontal_listbox.cpp \
|
||||
gui/auxiliary/window_builder/horizontal_scrollbar.cpp \
|
||||
gui/auxiliary/window_builder/image.cpp \
|
||||
gui/auxiliary/window_builder/label.cpp \
|
||||
|
|
|
@ -261,6 +261,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/window_builder/button.cpp
|
||||
gui/auxiliary/window_builder/control.cpp
|
||||
gui/auxiliary/window_builder/helper.cpp
|
||||
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||
gui/auxiliary/window_builder/horizontal_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/image.cpp
|
||||
gui/auxiliary/window_builder/label.cpp
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/auxiliary/window_builder/button.hpp"
|
||||
#include "gui/auxiliary/window_builder/helper.hpp"
|
||||
#include "gui/auxiliary/window_builder/horizontal_listbox.hpp"
|
||||
#include "gui/auxiliary/window_builder/horizontal_scrollbar.hpp"
|
||||
#include "gui/auxiliary/window_builder/image.hpp"
|
||||
#include "gui/auxiliary/window_builder/label.hpp"
|
||||
|
@ -67,6 +68,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
using namespace gui2::implementation;
|
||||
|
||||
TRY(button);
|
||||
TRY(horizontal_listbox);
|
||||
TRY(horizontal_scrollbar);
|
||||
TRY(image);
|
||||
TRY(label);
|
||||
|
|
151
src/gui/auxiliary/window_builder/horizontal_listbox.cpp
Normal file
151
src/gui/auxiliary/window_builder/horizontal_listbox.cpp
Normal file
|
@ -0,0 +1,151 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2009 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/auxiliary/window_builder/horizontal_listbox.hpp"
|
||||
|
||||
#include "foreach.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/auxiliary/window_builder/helper.hpp"
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
tbuilder_horizontal_listbox::tbuilder_horizontal_listbox(const config& cfg)
|
||||
: tbuilder_control(cfg)
|
||||
, vertical_scrollbar_mode(
|
||||
get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
|
||||
, horizontal_scrollbar_mode(
|
||||
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
|
||||
, list_builder(NULL)
|
||||
, list_data()
|
||||
{
|
||||
const config &l = cfg.child("list_definition");
|
||||
|
||||
VALIDATE(l, _("No list defined."));
|
||||
list_builder = new tbuilder_grid(l);
|
||||
assert(list_builder);
|
||||
VALIDATE(list_builder->rows == 1
|
||||
, _("A 'list_definition' should contain one row."));
|
||||
|
||||
const config &data = cfg.child("list_data");
|
||||
if (!data) return;
|
||||
|
||||
foreach(const config &row, data.child_range("row")) {
|
||||
unsigned col = 0;
|
||||
|
||||
foreach(const config &c, row.child_range("column")) {
|
||||
list_data.push_back(string_map());
|
||||
foreach (const config::attribute &i, c.attribute_range()) {
|
||||
list_data.back()[i.first] = i.second;
|
||||
}
|
||||
++col;
|
||||
}
|
||||
|
||||
VALIDATE(col == list_builder->cols, _("'list_data' must have "
|
||||
"the same number of columns as the 'list_definition'."));
|
||||
}
|
||||
}
|
||||
|
||||
twidget* tbuilder_horizontal_listbox::build() const
|
||||
{
|
||||
tlistbox *widget = new tlistbox(
|
||||
true, true, tgenerator_::horizontal_list, true);
|
||||
|
||||
init_control(widget);
|
||||
|
||||
widget->set_list_builder(list_builder); // FIXME in finalize???
|
||||
|
||||
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
|
||||
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
|
||||
|
||||
DBG_GUI_G << "Window builder: placed listbox '"
|
||||
<< id << "' with defintion '"
|
||||
<< definition << "'.\n";
|
||||
|
||||
boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
|
||||
boost::dynamic_pointer_cast
|
||||
<const tlistbox_definition::tresolution>(widget->config());
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
||||
widget->finalize(NULL, NULL, list_data);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
/*WIKI_MACRO
|
||||
* @start_macro = horizontal_listbox_description
|
||||
*
|
||||
* A horizontal listbox is a control that holds several items of the
|
||||
* same type. Normally the items in a listbox are ordered in rows,
|
||||
* this version orders them vertically instead.
|
||||
* @end_macro
|
||||
*/
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWidgetInstanceWML
|
||||
* @order = 2_horizontal_listbox
|
||||
*
|
||||
* == Horizontal listbox ==
|
||||
*
|
||||
* @macro = horizontal_listbox_description
|
||||
*
|
||||
* List with the horizontal listbox specific variables:
|
||||
* @start_table = config
|
||||
* vertical_scrollbar_mode (scrollbar_mode = auto | initial_auto)
|
||||
* Determines whether or not to show the
|
||||
* scrollbar. The default of initial_auto
|
||||
* is used when --new-widgets is used.
|
||||
* In the future the default will be
|
||||
* auto.
|
||||
* horizontal_scrollbar_mode (scrollbar_mode = auto | initial_auto)
|
||||
* Determines whether or not to show the
|
||||
* scrollbar. The default of initial_auto
|
||||
* is used when --new-widgets is used.
|
||||
* In the future the default will be
|
||||
* initial_auto.
|
||||
*
|
||||
* list_definition (section) This defines how a listbox item
|
||||
* looks. It must contain the grid
|
||||
* definition for 1 row of the list.
|
||||
*
|
||||
* list_data(section = []) A grid alike section which stores the
|
||||
* initial data for the listbox. Every row
|
||||
* must have the same number of columns as
|
||||
* the 'list_definition'.
|
||||
*
|
||||
* @end_table
|
||||
*
|
||||
* In order to force widgets to be the same size inside a horizontal listbox,
|
||||
* the widgets need to be inside a linked_group.
|
||||
*
|
||||
* Inside the list section there are only the following widgets allowed
|
||||
* * grid (to nest)
|
||||
* * selectable widgets which are
|
||||
* ** toggle_button
|
||||
* ** toggle_panel
|
||||
*
|
||||
*/
|
||||
|
53
src/gui/auxiliary/window_builder/horizontal_listbox.hpp
Normal file
53
src/gui/auxiliary/window_builder/horizontal_listbox.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2009 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_AUXILIARY_WINDOW_BUILDER_HORIZONTAL_LISTBOX_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WINDOW_BUILDER_HORIZONTAL_LISTBOX_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder/control.hpp"
|
||||
|
||||
#include "gui/widgets/scrollbar_container.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
struct tbuilder_horizontal_listbox
|
||||
: public tbuilder_control
|
||||
{
|
||||
tbuilder_horizontal_listbox(const config& cfg);
|
||||
|
||||
twidget* build () const;
|
||||
|
||||
tscrollbar_container::tscrollbar_mode
|
||||
vertical_scrollbar_mode,
|
||||
horizontal_scrollbar_mode;
|
||||
|
||||
tbuilder_grid_ptr list_builder;
|
||||
|
||||
/**
|
||||
* Listbox data.
|
||||
*
|
||||
* Contains a vector with the data to set in every cell, it's used to
|
||||
* serialize the data in the config, so the config is no longer required.
|
||||
*/
|
||||
std::vector<string_map> list_data;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
@ -12,7 +12,6 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUI_WIDGETS_LISTBOX_HPP_INCLUDED
|
||||
#define GUI_WIDGETS_LISTBOX_HPP_INCLUDED
|
||||
|
||||
|
@ -23,6 +22,7 @@ namespace gui2 {
|
|||
|
||||
namespace implementation {
|
||||
struct tbuilder_listbox;
|
||||
struct tbuilder_horizontal_listbox;
|
||||
}
|
||||
|
||||
/** The listbox class. */
|
||||
|
@ -30,6 +30,7 @@ class tlistbox
|
|||
: public tscrollbar_container
|
||||
{
|
||||
friend struct implementation::tbuilder_listbox;
|
||||
friend struct implementation::tbuilder_horizontal_listbox;
|
||||
friend class tdebug_layout_graph;
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -190,6 +190,7 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
* @start_table = widget_overview
|
||||
* Button @macro = button_description
|
||||
* Image @macro = image_description
|
||||
* Horizontal_listbox @macro = horizontal_listbox_description
|
||||
* Horizontal_scrollbar @macro = horizontal_scrollbar_description
|
||||
* Label @macro = label_description
|
||||
* Listbox @macro = listbox_description
|
||||
|
@ -262,6 +263,8 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
|
||||
/***** Control definitions *****/
|
||||
load_definitions<tbutton_definition>("button", cfg);
|
||||
load_definitions<thorizontal_listbox_definition>(
|
||||
"horizontal_listbox", cfg);
|
||||
load_definitions<thorizontal_scrollbar_definition>("horizontal_scrollbar", cfg);
|
||||
load_definitions<timage_definition>("image", cfg);
|
||||
load_definitions<tlabel_definition>("label", cfg);
|
||||
|
@ -759,11 +762,20 @@ tlistbox_definition::tresolution::tresolution(const config& cfg) :
|
|||
*
|
||||
*/
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWidgetDefinitionWML
|
||||
* @order = 1_horizonal_listbox
|
||||
*
|
||||
* == Horizontal listbox ==
|
||||
*
|
||||
* @macro = horizontal_listbox_description
|
||||
*
|
||||
* The definition of a horizontal listbox is the same as for a normal listbox.
|
||||
*/
|
||||
// Note the order should be the same as the enum tstate is listbox.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled")));
|
||||
|
||||
|
||||
const config &child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
|
|
|
@ -170,6 +170,15 @@ struct tbutton_definition : public tcontrol_definition
|
|||
|
||||
};
|
||||
|
||||
/*
|
||||
* A horizontal listbox definition is the same as a normal listbox.
|
||||
* The big difference between them is the difference in the instanciation,
|
||||
* which looks different on the WML side, still uses the normal listbox widget
|
||||
* class.
|
||||
*/
|
||||
struct tlistbox_definition;
|
||||
typedef tlistbox_definition thorizontal_listbox_definition;
|
||||
|
||||
struct thorizontal_scrollbar_definition : public tcontrol_definition
|
||||
{
|
||||
thorizontal_scrollbar_definition(const config& cfg);
|
||||
|
|
Loading…
Add table
Reference in a new issue