15 #define GETTEXT_DOMAIN "wesnoth-lib"
29 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
30 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
39 = {
"_begin",
"_line_up",
"_half_page_up",
"_page_up" };
42 = {
"_end",
"_line_down",
"_half_page_down",
"_page_down" };
48 const std::map<std::string, tscrollbar_::tscroll>& scroll_lookup()
50 static std::map<std::string, tscrollbar_::tscroll> lookup;
71 , vertical_scrollbar_mode_(auto_visible_first_run)
72 , horizontal_scrollbar_mode_(auto_visible_first_run)
73 , vertical_scrollbar_grid_(nullptr)
74 , horizontal_scrollbar_grid_(nullptr)
75 , vertical_scrollbar_(nullptr)
76 , horizontal_scrollbar_(nullptr)
77 , content_grid_(nullptr)
79 , content_visible_area_()
81 connect_signal<event::SDL_KEY_DOWN>(
90 connect_signal<event::SDL_WHEEL_UP>(
97 connect_signal<event::SDL_WHEEL_DOWN>(
104 connect_signal<event::SDL_WHEEL_LEFT>(
111 connect_signal<event::SDL_WHEEL_RIGHT>(
124 if(full_initialisation) {
185 if(static_cast<unsigned>(size.
y) <= maximum_height) {
206 if(resized && scrollbar_size.
y > size.
y) {
209 <<
" increased the height to " << scrollbar_size.
y <<
".\n";
213 if(maximum_height > static_cast<unsigned>(scrollbar_size.
y)) {
214 size.
y = maximum_height;
216 size.
y = scrollbar_size.
y;
226 <<
" resize modified the width, throw notification.\n";
250 if(static_cast<unsigned>(size.
x) <= maximum_width) {
284 <<
" increased the width to " << scrollbar_size.
x <<
".\n";
288 if(maximum_width > static_cast<unsigned>(scrollbar_size.
x)) {
289 size.
x = maximum_width;
291 size.
x = scrollbar_size.
x;
310 const tpoint vertical_scrollbar
317 const tpoint horizontal_scrollbar
328 vertical_scrollbar.
x + std::max(horizontal_scrollbar.
x, content.
x),
329 horizontal_scrollbar.
y + std::max(vertical_scrollbar.
y, content.
y));
332 <<
" horizontal_scrollbar " << horizontal_scrollbar <<
" content "
333 << content <<
" result " << result <<
".\n";
342 const unsigned items,
343 const unsigned visible_items)
345 assert(scrollbar_grid && scrollbar);
358 const bool scrollbar_needed = items > visible_items;
365 static bool is_inserted_before(
unsigned insertion_pos,
unsigned old_item_count,
unsigned old_position,
unsigned visible_items)
367 if(old_position == 0)
369 else if(old_position + visible_items >= old_item_count)
371 else if(insertion_pos <= old_position)
381 const unsigned items_before,
382 const unsigned items_after,
383 const int insertion_pos,
384 const unsigned visible_items)
386 assert(scrollbar_grid && scrollbar);
388 return set_scrollbar_mode(scrollbar_grid, scrollbar, scrollbar_mode, items_after, visible_items);
393 const bool inserted_before_visible_area =
is_inserted_before(static_cast<unsigned>(insertion_pos), items_before, previous_item_position, visible_items);
401 scrollbar->
set_item_position(inserted_before_visible_area ? previous_item_position + items_after - items_before : previous_item_position);
407 const bool scrollbar_needed = items_after > visible_items;
428 const tpoint content_grid_size(std::max(best_size.
x, content_size.x),
429 std::max(best_size.
y, content_size.y));
494 const bool must_be_active)
496 return tscrollbar_container_implementation::find_at<twidget>(
497 *
this, coordinate, must_be_active);
501 const bool must_be_active)
const
503 return tscrollbar_container_implementation::find_at<const twidget>(
504 *
this, coordinate, must_be_active);
508 const bool must_be_active)
510 return tscrollbar_container_implementation::find<twidget>(
511 *
this,
id, must_be_active);
515 const bool must_be_active)
const
517 return tscrollbar_container_implementation::find<const twidget>(
518 *
this,
id, must_be_active);
544 <<
" available size " << size <<
".\n";
546 if(size ==
tpoint(0, 0)) {
551 if(best_size.
x <= size.x && best_size.
y <= size.y) {
553 if(content_size.
x > size.x || content_size.
y > size.y) {
565 if(best_size.
x > size.x) {
573 <<
" can't use horizontal scrollbar, ask window.\n";
581 if(best_size.
y > size.y) {
589 <<
" can't use vertical scrollbar, ask window.\n";
604 const int height_modification,
605 const int width_modification_pos,
606 const int height_modification_pos)
609 << width_modification <<
" wanted height modification "
610 << height_modification <<
".\n";
621 <<
" window already needs a layout phase, bailing out.\n";
644 if(width_modification == 0) {
650 <<
" wanted width " << new_width;
652 assert(new_width > 0);
655 DBG_GUI_L <<
" width fits in container, test height.\n";
661 width_modification_pos,
672 DBG_GUI_L <<
" can't use horizontal scrollbar, ask window.\n";
679 DBG_GUI_L <<
" use the horizontal scrollbar, test height.\n";
685 width_modification_pos,
693 if(height_modification == 0) {
700 <<
" wanted height " << new_height;
702 assert(new_height > 0);
705 DBG_GUI_L <<
" height in container, resize allowed.\n";
711 height_modification_pos,
722 DBG_GUI_L <<
" can't use vertical scrollbar, ask window.\n";
729 DBG_GUI_L <<
" use the vertical scrollbar, resize allowed.\n";
735 height_modification_pos,
746 = find_widget<tgrid>(
this,
"_vertical_scrollbar_grid",
false,
true);
752 *vertical_scrollbar_,
757 this,
"_horizontal_scrollbar_grid",
false,
true);
763 *horizontal_scrollbar_,
768 for(
const auto & item : scroll_lookup())
783 button = find_widget<tclickable_>(
847 twindow& caller,
const std::vector<twidget*>& call_stack)
853 std::vector<twidget*> child_call_stack(call_stack);
878 const int wanted_bottom = rect.y + rect.h;
880 int distance = wanted_bottom - current_bottom;
887 const int wanted_right = rect.x + rect.w;
889 distance = wanted_right - current_right;
917 for(
const auto &
name : button_up_names)
919 tcontrol* button = find_widget<tcontrol>(
928 for(
const auto &
name : button_down_names)
930 tcontrol* button = find_widget<tcontrol>(
945 for(
const auto &
name : button_up_names)
947 tcontrol* button = find_widget<tcontrol>(
956 for(
const auto &
name : button_down_names)
958 tcontrol* button = find_widget<tcontrol>(
987 const unsigned position)
Define the common log macros for the gui toolkit.
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
Calculates the intersection of two rectangles.
Defines the exception classes for the layout algorithm.
const tgrid & grid() const
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
virtual void layout_children() override
See twidget::layout_children.
GLuint GLuint GLsizei GLenum type
virtual void impl_draw_children(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_children.
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
static void adjust_scrollbar_mode(tgrid *scrollbar_grid, tscrollbar_ *scrollbar, tscrollbar_container::tscrollbar_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")
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
tpoint recalculate_best_size()
Recalculates the best size.
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
const std::vector< std::string > items
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
static bool is_inserted_before(unsigned insertion_pos, unsigned old_item_count, unsigned old_position, unsigned visible_items)
base class of top level items, the only item which needs to store the final canvases to draw on ...
A class inherited from ttext_box that displays its input as stars.
virtual void request_reduce_height(const unsigned maximum_height) override
See twidget::request_reduce_height.
virtual void set_active(const bool active)=0
Sets the control's state.
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
#define log_scope2(domain, description)
Exception thrown when the width has been modified during resizing.
tevent
The event send to the dispatcher.
virtual void connect_click_handler(const event::tsignal_function &signal)=0
Connects a signal handler for a 'click' event.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
virtual void layout_children() override
See twidget::layout_children.
virtual void child_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack) override
See twidget::child_populate_dirty_list.
bool get_need_layout() const
virtual bool can_wrap() const override
See twidget::can_wrap.
twidget * swap_child(const std::string &id, twidget *widget, const bool recurse, twidget *new_parent=nullptr)
Exchanges a child in the grid.
Base class for all visible items.
GLuint const GLchar * name
A generic container base class.
Contains the SDL_Rect helper code.
static void set_scrollbar_mode(tgrid *scrollbar_grid, tscrollbar_ *scrollbar, tscrollbar_container::tscrollbar_mode &scrollbar_mode, const unsigned items, const unsigned visible_items)
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
void set_definition(const std::string &definition)
Sets the definition.
GLsizei const GLcharARB ** string
void invalidate_layout()
Updates the size of the window.