The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
walker_scrollbar_container.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2011 - 2025
3 by Mark de Wever <koraq@xs4all.nl>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#define GETTEXT_DOMAIN "wesnoth-lib"
17
19
20#include <cassert>
21
22namespace gui2::iteration
23{
24
29
31{
32 if(at_end(level)) {
33 return fail;
34 }
35
36 switch(level) {
37 case self:
38 if(widget_) {
39 widget_ = nullptr;
40 return invalid;
41 }
42 assert(false);
43 return fail;
44 case internal:
45 if(!entered_grid) {
46 entered_grid = true;
47 in_grid = true;
48 return valid;
49 }
50 if(in_grid) {
51 ++itor_;
52 if(itor_ == container_.end()) {
53 in_grid = false;
54 entered_children = true;
56 return invalid;
57 }
58 return valid;
59 }
60 assert(false);
61 return fail;
62 case child:
63 if(itor_ != container_.content_grid()->end()) {
64 ++itor_;
65 return itor_ == container_.content_grid()->end() ? invalid : valid;
66 }
67 }
68
69 assert(false);
70 return fail;
71}
72
74{
75 switch(level) {
76 case self:
77 return widget_ == nullptr;
78 case internal:
79 return entered_grid && !in_grid;
80 case child:
82 }
83
84 assert(false);
85 return true;
86}
87
89{
90 switch(level) {
91 case self:
92 return widget_;
93 case internal:
94 if(!in_grid || itor_ == container_.end()) {
95 return nullptr;
96 } else {
97 return *itor_;
98 }
99 case child:
101 return nullptr;
102 } else {
103 return *itor_;
104 }
105 }
106
107 assert(false);
108 return nullptr;
109}
110
111} // namespace gui2::iteration
iterator begin()
Definition grid.hpp:478
iterator end()
Definition grid.hpp:482
A walker for a gui2::container_base.
virtual state_t next(const level level)
Inherited from gui2::iteration::walker_base.
gui2::grid::iterator itor_
The iterator to the children of container_.
virtual bool at_end(const level level) const
Inherited from gui2::iteration::walker_base.
virtual gui2::widget * get(const level level)
Inherited from gui2::iteration::walker_base.
gui2::widget * widget_
The widget which the walker is attached to.
scrollbar_container(gui2::scrollbar_container &container)
Constructor.
bool entered_grid
Whether the grid has been yielded.
gui2::scrollbar_container & container_
The container which the walker is attached to.
level
The level to walk at.
Definition walker.hpp:35
@ internal
Visit its nested grid.
Definition walker.hpp:39
@ self
Visit the widget itself.
Definition walker.hpp:37
@ child
Visit the children of its nested grid.
Definition walker.hpp:41
state_t
The state of the walker.
Definition walker.hpp:49
@ invalid
When calling next the following it has the following results.
Definition walker.hpp:69
@ valid
When calling next the following it has the following results.
Definition walker.hpp:58
Base class for creating containers with one or two scrollbar(s).
Base class for all widgets.
Definition widget.hpp:55