The Battle for Wesnoth  1.15.0-dev
listbox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "gui/widgets/listbox.hpp"
18 
19 #include "gettext.hpp"
22 #include "gui/core/log.hpp"
27 #include "gui/widgets/pane.hpp"
29 #include "gui/widgets/settings.hpp"
31 #include "gui/widgets/viewport.hpp"
33 #include "gui/widgets/window.hpp"
34 #include "sdl/rect.hpp"
35 #include "utils/functional.hpp"
36 
37 #include <boost/optional.hpp>
38 
39 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
40 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
41 
42 namespace gui2
43 {
44 // ------------ WIDGET -----------{
45 
46 REGISTER_WIDGET(listbox)
47 REGISTER_WIDGET3(listbox_definition, horizontal_listbox, nullptr)
48 REGISTER_WIDGET3(listbox_definition, grid_listbox, nullptr)
49 
50 listbox::listbox(const implementation::builder_styled_widget& builder,
51  const generator_base::placement placement,
52  builder_grid_ptr list_builder,
53  const bool has_minimum,
54  const bool has_maximum,
55  const bool select)
56  : scrollbar_container(builder, type())
57  , generator_(generator_base::build(has_minimum, has_maximum, placement, select))
58  , is_horizontal_(placement == generator_base::horizontal_list)
59  , list_builder_(list_builder)
60  , need_layout_(false)
61  , orders_()
62  , callback_order_change_()
63 {
64 }
65 
66 grid& listbox::add_row(const string_map& item, const int index)
67 {
68  assert(generator_);
69  grid& row = generator_->create_item(index, list_builder_, item, std::bind(&listbox::list_item_clicked, this, _1));
70 
71  resize_content(row);
72 
73  return row;
74 }
75 
76 grid& listbox::add_row(const std::map<std::string /* widget id */, string_map>& data, const int index)
77 {
78  assert(generator_);
79  grid& row = generator_->create_item(index, list_builder_, data, std::bind(&listbox::list_item_clicked, this, _1));
80 
81  resize_content(row);
82 
83  return row;
84 }
85 
86 void listbox::remove_row(const unsigned row, unsigned count)
87 {
88  assert(generator_);
89 
90  if(row >= get_item_count()) {
91  return;
92  }
93 
94  if(!count || count + row > get_item_count()) {
95  count = get_item_count() - row;
96  }
97 
98  int height_reduced = 0;
99  int width_reduced = 0;
100 
101  // TODO: Fix this for horizontal listboxes
102  // Note the we have to use content_grid_ and cannot use "_list_grid" which is what generator_ uses.
103  int row_pos_y = is_horizontal_ ? -1 : generator_->item(row).get_y() - content_grid_->get_y();
104  int row_pos_x = is_horizontal_ ? -1 : 0;
105 
106  for(; count; --count) {
108  if(is_horizontal_) {
109  width_reduced += generator_->item(row).get_width();
110  } else {
111  height_reduced += generator_->item(row).get_height();
112  }
113  }
114 
115  generator_->delete_item(row);
116  }
117 
118  if((height_reduced != 0 || width_reduced != 0) && get_item_count() != 0) {
119  resize_content(-width_reduced, -height_reduced, row_pos_x, row_pos_y);
120  } else {
122  }
123 }
124 
126 {
127  generator_->clear();
129 }
130 
131 unsigned listbox::get_item_count() const
132 {
133  assert(generator_);
134  return generator_->get_item_count();
135 }
136 
137 void listbox::set_row_active(const unsigned row, const bool active)
138 {
139  assert(generator_);
140  generator_->item(row).set_active(active);
141 }
142 
143 void listbox::set_row_shown(const unsigned row, const bool shown)
144 {
145  assert(generator_);
146 
147  window* window = get_window();
148  assert(window);
149 
150  const int selected_row = get_selected_row();
151 
152  bool resize_needed = false;
153 
154  // Local scope for invalidate_layout_blocker
155  {
156  window::invalidate_layout_blocker invalidate_layout_blocker(*window);
157 
158  generator_->set_item_shown(row, shown);
159 
160  point best_size = generator_->calculate_best_size();
161  generator_->place(generator_->get_origin(), {std::max(best_size.x, content_visible_area().w), best_size.y});
162 
163  resize_needed = !content_resize_request();
164  }
165 
166  if(resize_needed) {
167  window->invalidate_layout();
168  } else {
169  content_grid_->set_visible_rectangle(content_visible_area());
170  set_is_dirty(true);
171  }
172 
173  if(selected_row != get_selected_row()) {
174  fire(event::NOTIFY_MODIFIED, *this, nullptr);
175  }
176 }
177 
178 void listbox::set_row_shown(const boost::dynamic_bitset<>& shown)
179 {
180  assert(generator_);
181  assert(shown.size() == get_item_count());
182 
183  if(generator_->get_items_shown() == shown) {
184  LOG_GUI_G << LOG_HEADER << " returning early" << std::endl;
185  return;
186  }
187 
188  window* window = get_window();
189  assert(window);
190 
191  const int selected_row = get_selected_row();
192 
193  bool resize_needed = false;
194 
195  // Local scope for invalidate_layout_blocker
196  {
197  window::invalidate_layout_blocker invalidate_layout_blocker(*window);
198 
199  for(std::size_t i = 0; i < shown.size(); ++i) {
200  generator_->set_item_shown(i, shown[i]);
201  }
202 
203  point best_size = generator_->calculate_best_size();
204  generator_->place(generator_->get_origin(), {std::max(best_size.x, content_visible_area().w), best_size.y});
205 
206  resize_needed = !content_resize_request();
207  }
208 
209  if(resize_needed) {
210  window->invalidate_layout();
211  } else {
212  content_grid_->set_visible_rectangle(content_visible_area());
213  set_is_dirty(true);
214  }
215 
216  if(selected_row != get_selected_row()) {
217  fire(event::NOTIFY_MODIFIED, *this, nullptr);
218  }
219 }
220 
221 boost::dynamic_bitset<> listbox::get_rows_shown() const
222 {
223  return generator_->get_items_shown();
224 }
225 
227 {
228  for(std::size_t i = 0; i < get_item_count(); i++) {
229  if(generator_->get_item_shown(i)) {
230  return true;
231  }
232  }
233 
234  return false;
235 }
236 
237 const grid* listbox::get_row_grid(const unsigned row) const
238 {
239  assert(generator_);
240  // rename this function and can we return a reference??
241  return &generator_->item(row);
242 }
243 
244 grid* listbox::get_row_grid(const unsigned row)
245 {
246  assert(generator_);
247  return &generator_->item(row);
248 }
249 
250 bool listbox::select_row(const unsigned row, const bool select)
251 {
252  assert(generator_);
253 
254  unsigned int before = generator_->get_selected_item_count();
255  generator_->select_item(row, select);
256 
257  return before != generator_->get_selected_item_count();
258 }
259 
260 bool listbox::select_row_at(const unsigned row, const bool select)
261 {
262  assert(generator_);
263  return select_row(generator_->get_item_at_ordered(row), select);
264 }
265 
266 bool listbox::row_selected(const unsigned row)
267 {
268  assert(generator_);
269  return generator_->is_selected(row);
270 }
271 
273 {
274  assert(generator_);
275  return generator_->get_selected_item();
276 }
277 
279 {
280  assert(generator_);
281 
282  /** @todo Hack to capture the keyboard focus. */
283  get_window()->keyboard_capture(this);
284 
285  for(std::size_t i = 0; i < generator_->get_item_count(); ++i) {
286  if(generator_->item(i).has_widget(caller)) {
287  toggle_button* checkbox = dynamic_cast<toggle_button*>(&caller);
288 
289  if(checkbox != nullptr) {
290  generator_->select_item(i, checkbox->get_value_bool());
291  } else {
293  }
294 
295  // TODO: enable this code once toggle_panel::set_value dispatches
296  // NOTIFY_MODIFED events. See comment in said function for more details.
297 #if 0
298  selectable_item& selectable = dynamic_cast<selectable_item&>(caller);
299 
300  generator_->select_item(i, selectable.get_value_bool());
301 #endif
302 
303  fire(event::NOTIFY_MODIFIED, *this, nullptr);
304  break;
305  }
306  }
307 
308  const int selected_item = generator_->get_selected_item();
309  if(selected_item == -1) {
310  return;
311  }
312 
313  const SDL_Rect& visible = content_visible_area();
314  SDL_Rect rect = generator_->item(selected_item).get_rectangle();
315 
316  if(sdl::rects_overlap(visible, rect)) {
317  rect.x = visible.x;
318  rect.w = visible.w;
319 
320  show_content_rect(rect);
321  }
322 }
323 
324 void listbox::set_self_active(const bool /*active*/)
325 {
326  /* DO NOTHING */
327 }
328 
330 {
332  return true;
333  }
334 
335  if(get_size() == point()) {
336  return false;
337  }
338 
339  if(content_resize_request(true)) {
340  content_grid_->set_visible_rectangle(content_visible_area());
341  set_is_dirty(true);
342  return true;
343  }
344 
345  return false;
346 }
347 
348 void listbox::place(const point& origin, const point& size)
349 {
350  boost::optional<unsigned> vertical_scrollbar_position, horizontal_scrollbar_position;
351 
352  // Check if this is the first time placing the list box
353  if(get_origin() != point {-1, -1}) {
354  vertical_scrollbar_position = get_vertical_scrollbar_item_position();
355  horizontal_scrollbar_position = get_horizontal_scrollbar_item_position();
356  }
357 
358  // Inherited.
359  scrollbar_container::place(origin, size);
360 
361  const int selected_item = generator_->get_selected_item();
362  if(vertical_scrollbar_position && horizontal_scrollbar_position) {
363  LOG_GUI_L << LOG_HEADER << " restoring scroll position" << std::endl;
364 
365  set_vertical_scrollbar_item_position(*vertical_scrollbar_position);
366  set_horizontal_scrollbar_item_position(*horizontal_scrollbar_position);
367  } else if(selected_item != -1) {
368  LOG_GUI_L << LOG_HEADER << " making the initially selected item visible" << std::endl;
369 
370  const SDL_Rect& visible = content_visible_area();
371  SDL_Rect rect = generator_->item(selected_item).get_rectangle();
372 
373  rect.x = visible.x;
374  rect.w = visible.w;
375 
376  show_content_rect(rect);
377  }
378 }
379 
380 void listbox::resize_content(const int width_modification,
381  const int height_modification,
382  const int width_modification_pos,
383  const int height_modification_pos)
384 {
385  DBG_GUI_L << LOG_HEADER << " current size " << content_grid()->get_size() << " width_modification "
386  << width_modification << " height_modification " << height_modification << ".\n";
387 
389  width_modification, height_modification, width_modification_pos, height_modification_pos))
390  {
391  // Calculate new size.
393  size.x += width_modification;
394  size.y += height_modification;
395 
396  // Set new size.
397  content_grid()->set_size(size);
398 
399  // Set status.
400  need_layout_ = true;
401 
402  // If the content grows assume it "overwrites" the old content.
403  if(width_modification < 0 || height_modification < 0) {
404  set_is_dirty(true);
405  }
406 
407  DBG_GUI_L << LOG_HEADER << " succeeded.\n";
408  } else {
409  DBG_GUI_L << LOG_HEADER << " failed.\n";
410  }
411 }
412 
414 {
415  if(row.get_visible() == visibility::invisible) {
416  return;
417  }
418 
419  DBG_GUI_L << LOG_HEADER << " current size " << content_grid()->get_size() << " row size " << row.get_best_size()
420  << ".\n";
421 
422  const point content = content_grid()->get_size();
423  point size = row.get_best_size();
424 
425  if(size.x < content.x) {
426  size.x = 0;
427  } else {
428  size.x -= content.x;
429  }
430 
431  resize_content(size.x, size.y);
432 }
433 
435 {
436  layout_children(false);
437 }
438 
439 void listbox::child_populate_dirty_list(window& caller, const std::vector<widget*>& call_stack)
440 {
441  // Inherited.
443 
444  assert(generator_);
445  std::vector<widget*> child_call_stack = call_stack;
446  generator_->populate_dirty_list(caller, child_call_stack);
447 }
448 
450 {
451  // Get the size from the base class, then add any extra space for the header and footer.
453 
454  if(const grid* header = find_widget<const grid>(&get_grid(), "_header_grid", false, false)) {
455  result.y += header->get_best_size().y;
456  }
457 
458  if(const grid* footer = find_widget<const grid>(&get_grid(), "_footer_grid", false, false)) {
459  result.y += footer->get_best_size().y;
460  }
461 
462  return result;
463 }
464 
466 {
467  const SDL_Rect& visible = content_visible_area();
469 
470  // When scrolling make sure the new items are visible...
471  if(direction == KEY_VERTICAL) {
472  // ...but leave the horizontal scrollbar position.
473  rect.x = visible.x;
474  rect.w = visible.w;
475  } else {
476  // ...but leave the vertical scrollbar position.
477  rect.y = visible.y;
478  rect.h = visible.h;
479  }
480 
481  show_content_rect(rect);
482 
483  fire(event::NOTIFY_MODIFIED, *this, nullptr);
484 }
485 
486 void listbox::handle_key_up_arrow(SDL_Keymod modifier, bool& handled)
487 {
488  assert(generator_);
489 
490  generator_->handle_key_up_arrow(modifier, handled);
491 
492  if(handled) {
494  } else {
495  // Inherited.
496  scrollbar_container::handle_key_up_arrow(modifier, handled);
497  }
498 }
499 
500 void listbox::handle_key_down_arrow(SDL_Keymod modifier, bool& handled)
501 {
502  assert(generator_);
503 
504  generator_->handle_key_down_arrow(modifier, handled);
505 
506  if(handled) {
508  } else {
509  // Inherited.
510  scrollbar_container::handle_key_up_arrow(modifier, handled);
511  }
512 }
513 
514 void listbox::handle_key_left_arrow(SDL_Keymod modifier, bool& handled)
515 {
516  assert(generator_);
517 
518  generator_->handle_key_left_arrow(modifier, handled);
519 
520  // Inherited.
521  if(handled) {
523  } else {
525  }
526 }
527 
528 void listbox::handle_key_right_arrow(SDL_Keymod modifier, bool& handled)
529 {
530  assert(generator_);
531 
532  generator_->handle_key_right_arrow(modifier, handled);
533 
534  // Inherited.
535  if(handled) {
537  } else {
539  }
540 }
541 
543  builder_grid_const_ptr footer,
544  const std::vector<std::map<std::string, string_map>>& list_data)
545 {
546  // "Inherited."
548 
549  assert(generator_);
550 
551  if(header) {
552  swap_grid(&get_grid(), content_grid(), header->build(), "_header_grid");
553  }
554 
555  grid& p = find_widget<grid>(this, "_header_grid", false);
556 
557  for(unsigned i = 0, max = std::max(p.get_cols(), p.get_rows()); i < max; ++i) {
558  //
559  // TODO: I had to change this to case to a toggle_button in order to use a signal handler.
560  // Should probably look into a way to make it more general like it was before (used to be
561  // cast to selectable_item).
562  //
563  // - vultraz, 2017-08-23
564  //
565  if(toggle_button* selectable = find_widget<toggle_button>(&p, "sort_" + std::to_string(i), false, false)) {
566  // Register callback to sort the list.
567  connect_signal_notify_modified(*selectable, std::bind(&listbox::order_by_column, this, i, _1));
568 
569  if(orders_.size() < max) {
570  orders_.resize(max);
571  }
572 
573  orders_[i].first = selectable;
574  }
575  }
576 
577  if(footer) {
578  swap_grid(&get_grid(), content_grid(), footer->build(), "_footer_grid");
579  }
580 
581  generator_->create_items(-1, list_builder_, list_data, std::bind(&listbox::list_item_clicked, this, _1));
582  swap_grid(nullptr, content_grid(), generator_, "_list_grid");
583 }
584 
585 void listbox::order_by_column(unsigned column, widget& widget)
586 {
587  selectable_item& selectable = dynamic_cast<selectable_item&>(widget);
588  if(column >= orders_.size()) {
589  return;
590  }
591 
592  for(auto& pair : orders_) {
593  if(pair.first != nullptr && pair.first != &selectable) {
594  pair.first->set_value(SORT_NONE);
595  }
596  }
597 
598  SORT_ORDER order = static_cast<SORT_ORDER>(selectable.get_value());
599 
600  if(static_cast<unsigned int>(order) > orders_[column].second.size()) {
601  return;
602  }
603 
604  if(order == SORT_NONE) {
605  order_by(std::less<unsigned>());
606  } else {
607  order_by(orders_[column].second[order - 1]);
608  }
609 
610  if(callback_order_change_ != nullptr) {
611  callback_order_change_(column, order);
612  }
613 }
614 
616 {
617  generator_->set_order(func);
618 
619  set_is_dirty(true);
620  need_layout_ = true;
621 }
622 
623 void listbox::set_column_order(unsigned col, const generator_sort_array& func)
624 {
625  if(col >= orders_.size()) {
626  orders_.resize(col + 1);
627  }
628 
629  orders_[col].second = func;
630 }
631 
633 {
634  set_column_order(col, {{
635  [f](int lhs, int rhs) { return translation::icompare(f(lhs), f(rhs)) < 0; },
636  [f](int lhs, int rhs) { return translation::icompare(f(lhs), f(rhs)) > 0; }
637  }});
638 }
639 
640 void listbox::set_active_sorting_option(const order_pair& sort_by, const bool select_first)
641 {
642  // TODO: should this be moved to a public header_grid() getter function?
643  grid& header_grid = find_widget<grid>(this, "_header_grid", false);
644 
645  selectable_item& w = find_widget<selectable_item>(&header_grid, "sort_" + std::to_string(sort_by.first), false);
646 
647  // Set the sorting toggle widgets' value (in this case, its state) to the given sorting
648  // order. This is necessary since the widget's value is used to determine the order in
649  // @ref order_by_column in lieu of a direction being passed directly.
650  w.set_value(static_cast<int>(sort_by.second));
651 
652  order_by_column(sort_by.first, dynamic_cast<widget&>(w));
653 
654  if(select_first && generator_->get_item_count() > 0) {
655  select_row_at(0);
656  }
657 }
658 
660 {
661  for(unsigned int column = 0; column < orders_.size(); ++column) {
662  selectable_item* w = orders_[column].first;
663 
664  if(w && w->get_value() != SORT_NONE) {
665  return std::make_pair(column, static_cast<SORT_ORDER>(w->get_value()));
666  }
667  }
668 
669  return std::make_pair(-1, SORT_NONE);
670 }
671 
673 {
674  for(auto& pair : orders_) {
675  if(pair.first != nullptr) {
676  pair.first->set_value(SORT_NONE);
677  }
678  }
679 }
680 
681 void listbox::set_content_size(const point& origin, const point& size)
682 {
683  /** @todo This function needs more testing. */
684  assert(content_grid());
685 
686  const int best_height = content_grid()->get_best_size().y;
687  const point s(size.x, size.y < best_height ? size.y : best_height);
688 
689  content_grid()->place(origin, s);
690 }
691 
692 void listbox::layout_children(const bool force)
693 {
694  assert(content_grid());
695 
696  if(need_layout_ || force) {
698 
699  const SDL_Rect& visible = content_visible_area_;
700 
702 
703  need_layout_ = false;
704  set_is_dirty(true);
705  }
706 }
707 
708 // }---------- DEFINITION ---------{
709 
712 {
713  DBG_GUI_P << "Parsing listbox " << id << '\n';
714 
715  load_resolutions<resolution>(cfg);
716 }
717 
718 /*WIKI
719  * @page = GUIWidgetDefinitionWML
720  * @order = 1_listbox
721  * @begin{parent}{name="gui/"}
722  * @begin{tag}{name="listbox_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
723  * == Listbox ==
724  *
725  * @macro = listbox_description
726  *
727  * The definition of a listbox contains the definition of its scrollbar.
728  *
729  * The resolution for a listbox also contains the following keys:
730  * @begin{tag}{name="resolution"}{min=0}{max=-1}{super=generic/widget_definition/resolution}
731  * @begin{table}{config}
732  * scrollbar & section & & A grid containing the widgets for the
733  * scrollbar. The scrollbar has some special
734  * widgets so it can make default behavior
735  * for certain widgets. $
736  * @end{table}
737  * @begin{table}{dialog_widgets}
738  * _begin & & clickable & o & Moves the position to the beginning
739  * of the list. $
740  * _line_up & & clickable & o & Move the position one item up. (NOTE
741  * if too many items to move per item it
742  * might be more items.) $
743  * _half_page_up & & clickable & o &
744  * Move the position half the number of the
745  * visible items up. (See note at
746  * _line_up.) $
747  * _page_up & & clickable & o & Move the position the number of
748  * visible items up. (See note at
749  * _line_up.) $
750  *
751  * _end & & clickable & o & Moves the position to the end of the
752  * list. $
753  * _line_down & & clickable & o & Move the position one item down.(See
754  * note at _line_up.) $
755  * _half_page_down & & clickable & o &
756  * Move the position half the number of the
757  * visible items down. (See note at
758  * _line_up.) $
759  * _page_down & & clickable & o & Move the position the number of
760  * visible items down. (See note at
761  * _line_up.) $
762  *
763  * _scrollbar & & vertical_scrollbar & m &
764  * This is the scrollbar so the user can
765  * scroll through the list. $
766  * @end{table}
767  * A clickable is one of:
768  * * button
769  * * repeating_button
770  * @{allow}{link}{name="gui/window/resolution/grid/row/column/button"}
771  * @{allow}{link}{name="gui/window/resolution/grid/row/column/repeating_button"}
772  * The following states exist:
773  * * state_enabled, the listbox is enabled.
774  * * state_disabled, the listbox is disabled.
775  * @begin{tag}{name="state_enabled"}{min=0}{max=1}{super="generic/state"}
776  * @end{tag}{name="state_enabled"}
777  * @begin{tag}{name="state_disabled"}{min=0}{max=1}{super="generic/state"}
778  * @end{tag}{name="state_disabled"}
779  * @allow{link}{name="gui/window/resolution/grid"}
780  * @end{tag}{name="resolution"}
781  * @end{tag}{name="listbox_definition"}
782  * @end{parent}{name="gui/"}
783  */
784 
785 /*WIKI
786  * @page = GUIWidgetDefinitionWML
787  * @order = 1_horizonal_listbox
788  *
789  * == Horizontal listbox ==
790  * @begin{parent}{name="gui/"}
791  * @begin{tag}{name="horizontal_listbox_definition"}{min=0}{max=-1}{super="gui/listbox_definition"}
792  * @end{tag}{name="horizontal_listbox_definition"}
793  * @end{parent}{name="gui/"}
794  * @macro = horizontal_listbox_description
795  * The definition of a horizontal listbox is the same as for a normal listbox.
796  */
798  : resolution_definition(cfg)
799  , grid(nullptr)
800 {
801  // Note the order should be the same as the enum state_t in listbox.hpp.
802  state.emplace_back(cfg.child("state_enabled"));
803  state.emplace_back(cfg.child("state_disabled"));
804 
805  const config& child = cfg.child("grid");
806  VALIDATE(child, _("No grid defined."));
807 
808  grid = std::make_shared<builder_grid>(child);
809 }
810 
811 // }---------- BUILDER -----------{
812 
813 /*WIKI_MACRO
814  * @begin{macro}{listbox_description}
815  *
816  * A listbox is a styled_widget that holds several items of the same type.
817  * Normally the items in a listbox are ordered in rows, this version
818  * might allow more options for ordering the items in the future.
819  * @end{macro}
820  */
821 
822 /*WIKI
823  * @page = GUIWidgetInstanceWML
824  * @order = 2_listbox
825  *
826  * == Listbox ==
827  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
828  * @begin{tag}{name="listbox"}{min=0}{max=-1}{super="generic/widget_instance"}
829  * @macro = listbox_description
830  *
831  * List with the listbox specific variables:
832  * @begin{table}{config}
833  * vertical_scrollbar_mode & scrollbar_mode & initial_auto &
834  * Determines whether or not to show the
835  * scrollbar. $
836  * horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
837  * Determines whether or not to show the
838  * scrollbar. $
839  *
840  * header & grid & [] & Defines the grid for the optional
841  * header. (This grid will automatically
842  * get the id _header_grid.) $
843  * footer & grid & [] & Defines the grid for the optional
844  * footer. (This grid will automatically
845  * get the id _footer_grid.) $
846  *
847  * list_definition & section & & This defines how a listbox item
848  * looks. It must contain the grid
849  * definition for 1 row of the list. $
850  *
851  * list_data & section & [] & A grid alike section which stores the
852  * initial data for the listbox. Every row
853  * must have the same number of columns as
854  * the 'list_definition'. $
855  *
856  * has_minimum & bool & true & If false, less than one row can be selected. $
857  *
858  * has_maximum & bool & true & If false, more than one row can be selected. $
859  *
860  * @end{table}
861  * @begin{tag}{name="header"}{min=0}{max=1}{super="gui/window/resolution/grid"}
862  * @end{tag}{name="header"}
863  * @begin{tag}{name="footer"}{min=0}{max=1}{super="gui/window/resolution/grid"}
864  * @end{tag}{name="footer"}
865  * @begin{tag}{name="list_definition"}{min=0}{max=1}
866  * @begin{tag}{name="row"}{min=1}{max=1}{super="generic/listbox_grid/row"}
867  * @end{tag}{name="row"}
868  * @end{tag}{name="list_definition"}x
869  * @begin{tag}{name="list_data"}{min=0}{max=1}{super="generic/listbox_grid"}
870  * @end{tag}{name="list_data"}
871  *
872  * In order to force widgets to be the same size inside a listbox, the widgets
873  * need to be inside a linked_group.
874  *
875  * Inside the list section there are only the following widgets allowed
876  * * grid (to nest)
877  * * selectable widgets which are
878  * ** toggle_button
879  * ** toggle_panel
880  * @end{tag}{name="listbox"}
881  *
882  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
883  */
884 
885 /*WIKI
886  * @begin{parent}{name="generic/"}
887  * @begin{tag}{name="listbox_grid"}{min="0"}{max="-1"}
888  * @begin{tag}{name="row"}{min="0"}{max="-1"}
889  * @begin{table}{config}
890  * grow_factor & unsigned & 0 & The grow factor for a row. $
891  * @end{table}
892  * @begin{tag}{name="column"}{min="0"}{max="-1"}{super="gui/window/resolution/grid/row/column"}
893  * @begin{table}{config}
894  * label & t_string & "" & $
895  * tooltip & t_string & "" & $
896  * icon & t_string & "" & $
897  * @end{table}
898  * @allow{link}{name="gui/window/resolution/grid/row/column/toggle_button"}
899  * @allow{link}{name="gui/window/resolution/grid/row/column/toggle_panel"}
900  * @end{tag}{name="column"}
901  * @end{tag}{name="row"}
902  * @end{tag}{name="listbox_grid"}
903  * @end{parent}{name="generic/"}
904  */
905 
906 namespace implementation
907 {
908 static std::vector<std::map<std::string, string_map>> parse_list_data(const config& data, const unsigned int req_cols)
909 {
910  std::vector<std::map<std::string, string_map>> list_data;
911 
912  for(const auto& row : data.child_range("row")) {
913  auto cols = row.child_range("column");
914 
915  VALIDATE(static_cast<unsigned>(cols.size()) == req_cols,
916  _("'list_data' must have the same number of columns as the 'list_definition'.")
917  );
918 
919  for(const auto& c : cols) {
920  list_data.emplace_back();
921 
922  for(const auto& i : c.attribute_range()) {
923  list_data.back()[""][i.first] = i.second;
924  }
925 
926  for(const auto& w : c.child_range("widget")) {
927  VALIDATE(w.has_attribute("id"), missing_mandatory_wml_key("[list_data][row][column][widget]", "id"));
928 
929  for(const auto& i : w.attribute_range()) {
930  list_data.back()[w["id"]][i.first] = i.second;
931  }
932  }
933  }
934  }
935 
936  return list_data;
937 }
938 
939 builder_listbox::builder_listbox(const config& cfg)
940  : builder_styled_widget(cfg)
941  , vertical_scrollbar_mode(get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
942  , horizontal_scrollbar_mode(get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
943  , header(nullptr)
944  , footer(nullptr)
945  , list_builder(nullptr)
946  , list_data()
947  , has_minimum_(cfg["has_minimum"].to_bool(true))
948  , has_maximum_(cfg["has_maximum"].to_bool(true))
949 {
950  if(const config& h = cfg.child("header")) {
951  header = std::make_shared<builder_grid>(h);
952  }
953 
954  if(const config& f = cfg.child("footer")) {
955  footer = std::make_shared<builder_grid>(f);
956  }
957 
958  const config& l = cfg.child("list_definition");
959 
960  VALIDATE(l, _("No list defined."));
961 
962  list_builder = std::make_shared<builder_grid>(l);
963  assert(list_builder);
964 
965  VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row."));
966 
967  if(cfg.has_child("list_data")) {
968  list_data = parse_list_data(cfg.child("list_data"), list_builder->cols);
969  }
970 }
971 
973 {
975 
978 
979  DBG_GUI_G << "Window builder: placed listbox '" << id << "' with definition '" << definition << "'.\n";
980 
981  const auto conf = widget->cast_config_to<listbox_definition>();
982  assert(conf);
983 
984  widget->init_grid(conf->grid);
985 
986  widget->finalize(header, footer, list_data);
987 
988  return widget;
989 }
990 
991 /*WIKI_MACRO
992  * @begin{macro}{horizontal_listbox_description}
993  *
994  * A horizontal listbox is a styled_widget that holds several items of the
995  * same type. Normally the items in a listbox are ordered in rows,
996  * this version orders them in columns instead.
997  * @end{macro}
998  */
999 
1000 /*WIKI
1001  * @page = GUIWidgetInstanceWML
1002  * @order = 2_horizontal_listbox
1003  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
1004  * @begin{tag}{name="horizontal_listbox"}{min="0"}{max="-1"}{super="generic/widget_instance"}
1005  * == Horizontal listbox ==
1006  *
1007  * @macro = horizontal_listbox_description
1008  *
1009  * List with the horizontal listbox specific variables:
1010  * @begin{table}{config}
1011  * vertical_scrollbar_mode & scrollbar_mode & initial_auto &
1012  * Determines whether or not to show the
1013  * scrollbar. $
1014  * horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
1015  * Determines whether or not to show the
1016  * scrollbar. $
1017  *
1018  * list_definition & section & & This defines how a listbox item
1019  * looks. It must contain the grid
1020  * definition for 1 column of the list. $
1021  *
1022  * list_data & section & [] & A grid alike section which stores the
1023  * initial data for the listbox. Every row
1024  * must have the same number of columns as
1025  * the 'list_definition'. $
1026  *
1027  * has_minimum & bool & true & If false, less than one row can be selected. $
1028  *
1029  * has_maximum & bool & true & If false, more than one row can be selected. $
1030  *
1031  * @end{table}
1032  * @begin{tag}{name="header"}{min=0}{max=1}{super="gui/window/resolution/grid"}
1033  * @end{tag}{name="header"}
1034  * @begin{tag}{name="footer"}{min=0}{max=1}{super="gui/window/resolution/grid"}
1035  * @end{tag}{name="footer"}
1036  * @begin{tag}{name="list_definition"}{min=0}{max=1}
1037  * @begin{tag}{name="row"}{min=1}{max=1}{super="generic/listbox_grid/row"}
1038  * @end{tag}{name="row"}
1039  * @end{tag}{name="list_definition"}
1040  * @begin{tag}{name="list_data"}{min=0}{max=1}{super="generic/listbox_grid"}
1041  * @end{tag}{name="list_data"}
1042  * In order to force widgets to be the same size inside a horizontal listbox,
1043  * the widgets need to be inside a linked_group.
1044  *
1045  * Inside the list section there are only the following widgets allowed
1046  * * grid (to nest)
1047  * * selectable widgets which are
1048  * ** toggle_button
1049  * ** toggle_panel
1050  * @end{tag}{name="horizontal_listbox"}
1051  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
1052  */
1053 
1055  : builder_styled_widget(cfg)
1056  , vertical_scrollbar_mode(get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
1057  , horizontal_scrollbar_mode(get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
1058  , list_builder(nullptr)
1059  , list_data()
1060  , has_minimum_(cfg["has_minimum"].to_bool(true))
1061  , has_maximum_(cfg["has_maximum"].to_bool(true))
1062 {
1063  const config& l = cfg.child("list_definition");
1064 
1065  VALIDATE(l, _("No list defined."));
1066 
1067  list_builder = std::make_shared<builder_grid>(l);
1068  assert(list_builder);
1069 
1070  VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row."));
1071 
1072  if(cfg.has_child("list_data")) {
1073  list_data = parse_list_data(cfg.child("list_data"), list_builder->cols);
1074  }
1075 }
1076 
1078 {
1080 
1083 
1084  DBG_GUI_G << "Window builder: placed listbox '" << id << "' with definition '" << definition << "'.\n";
1085 
1086  const auto conf = widget->cast_config_to<listbox_definition>();
1087  assert(conf);
1088 
1089  widget->init_grid(conf->grid);
1090 
1091  widget->finalize(nullptr, nullptr, list_data);
1092 
1093  return widget;
1094 }
1095 
1096 /*WIKI_MACRO
1097  * @begin{macro}{grid_listbox_description}
1098  *
1099  * A grid listbox is a styled_widget that holds several items of the
1100  * same type. Normally the items in a listbox are ordered in rows,
1101  * this version orders them in a grid instead.
1102  * @end{macro}
1103  */
1104 
1105 /*WIKI
1106  * @page = GUIWidgetInstanceWML
1107  * @order = 2_grid_listbox
1108  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
1109  * @begin{tag}{name="grid_listbox"}{min="0"}{max="-1"}{super="generic/widget_instance"}
1110  * == Horizontal listbox ==
1111  *
1112  * @macro = grid_listbox_description
1113  *
1114  * List with the grid listbox specific variables:
1115  * @begin{table}{config}
1116  * vertical_scrollbar_mode & scrollbar_mode & initial_auto &
1117  * Determines whether or not to show the
1118  * scrollbar. $
1119  * horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
1120  * Determines whether or not to show the
1121  * scrollbar. $
1122  *
1123  * list_definition & section & & This defines how a listbox item
1124  * looks. It must contain the grid
1125  * definition for 1 column of the list. $
1126  *
1127  * list_data & section & [] & A grid alike section which stores the
1128  * initial data for the listbox. Every row
1129  * must have the same number of columns as
1130  * the 'list_definition'. $
1131  *
1132  * has_minimum & bool & true & If false, less than one cell can be selected. $
1133  *
1134  * has_maximum & bool & true & If false, more than one cell can be selected. $
1135  *
1136  * @end{table}
1137  * @begin{tag}{name="header"}{min=0}{max=1}{super="gui/window/resolution/grid"}
1138  * @end{tag}{name="header"}
1139  * @begin{tag}{name="footer"}{min=0}{max=1}{super="gui/window/resolution/grid"}
1140  * @end{tag}{name="footer"}
1141  * @begin{tag}{name="list_definition"}{min=0}{max=1}
1142  * @begin{tag}{name="row"}{min=1}{max=1}{super="generic/listbox_grid/row"}
1143  * @end{tag}{name="row"}
1144  * @end{tag}{name="list_definition"}
1145  * @begin{tag}{name="list_data"}{min=0}{max=1}{super="generic/listbox_grid"}
1146  * @end{tag}{name="list_data"}
1147  * In order to force widgets to be the same size inside a grid listbox,
1148  * the widgets need to be inside a linked_group.
1149  *
1150  * Inside the list section there are only the following widgets allowed
1151  * * grid (to nest)
1152  * * selectable widgets which are
1153  * ** toggle_button
1154  * ** toggle_panel
1155  * @end{tag}{name="grid_listbox"}
1156  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
1157  */
1158 
1160  : builder_styled_widget(cfg)
1161  , vertical_scrollbar_mode(get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
1162  , horizontal_scrollbar_mode(get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
1163  , list_builder(nullptr)
1164  , list_data()
1165  , has_minimum_(cfg["has_minimum"].to_bool(true))
1166  , has_maximum_(cfg["has_maximum"].to_bool(true))
1167 {
1168  const config& l = cfg.child("list_definition");
1169 
1170  VALIDATE(l, _("No list defined."));
1171 
1172  list_builder = std::make_shared<builder_grid>(l);
1173  assert(list_builder);
1174 
1175  VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row."));
1176 
1177  if(cfg.has_child("list_data")) {
1178  list_data = parse_list_data(cfg.child("list_data"), list_builder->cols);
1179  }
1180 }
1181 
1183 {
1185 
1188 
1189  DBG_GUI_G << "Window builder: placed listbox '" << id << "' with definition '" << definition << "'.\n";
1190 
1191  const auto conf = widget->cast_config_to<listbox_definition>();
1192  assert(conf);
1193 
1194  widget->init_grid(conf->grid);
1195 
1196  widget->finalize(nullptr, nullptr, list_data);
1197 
1198  return widget;
1199 }
1200 
1201 } // namespace implementation
1202 
1203 // }------------ END --------------
1204 
1205 } // namespace gui2
const order_pair get_active_sorting_option()
Definition: listbox.cpp:659
Define the common log macros for the gui toolkit.
virtual void handle_key_left_arrow(SDL_Keymod modifier, bool &handled)=0
Left arrow key pressed.
void show_content_rect(const SDL_Rect &rect)
Shows a certain part of the content.
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
Definition: window.cpp:1282
virtual void handle_key_up_arrow(SDL_Keymod modifier, bool &handled)=0
Up arrow key pressed.
virtual unsigned get_item_at_ordered(unsigned index_ordered) const =0
#define DBG_GUI_P
Definition: log.hpp:68
void set_active_sorting_option(const order_pair &sort_by, const bool select_first=false)
Sorts the listbox by a pre-set sorting option.
Definition: listbox.cpp:640
Defines the exception classes for the layout algorithm.
Small abstract helper class.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
Definition: grid.cpp:603
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:423
#define LOG_GUI_L
Definition: log.hpp:58
Helper class to block invalidate_layout.
Definition: window.hpp:198
std::vector< state_definition > state
void set_horizontal_scrollbar_mode(const scrollbar_mode scrollbar_mode)
std::function< void(unsigned, SORT_ORDER)> callback_order_change_
Definition: listbox.hpp:381
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: listbox.cpp:449
#define DBG_GUI_L
Definition: log.hpp:57
virtual unsigned get_item_count() const =0
Returns the number of items.
virtual void handle_key_right_arrow(SDL_Keymod modifier, bool &handled)=0
Right arrow key pressed.
virtual grid & create_item(const int index, builder_grid_const_ptr list_builder, const string_map &item_data, const std::function< void(widget &)> &callback)=0
Creates a new item.
void finalize_setup()
The builder needs to call us so we do our setup.
void update_visible_area_on_key_event(const KEY_SCROLL_DIRECTION direction)
Helper to update visible area after a key event.
Definition: listbox.cpp:465
virtual void set_item_shown(const unsigned index, const bool show)=0
Shows or hides an item.
void mark_as_unsorted()
Deactivates all sorting toggle buttons at the top, making the list look like it&#39;s not sorted...
Definition: listbox.cpp:672
std::shared_ptr< const builder_grid > builder_grid_const_ptr
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
Definition: listbox.hpp:456
bool rects_overlap(const SDL_Rect &rect1, const SDL_Rect &rect2)
Tests whether two rectangles overlap.
Definition: rect.cpp:33
const grid & get_grid() const
virtual void place(const point &origin, const point &size) override=0
See widget::place.
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
Definition: listbox.hpp:483
visibility get_visible() const
Definition: widget.cpp:500
virtual void place(const point &origin, const point &size) override
See widget::place.
#define LOG_HEADER
Definition: listbox.cpp:40
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
Definition: config.cpp:416
virtual void set_order(const order_func &order)=0
virtual bool is_selected(const unsigned index) const =0
Returns whether the item is selected.
void resize_content(const int width_modification, const int height_modification, const int width__modification_pos=-1, const int height_modification_pos=-1)
Resizes the content.
Definition: listbox.cpp:380
virtual bool has_widget(const widget &widget) const override
See widget::has_widget.
Definition: grid.cpp:666
This file contains the window object, this object is a top level container which has the event manage...
child_itors child_range(config_key_type key)
Definition: config.cpp:366
void set_vertical_scrollbar_mode(const scrollbar_mode scrollbar_mode)
SDL_Rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:307
Base class for all widgets.
Definition: widget.hpp:47
std::function< bool(unsigned, unsigned)> order_func
Definition: generator.hpp:248
unsigned get_height() const
Definition: widget.cpp:327
void register_translatable_sorting_option(const int col, translatable_sorter_func_t f)
Registers a special sorting function specifically for translatable values.
Definition: listbox.cpp:632
virtual grid & item(const unsigned index)=0
Gets the grid of an item.
#define h
void swap_grid(grid *g, grid *content_grid, widget *widget, const std::string &id)
Swaps an item in a grid for another one.
std::unique_ptr< grid > content_grid_
The grid that holds the content.
bool row_selected(const unsigned row)
Check if a row is selected.
Definition: listbox.cpp:266
bool need_layout_
Definition: listbox.hpp:376
virtual unsigned get_selected_item_count() const =0
Returns the number of selected items.
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:272
void handle_key_down_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
Definition: listbox.cpp:500
void set_row_active(const unsigned row, const bool active)
Makes a row active or inactive.
Definition: listbox.cpp:137
std::pair< int, SORT_ORDER > order_pair
Definition: listbox.hpp:288
unsigned get_width() const
Definition: widget.cpp:322
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:250
torder_list orders_
Definition: listbox.hpp:379
std::string missing_mandatory_wml_key(const std::string &section, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
int x
x coordinate.
Definition: point.hpp:44
bool select_row_at(const unsigned row, const bool select=true)
Selects a row at the given position, regardless of sorting order.
Definition: listbox.cpp:260
Generic file dialog.
Definition: field-fwd.hpp:22
Sent by a widget to notify others its contents or state are modified.
Definition: handler.hpp:96
virtual point calculate_best_size() const override=0
See widget::calculate_best_size.
The listbox class.
Definition: listbox.hpp:40
void finalize(builder_grid_const_ptr header, builder_grid_const_ptr footer, const std::vector< std::map< std::string, string_map >> &list_data)
Finishes the building initialization of the widget.
Definition: listbox.cpp:542
Base container class.
Definition: grid.hpp:30
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
Definition: listbox.hpp:506
virtual void handle_key_left_arrow(SDL_Keymod modifier, bool &handled)
Left arrow key pressed.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
std::string definition
Parameters for the styled_widget.
void populate_dirty_list(window &caller, std::vector< widget *> &call_stack)
Adds a widget to the dirty list if it is dirty.
Definition: widget.cpp:414
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
Definition: listbox.hpp:507
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:232
point get_best_size() const
Gets the best size for the widget.
Definition: widget.cpp:190
Abstract base class for the generator.
Definition: generator.hpp:39
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
listbox_definition(const config &cfg)
Definition: listbox.cpp:710
std::vector< std::map< std::string, string_map > > list_data
Listbox data.
Definition: listbox.hpp:469
virtual void set_content_size(const point &origin, const point &size) override
Inherited from scrollbar_container.
Definition: listbox.cpp:681
This file contains the settings handling of the widget library.
void clear()
Removes all the rows in the listbox, clearing it.
Definition: listbox.cpp:125
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:463
builder_grid_const_ptr list_builder_
Contains the builder for the new items.
Definition: listbox.hpp:374
virtual void child_populate_dirty_list(window &caller, const std::vector< widget *> &call_stack) override
See widget::child_populate_dirty_list.
Definition: listbox.cpp:439
void toggle_item(const unsigned index)
Toggles the selection state of an item.
Definition: generator.hpp:97
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:131
bool content_resize_request(const bool force_sizing=false)
Notification if the content of a child needs a resize.
bool any_rows_shown() const
Definition: listbox.cpp:226
int get_y() const
Definition: widget.cpp:317
void order_by_column(unsigned column, widget &widget)
Definition: listbox.cpp:585
bool update_content_size()
Request to update the size of the content after changing the content.
Definition: listbox.cpp:329
virtual void create_items(const int index, builder_grid_const_ptr list_builder, const std::vector< string_map > &data, const std::function< void(widget &)> &callback)=0
Creates one or more new item(s).
void init_grid(const std::shared_ptr< builder_grid > &grid_builder)
Initializes and builds the grid.
virtual bool get_item_shown(const unsigned index) const =0
Returns whether the item is shown.
void list_item_clicked(widget &caller)
Function to call after the user clicked on a row.
Definition: listbox.cpp:278
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
virtual void place(const point &origin, const point &size) override
See widget::place.
Definition: grid.cpp:479
void order_by(const generator_base::order_func &func)
Definition: listbox.cpp:615
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
Definition: listbox.cpp:324
std::vector< std::map< std::string, string_map > > list_data
Listbox data.
Definition: listbox.hpp:493
Base class for creating containers with one or two scrollbar(s).
virtual int get_selected_item() const =0
Returns the selected item.
std::size_t i
Definition: function.cpp:933
void handle_key_right_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
Definition: listbox.cpp:528
#define LOG_GUI_G
Definition: log.hpp:41
virtual void clear()=0
Deletes all items.
std::shared_ptr< const typename T::resolution > cast_config_to() const
Casts the current resolution definition config to the respective type of a derived widget...
void set_vertical_scrollbar_item_position(const unsigned position)
Move the vertical scrollbar to a position.
mock_party p
The user set the widget invisible, that means:
window * get_window()
Get the parent window.
Definition: widget.cpp:114
static map_location::DIRECTION s
window * build(const builder_window::window_resolution *definition)
Builds a window.
const SDL_Rect & content_visible_area() const
std::map< std::string, t_string > string_map
Definition: widget.hpp:24
std::array< generator_base::order_func, 2 > generator_sort_array
Definition: generator.hpp:381
Holds a 2D point.
Definition: point.hpp:23
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:66
void set_active(const bool active)
Activates all children.
Definition: grid.cpp:162
int w
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
virtual void set_value(unsigned value, bool fire_event=false)=0
Select the styled_widget.
scrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
Definition: helper.cpp:120
boost::dynamic_bitset get_rows_shown() const
Returns a list of visible rows.
Definition: listbox.cpp:221
virtual void layout_children() override
See widget::layout_children.
Definition: listbox.cpp:434
point get_size() const
Returns the size of the widget.
Definition: widget.cpp:302
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:237
std::vector< std::map< std::string, string_map > > list_data
Listbox data.
Definition: listbox.hpp:517
Contains the SDL_Rect helper code.
virtual void delete_item(const unsigned index)=0
Deletes an item.
#define f
virtual void child_populate_dirty_list(window &caller, const std::vector< widget *> &call_stack) override
See widget::child_populate_dirty_list.
static std::vector< std::map< std::string, string_map > > parse_list_data(const config &data, const unsigned int req_cols)
Definition: listbox.cpp:908
int icompare(const std::string &s1, const std::string &s2)
Case-insensitive lexicographical comparison.
Definition: gettext.cpp:476
SDL_Rect content_visible_area_
Cache for the visible area for the content.
virtual void handle_key_down_arrow(SDL_Keymod modifier, bool &handled)=0
Down arrow key pressed.
virtual void select_item(const unsigned index, const bool select)=0
(De)selects an item.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Definition: listbox.cpp:86
const bool is_horizontal_
Definition: listbox.hpp:371
#define REGISTER_WIDGET3(type, id, key)
Registers a widget.
unsigned get_vertical_scrollbar_item_position() const
Returns current position of the vertical scrollbar.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:120
void set_column_order(unsigned col, const generator_sort_array &func)
Definition: listbox.cpp:623
virtual void set_size(const point &size)
Sets the size of the widget.
Definition: widget.cpp:224
void invalidate_layout()
Updates the size of the window.
Definition: window.cpp:806
void handle_key_up_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
Definition: listbox.cpp:486
virtual void handle_key_up_arrow(SDL_Keymod modifier, bool &handled)
Up arrow key pressed.
generator_base * generator_
Contains a pointer to the generator.
Definition: listbox.hpp:369
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
mock_char c
std::function< std::string(const int)> translatable_sorter_func_t
Definition: listbox.hpp:277
unsigned get_horizontal_scrollbar_item_position() const
Returns current position of the horizontal scrollbar.
int y
y coordinate.
Definition: point.hpp:47
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
Definition: listbox.hpp:482
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63
#define DBG_GUI_G
Definition: log.hpp:40
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
Definition: listbox.cpp:143
std::shared_ptr< builder_grid > builder_grid_ptr
void handle_key_left_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from scrollbar_container.
Definition: listbox.cpp:514
static std::deque< std::string > call_stack
Definition: function.cpp:39
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
Definition: listbox.hpp:455
virtual void place(const point &origin, const point &size) override
See widget::place.
Definition: listbox.cpp:348
point get_origin() const
Returns the screen origin of the widget.
Definition: widget.cpp:297
Class for a toggle button.
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
boost::dynamic_bitset get_items_shown() const
Returns the visibility of all the items as a bit set.
Definition: generator.hpp:119
virtual unsigned get_value() const =0
Is the styled_widget selected?
void set_horizontal_scrollbar_item_position(const unsigned position)
Move the horizontal scrollbar to a position.