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