16 #define GETTEXT_DOMAIN "wesnoth-lib"
31 #include <string_view>
33 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
34 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
42 using namespace std::literals;
43 constexpr std::array button_up_names {
"_begin"sv,
"_line_up"sv,
"_half_page_up"sv,
"_page_up"sv };
44 constexpr std::array button_down_names {
"_end"sv,
"_line_down"sv,
"_half_page_down"sv,
"_page_down"sv };
50 const std::map<std::string, scrollbar_base::scroll_mode>& scroll_lookup()
52 static std::map<std::string, scrollbar_base::scroll_mode> lookup;
74 , vertical_scrollbar_mode_(AUTO_VISIBLE_FIRST_RUN)
75 , horizontal_scrollbar_mode_(AUTO_VISIBLE_FIRST_RUN)
76 , vertical_scrollbar_grid_(nullptr)
77 , horizontal_scrollbar_grid_(nullptr)
78 , vertical_scrollbar_(nullptr)
79 , horizontal_scrollbar_(nullptr)
80 , content_grid_(nullptr)
82 , content_visible_area_()
84 connect_signal<event::SDL_KEY_DOWN>(
87 connect_signal<event::SDL_WHEEL_UP>(
91 connect_signal<event::SDL_WHEEL_DOWN>(
95 connect_signal<event::SDL_WHEEL_LEFT>(
99 connect_signal<event::SDL_WHEEL_RIGHT>(
103 connect_signal<event::SDL_TOUCH_MOTION>(
106 std::placeholders::_2,
107 std::placeholders::_3,
108 std::placeholders::_5,
109 std::placeholders::_6),
118 if(full_initialization) {
164 const unsigned offset =
169 content_grid_->request_reduce_height(maximum_height - offset);
173 if(
static_cast<unsigned>(
size.y) <= maximum_height) {
192 if(resized && scrollbar_size.y >
size.y) {
195 <<
" increased the height to " << scrollbar_size.y <<
".";
199 if(maximum_height >
static_cast<unsigned>(scrollbar_size.y)) {
200 size.y = maximum_height;
202 size.y = scrollbar_size.y;
228 const unsigned offset =
237 if(
static_cast<unsigned>(
size.x) <= maximum_width) {
266 <<
" increased the width to " << scrollbar_size.x <<
".";
270 if(maximum_width >
static_cast<unsigned>(scrollbar_size.x)) {
271 size.x = maximum_width;
273 size.x = scrollbar_size.x;
320 const unsigned items,
321 const unsigned visible_items,
324 assert(scrollbar_grid && scrollbar);
335 const bool scrollbar_needed = items > visible_items;
338 if(items <= visible_items && content_grid !=
nullptr
348 unsigned insertion_pos,
unsigned old_item_count,
unsigned old_position,
unsigned visible_items)
350 if(old_position == 0) {
352 }
else if(old_position + visible_items >= old_item_count) {
354 }
else if(insertion_pos <= old_position) {
364 const unsigned items_before,
365 const unsigned items_after,
366 const int insertion_pos,
367 const unsigned visible_items)
369 assert(scrollbar_grid && scrollbar);
379 static_cast<unsigned>(insertion_pos), items_before, previous_item_position, visible_items);
388 ? previous_item_position + items_after - items_before
389 : previous_item_position);
395 const bool scrollbar_needed = items_after > visible_items;
413 const point content_grid_size(std::max(best_size.x, content_size.x), std::max(best_size.y, content_size.y));
484 widget*
w = scrollbar_container_implementation::find_at<widget>(*
this,
coordinate, must_be_active);
494 const widget*
w = scrollbar_container_implementation::find_at<const widget>(*
this,
coordinate, must_be_active);
504 return scrollbar_container_implementation::find<widget>(*
this,
id, must_be_active);
509 return scrollbar_container_implementation::find<const widget>(*
this,
id, must_be_active);
520 return std::make_unique<gui2::iteration::scrollbar_container>(*
this);
545 if(best_size.x <=
size.x && best_size.y <=
size.y) {
548 if(content_size.x >
size.x || content_size.y >
size.y) {
562 if(best_size.x >
size.x) {
579 if(best_size.y >
size.y) {
604 const int height_modification,
605 const int width_modification_pos,
606 const int height_modification_pos)
608 DBG_GUI_L <<
LOG_HEADER <<
" wanted width modification " << width_modification <<
" wanted height modification "
609 << height_modification <<
".";
646 if(width_modification == 0) {
650 const int new_width =
content_grid_->get_width() + width_modification;
658 DBG_GUI_L <<
" width fits in container, test height.";
673 DBG_GUI_L <<
" can't use horizontal scrollbar, ask window.";
682 DBG_GUI_L <<
" use the horizontal scrollbar, test height.";
692 if(height_modification == 0) {
696 const int new_height =
content_grid_->get_height() + height_modification;
705 DBG_GUI_L <<
" height in container, resize allowed.";
719 DBG_GUI_L <<
" can't use vertical scrollbar, ask window.";
728 DBG_GUI_L <<
" use the vertical scrollbar, resize allowed.";
757 for(
const auto& item : scroll_lookup()) {
776 auto content = build_single_widget_instance<spacer>();
840 const int wanted_bottom =
rect.y +
rect.h;
843 int distance = wanted_bottom - current_bottom;
849 const int wanted_right =
rect.x +
rect.w;
852 distance = wanted_right - current_right;
875 for(
const auto& name : button_up_names) {
884 for(
const auto& name : button_down_names) {
898 for(
const auto& name : button_up_names) {
907 for(
const auto& name : button_down_names) {
1105 static const std::string
type =
"scrollbar_container";
1115 const event::ui_event event,
bool& handled,
const SDL_Keycode key, SDL_Keymod modifier)
1212 const point& position,
1213 const point& distance)
1218 bool is_scrollbar_moved =
false;
1224 is_scrollbar_moved =
true;
1232 is_scrollbar_moved =
true;
1236 if (is_scrollbar_moved) {
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
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)
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::size_t size(const std::string &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...