16 #define GETTEXT_DOMAIN "wesnoth-lib"
32 #include <string_view>
34 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
35 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
43 using namespace std::literals;
44 constexpr std::array button_up_names {
"_begin"sv,
"_line_up"sv,
"_half_page_up"sv,
"_page_up"sv };
45 constexpr std::array button_down_names {
"_end"sv,
"_line_down"sv,
"_half_page_down"sv,
"_page_down"sv };
51 const std::map<std::string, scrollbar_base::scroll_mode>& scroll_lookup()
53 static std::map<std::string, scrollbar_base::scroll_mode> lookup;
75 , vertical_scrollbar_mode_(builder.vertical_scrollbar_mode)
76 , horizontal_scrollbar_mode_(builder.horizontal_scrollbar_mode)
77 , vertical_scrollbar_grid_(nullptr)
78 , horizontal_scrollbar_grid_(nullptr)
79 , vertical_scrollbar_(nullptr)
80 , horizontal_scrollbar_(nullptr)
81 , content_grid_(nullptr)
83 , content_visible_area_()
85 connect_signal<event::SDL_KEY_DOWN>(
88 connect_signal<event::SDL_WHEEL_UP>(
92 connect_signal<event::SDL_WHEEL_DOWN>(
96 connect_signal<event::SDL_WHEEL_LEFT>(
100 connect_signal<event::SDL_WHEEL_RIGHT>(
104 connect_signal<event::SDL_TOUCH_MOTION>(
107 std::placeholders::_2,
108 std::placeholders::_3,
109 std::placeholders::_5,
110 std::placeholders::_6),
119 if(full_initialization) {
165 const unsigned offset =
170 content_grid_->request_reduce_height(maximum_height - offset);
174 if(
static_cast<unsigned>(
size.y) <= maximum_height) {
193 if(resized && scrollbar_size.y >
size.y) {
196 <<
" increased the height to " << scrollbar_size.y <<
".";
200 if(maximum_height >
static_cast<unsigned>(scrollbar_size.y)) {
201 size.y = maximum_height;
203 size.y = scrollbar_size.y;
229 const unsigned offset =
238 if(
static_cast<unsigned>(
size.x) <= maximum_width) {
267 <<
" increased the width to " << scrollbar_size.x <<
".";
271 if(maximum_width >
static_cast<unsigned>(scrollbar_size.x)) {
272 size.x = maximum_width;
274 size.x = scrollbar_size.x;
321 const unsigned items,
322 const unsigned visible_items,
325 assert(scrollbar_grid && scrollbar);
336 const bool scrollbar_needed = items > visible_items;
339 if(items <= visible_items && content_grid !=
nullptr
349 unsigned insertion_pos,
unsigned old_item_count,
unsigned old_position,
unsigned visible_items)
351 if(old_position == 0) {
353 }
else if(old_position + visible_items >= old_item_count) {
355 }
else if(insertion_pos <= old_position) {
365 const unsigned items_before,
366 const unsigned items_after,
367 const int insertion_pos,
368 const unsigned visible_items)
370 assert(scrollbar_grid && scrollbar);
380 static_cast<unsigned>(insertion_pos), items_before, previous_item_position, visible_items);
389 ? previous_item_position + items_after - items_before
390 : previous_item_position);
396 const bool scrollbar_needed = items_after > visible_items;
414 const point content_grid_size(std::max(best_size.x, content_size.x), std::max(best_size.y, content_size.y));
485 widget*
w = scrollbar_container_implementation::find_at<widget>(*
this,
coordinate, must_be_active);
495 const widget*
w = scrollbar_container_implementation::find_at<const widget>(*
this,
coordinate, must_be_active);
505 return scrollbar_container_implementation::find<widget>(*
this,
id, must_be_active);
510 return scrollbar_container_implementation::find<const widget>(*
this,
id, must_be_active);
521 return std::make_unique<gui2::iteration::scrollbar_container>(*
this);
546 if(best_size.x <=
size.x && best_size.y <=
size.y) {
549 if(content_size.x >
size.x || content_size.y >
size.y) {
563 if(best_size.x >
size.x) {
580 if(best_size.y >
size.y) {
605 const int height_modification,
606 const int width_modification_pos,
607 const int height_modification_pos)
609 DBG_GUI_L <<
LOG_HEADER <<
" wanted width modification " << width_modification <<
" wanted height modification "
610 << height_modification <<
".";
647 if(width_modification == 0) {
651 const int new_width =
content_grid_->get_width() + width_modification;
659 DBG_GUI_L <<
" width fits in container, test height.";
674 DBG_GUI_L <<
" can't use horizontal scrollbar, ask window.";
683 DBG_GUI_L <<
" use the horizontal scrollbar, test height.";
693 if(height_modification == 0) {
697 const int new_height =
content_grid_->get_height() + height_modification;
706 DBG_GUI_L <<
" height in container, resize allowed.";
720 DBG_GUI_L <<
" can't use vertical scrollbar, ask window.";
729 DBG_GUI_L <<
" use the vertical scrollbar, resize allowed.";
758 for(
const auto& item : scroll_lookup()) {
777 auto content = build_single_widget_instance<spacer>();
841 const int wanted_bottom =
rect.y +
rect.h;
844 int distance = wanted_bottom - current_bottom;
850 const int wanted_right =
rect.x +
rect.w;
853 distance = wanted_right - current_right;
876 for(
const auto& name : button_up_names) {
885 for(
const auto& name : button_down_names) {
899 for(
const auto& name : button_up_names) {
908 for(
const auto& name : button_down_names) {
1106 static const std::string
type =
"scrollbar_container";
1116 const event::ui_event event,
bool& handled,
const SDL_Keycode key, SDL_Keymod modifier)
1213 const point& position,
1214 const point& distance)
1219 bool is_scrollbar_moved =
false;
1225 is_scrollbar_moved =
true;
1233 is_scrollbar_moved =
true;
1237 if (is_scrollbar_moved) {
A config object defines a single node in a WML file, with access to child nodes.
A generic container base class.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
const grid & get_grid() const
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
virtual void layout_children() override
See widget::layout_children.
virtual void set_origin(const point &origin) override
See widget::set_origin.
virtual void place(const point &origin, const point &size) override
See widget::place.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
virtual void impl_draw_children() override
See widget::impl_draw_children.
Main class to show messages to the user.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
base class of top level items, the only item which needs to store the final canvases to draw on.
void invalidate_layout()
Updates the size of the window.
bool get_need_layout() const
This file contains the definitions for the gui2::event::message class.
Define the common log macros for the gui toolkit.
Defines the exception classes for the layout algorithm.
#define log_scope2(domain, description)
void point(int x, int y)
Draw a single point.
ui_event
The event sent to the dispatcher.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
scrollbar_container::scrollbar_mode scrollbar_mode
scrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
std::unique_ptr< class walker_base > walker_ptr
static bool is_inserted_before(unsigned insertion_pos, unsigned old_item_count, unsigned old_position, unsigned visible_items)
static void adjust_scrollbar_mode(grid *scrollbar_grid, scrollbar_base *scrollbar, scrollbar_container::scrollbar_mode &scrollbar_mode, const unsigned items_before, const unsigned items_after, const int insertion_pos, const unsigned visible_items)
lg::log_domain log_gui_layout("gui/layout")
static void set_scrollbar_mode(grid *scrollbar_grid, scrollbar_base *scrollbar, scrollbar_container::scrollbar_mode &scrollbar_mode, const unsigned items, const unsigned visible_items, grid *content_grid)
Contains the implementation details for lexical_cast and shouldn't be used directly.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Contains the SDL_Rect helper code.
The message callbacks hold a reference to a message.
Exception thrown when the width has been modified during resizing.
An abstract description of a rectangle with integer coordinates.
rect intersect(const SDL_Rect &r) const
Calculates the intersection of this rectangle and another; that is, the maximal rectangle that is con...