15 #ifdef GUI2_EXPERIMENTAL_LISTBOX
17 #define GETTEXT_DOMAIN "wesnoth-lib"
24 #include "gui/widgets/detail/register.hpp"
31 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
32 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
37 #ifdef GUI2_EXPERIMENTAL_LISTBOX
41 tlist::tlist(
const bool has_minimum,
42 const bool has_maximum,
49 , list_builder_(list_builder)
58 connect_signal<event::LEFT_BUTTON_DOWN>(
59 std::bind(&tlist::signal_handler_left_button_down,
this, _2),
62 connect_signal<event::SDL_KEY_DOWN>(std::bind(
63 &tlist::signal_handler_sdl_key_down,
this, _2, _3, _5, _6));
65 connect_signal<event::SDL_KEY_DOWN>(
67 &tlist::signal_handler_sdl_key_down,
this, _2, _3, _5, _6),
73 std::map<std::string, string_map>
data;
75 data.insert(std::make_pair(
"", item));
80 tlist::add_row(
const std::map<std::string /* widget id */, string_map>& data,
84 tgrid&
grid = generator_->create_item(index, list_builder_, data,
nullptr);
86 tselectable_* selectable
87 = find_widget<tselectable_>(&
grid,
"_toggle",
false,
false);
90 dynamic_cast<twidget&
>(*selectable)
93 &tlist::signal_handler_pre_child_left_button_click,
102 dynamic_cast<twidget&
>(*selectable)
104 std::bind(&tlist::signal_handler_left_button_click,
111 dynamic_cast<twidget&
>(*selectable)
113 std::bind(&tlist::signal_handler_left_button_click,
121 void tlist::append_rows(
const std::vector<string_map>&
items)
129 void tlist::remove_row(
const unsigned row,
unsigned count)
133 if(row >= get_item_count()) {
137 if(!count || count > get_item_count()) {
138 count = get_item_count();
141 unsigned height_reduced = 0;
143 if(generator_->item(row).get_visible() != tvisible::invisible) {
144 height_reduced += generator_->item(row).get_height();
146 generator_->delete_item(row);
149 if(height_reduced != 0) {
161 unsigned tlist::get_item_count()
const
164 return generator_->get_item_count();
167 void tlist::set_row_active(
const unsigned row,
const bool active)
170 generator_->item(row).set_active(active);
173 void tlist::set_row_shown(
const unsigned row,
const bool shown)
177 twindow* window = get_window();
180 const int selected_row = get_selected_row();
182 bool resize_needed =
false;
186 generator_->set_item_shown(row, shown);
187 generator_->place(generator_->get_origin(),
188 generator_->calculate_best_size());
193 window->invalidate_layout();
199 if(selected_row != get_selected_row()) {
204 void tlist::set_row_shown(
const std::vector<bool>& shown)
207 assert(shown.size() == get_item_count());
209 twindow* window = get_window();
212 const int selected_row = get_selected_row();
214 bool resize_needed =
false;
218 for(
size_t i = 0;
i < shown.size(); ++
i) {
219 generator_->set_item_shown(
i, shown[
i]);
221 generator_->place(generator_->get_origin(),
222 generator_->calculate_best_size());
227 window->invalidate_layout();
233 if(selected_row != get_selected_row()) {
238 const tgrid* tlist::get_row_grid(
const unsigned row)
const
242 return &generator_->item(row);
245 tgrid* tlist::get_row_grid(
const unsigned row)
248 return &generator_->item(row);
251 bool tlist::select_row(
const unsigned row,
const bool select)
255 generator_->select_item(row, select);
260 int tlist::get_selected_row()
const
264 return generator_->get_selected_item();
267 void tlist::place(
const tpoint& origin,
const tpoint&
size)
280 const int selected_item = generator_->get_selected_item();
281 if(selected_item != -1) {
294 void tlist::resize_content(
295 const int width_modification
296 ,
const int height_modification)
299 <<
" width_modification " << width_modification
300 <<
" height_modification " << height_modification
303 if(content_resize_request(width_modification, height_modification)) {
306 tpoint size = content_grid()->get_size();
307 size.x += width_modification;
308 size.y += height_modification;
311 content_grid()->set_size(size);
316 if(width_modification < 0 || height_modification < 0) {
328 init_grid(cast<tlistbox_definition::tresolution>(
config()).grid);
337 tgrid*
g = find_widget<tgrid>(&
grid(),
"_header_grid",
false,
false);
341 g = find_widget<tgrid>(&
grid(),
"_footer_grid",
false,
false);
345 g = find_widget<tgrid>(&
grid(),
"_vertical_scrollbar_grid",
false,
false);
349 g = find_widget<tgrid>(&
grid(),
"_horizontal_scrollbar_grid",
false,
false);
354 bool tlist::get_active()
const
356 return state_ != DISABLED;
359 unsigned tlist::get_state()
const
364 void tlist::layout_children(
const bool force)
366 if(need_layout_ || force) {
372 need_layout_ =
false;
377 void tlist::set_self_active(
const bool active)
392 assert(get_window());
393 get_window()->keyboard_capture(
this);
396 void tlist::signal_handler_pre_child_left_button_click(
397 tgrid* grid,
const event::tevent event,
bool& handled,
bool& halt)
399 DBG_GUI_E << LOG_HEADER <<
' ' <<
event <<
".\n";
404 for(
size_t i = 0;
i < generator_->get_item_count(); ++
i) {
405 if(&generator_->item(
i) ==
grid) {
419 if(generator_->is_selected(
i)) {
429 void tlist::signal_handler_left_button_click(tgrid* grid,
432 DBG_GUI_E << LOG_HEADER <<
' ' <<
event <<
".\n";
437 for(
size_t i = 0;
i < generator_->get_item_count(); ++
i) {
438 if(&generator_->item(
i) ==
grid) {
439 generator_->select_item(
i);
445 void tlist::signal_handler_sdl_key_down(
const event::tevent event,
450 DBG_GUI_E << LOG_HEADER <<
' ' <<
event <<
".\n";
458 generator_->handle_key_up_arrow(modifier, handled);
461 generator_->handle_key_down_arrow(modifier, handled);
464 generator_->handle_key_left_arrow(modifier, handled);
467 generator_->handle_key_right_arrow(modifier, handled);
Define the common log macros for the gui toolkit.
void set_single_child(tgrid &grid, twidget *widget)
Sets the single child in a grid.
boost::intrusive_ptr< const tbuilder_grid > tbuilder_grid_const_ptr
GLuint GLuint GLsizei GLenum type
void clear(const std::string &key)
tplacement
Determines how the items are placed.
const std::vector< std::string > items
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
A left mouse button click event for a widget.
A class inherited from ttext_box that displays its input as stars.
friend class tinvalidate_layout_blocker
Send by a widget to notify others its contents or state are modified.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
tevent
The event send to the dispatcher.
void init()
Initializes the gui subsystems.
GLuint GLuint GLsizei count
std::map< std::string, t_string > string_map
static tgenerator_ * build(const bool has_minimum, const bool has_maximum, const tplacement placement, const bool select)
Create a new generator.
GLenum GLenum GLvoid * row
A config object defines a single node in a WML file, with access to child nodes.
GLsizei const GLcharARB ** string