16 #define GETTEXT_DOMAIN "wesnoth-lib"
33 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
34 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
42 static const std::string button_up_names[]
43 {
"_begin",
"_line_up",
"_half_page_up",
"_page_up" };
45 static const std::string button_down_names[]
46 {
"_end",
"_line_down",
"_half_page_down",
"_page_down" };
52 const std::map<std::string, scrollbar_base::scroll_mode>& scroll_lookup()
54 static std::map<std::string, scrollbar_base::scroll_mode> lookup;
76 , vertical_scrollbar_mode_(AUTO_VISIBLE_FIRST_RUN)
77 , horizontal_scrollbar_mode_(AUTO_VISIBLE_FIRST_RUN)
78 , vertical_scrollbar_grid_(nullptr)
79 , horizontal_scrollbar_grid_(nullptr)
80 , vertical_scrollbar_(nullptr)
81 , horizontal_scrollbar_(nullptr)
82 , content_grid_(nullptr)
84 , content_visible_area_()
86 connect_signal<event::SDL_KEY_DOWN>(
89 connect_signal<event::SDL_WHEEL_UP>(
93 connect_signal<event::SDL_WHEEL_DOWN>(
97 connect_signal<event::SDL_WHEEL_LEFT>(
101 connect_signal<event::SDL_WHEEL_RIGHT>(
105 connect_signal<event::SDL_TOUCH_MOTION>(
108 std::placeholders::_2,
109 std::placeholders::_3,
110 std::placeholders::_5,
111 std::placeholders::_6),
120 if(full_initialization) {
166 const unsigned offset =
171 content_grid_->request_reduce_height(maximum_height - offset);
175 if(
static_cast<unsigned>(
size.y) <= maximum_height) {
194 if(resized && scrollbar_size.y >
size.y) {
197 <<
" increased the height to " << scrollbar_size.y <<
".";
201 if(maximum_height >
static_cast<unsigned>(scrollbar_size.y)) {
202 size.y = maximum_height;
204 size.y = scrollbar_size.y;
230 const unsigned offset =
239 if(
static_cast<unsigned>(
size.x) <= maximum_width) {
268 <<
" increased the width to " << scrollbar_size.x <<
".";
272 if(maximum_width >
static_cast<unsigned>(scrollbar_size.x)) {
273 size.x = maximum_width;
275 size.x = scrollbar_size.x;
322 const unsigned items,
323 const unsigned visible_items,
326 assert(scrollbar_grid && scrollbar);
338 const bool scrollbar_needed =
items > visible_items;
341 if(
items <= visible_items && content_grid !=
nullptr
351 unsigned insertion_pos,
unsigned old_item_count,
unsigned old_position,
unsigned visible_items)
353 if(old_position == 0) {
355 }
else if(old_position + visible_items >= old_item_count) {
357 }
else if(insertion_pos <= old_position) {
367 const unsigned items_before,
368 const unsigned items_after,
369 const int insertion_pos,
370 const unsigned visible_items)
372 assert(scrollbar_grid && scrollbar);
382 static_cast<unsigned>(insertion_pos), items_before, previous_item_position, visible_items);
391 ? previous_item_position + items_after - items_before
392 : previous_item_position);
398 const bool scrollbar_needed = items_after > visible_items;
416 const point content_grid_size(std::max(best_size.x, content_size.x), std::max(best_size.y, content_size.y));
487 widget*
w = scrollbar_container_implementation::find_at<widget>(*
this,
coordinate, must_be_active);
497 const widget*
w = scrollbar_container_implementation::find_at<const widget>(*
this,
coordinate, must_be_active);
507 return scrollbar_container_implementation::find<widget>(*
this,
id, must_be_active);
512 return scrollbar_container_implementation::find<const widget>(*
this,
id, must_be_active);
523 return std::make_unique<gui2::iteration::scrollbar_container>(*
this);
548 if(best_size.x <=
size.x && best_size.y <=
size.y) {
551 if(content_size.x >
size.x || content_size.y >
size.y) {
565 if(best_size.x >
size.x) {
582 if(best_size.y >
size.y) {
607 const int height_modification,
608 const int width_modification_pos,
609 const int height_modification_pos)
611 DBG_GUI_L <<
LOG_HEADER <<
" wanted width modification " << width_modification <<
" wanted height modification "
612 << height_modification <<
".";
649 if(width_modification == 0) {
653 const int new_width =
content_grid_->get_width() + width_modification;
661 DBG_GUI_L <<
" width fits in container, test height.";
676 DBG_GUI_L <<
" can't use horizontal scrollbar, ask window.";
685 DBG_GUI_L <<
" use the horizontal scrollbar, test height.";
695 if(height_modification == 0) {
699 const int new_height =
content_grid_->get_height() + height_modification;
708 DBG_GUI_L <<
" height in container, resize allowed.";
722 DBG_GUI_L <<
" can't use vertical scrollbar, ask window.";
731 DBG_GUI_L <<
" use the vertical scrollbar, resize allowed.";
760 for(
const auto&
item : scroll_lookup()) {
779 auto content = build_single_widget_instance<spacer>();
843 const int wanted_bottom =
rect.y +
rect.h;
846 int distance = wanted_bottom - current_bottom;
852 const int wanted_right =
rect.x +
rect.w;
855 distance = wanted_right - current_right;
878 for(
const auto& name : button_up_names) {
887 for(
const auto& name : button_down_names) {
901 for(
const auto& name : button_up_names) {
910 for(
const auto& name : button_down_names) {
1108 static const std::string
type =
"scrollbar_container";
1118 const event::ui_event event,
bool& handled,
const SDL_Keycode key, SDL_Keymod modifier)
1215 const point& position,
1216 const point& distance)
1221 bool is_scrollbar_moved =
false;
1227 is_scrollbar_moved =
true;
1235 is_scrollbar_moved =
true;
1239 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...