16 #define GETTEXT_DOMAIN "wesnoth-lib"
33 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
34 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
41 static const std::string button_up_names[]
42 {
"_begin",
"_line_up",
"_half_page_up",
"_page_up" };
44 static const std::string button_down_names[]
45 {
"_end",
"_line_down",
"_half_page_down",
"_page_down" };
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_(AUTO_VISIBLE_FIRST_RUN)
76 , horizontal_scrollbar_mode_(AUTO_VISIBLE_FIRST_RUN)
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);
337 const bool scrollbar_needed =
items > visible_items;
340 if(
items <= visible_items && content_grid !=
nullptr
350 unsigned insertion_pos,
unsigned old_item_count,
unsigned old_position,
unsigned visible_items)
352 if(old_position == 0) {
354 }
else if(old_position + visible_items >= old_item_count) {
356 }
else if(insertion_pos <= old_position) {
366 const unsigned items_before,
367 const unsigned items_after,
368 const int insertion_pos,
369 const unsigned visible_items)
371 assert(scrollbar_grid && scrollbar);
381 static_cast<unsigned>(insertion_pos), items_before, previous_item_position, visible_items);
390 ? previous_item_position + items_after - items_before
391 : previous_item_position);
397 const bool scrollbar_needed = items_after > visible_items;
415 const point content_grid_size(std::max(best_size.x, content_size.x), std::max(best_size.y, content_size.y));
486 widget*
w = scrollbar_container_implementation::find_at<widget>(*
this,
coordinate, must_be_active);
496 const widget*
w = scrollbar_container_implementation::find_at<const widget>(*
this,
coordinate, must_be_active);
506 return scrollbar_container_implementation::find<widget>(*
this,
id, must_be_active);
511 return scrollbar_container_implementation::find<const widget>(*
this,
id, must_be_active);
522 return std::make_unique<gui2::iteration::scrollbar_container>(*
this);
547 if(best_size.x <=
size.x && best_size.y <=
size.y) {
550 if(content_size.x >
size.x || content_size.y >
size.y) {
564 if(best_size.x >
size.x) {
581 if(best_size.y >
size.y) {
606 const int height_modification,
607 const int width_modification_pos,
608 const int height_modification_pos)
610 DBG_GUI_L <<
LOG_HEADER <<
" wanted width modification " << width_modification <<
" wanted height modification "
611 << height_modification <<
".";
648 if(width_modification == 0) {
652 const int new_width =
content_grid_->get_width() + width_modification;
660 DBG_GUI_L <<
" width fits in container, test height.";
675 DBG_GUI_L <<
" can't use horizontal scrollbar, ask window.";
684 DBG_GUI_L <<
" use the horizontal scrollbar, test height.";
694 if(height_modification == 0) {
698 const int new_height =
content_grid_->get_height() + height_modification;
707 DBG_GUI_L <<
" height in container, resize allowed.";
721 DBG_GUI_L <<
" can't use vertical scrollbar, ask window.";
730 DBG_GUI_L <<
" use the vertical scrollbar, resize allowed.";
759 for(
const auto&
item : scroll_lookup()) {
778 auto content = build_single_widget_instance<spacer>();
842 const int wanted_bottom =
rect.y +
rect.h;
845 int distance = wanted_bottom - current_bottom;
851 const int wanted_right =
rect.x +
rect.w;
854 distance = wanted_right - current_right;
877 for(
const auto& name : button_up_names) {
886 for(
const auto& name : button_down_names) {
900 for(
const auto& name : button_up_names) {
909 for(
const auto& name : button_down_names) {
1084 static const std::string
type =
"scrollbar_container";
1094 const event::ui_event event,
bool& handled,
const SDL_Keycode key, SDL_Keymod modifier)
1191 const point& position,
1192 const point& distance)
1197 bool is_scrollbar_moved =
false;
1203 is_scrollbar_moved =
true;
1211 is_scrollbar_moved =
true;
1215 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)
std::pair< std::string, unsigned > item
const std::vector< std::string > items
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...