The Battle for Wesnoth
1.19.7+dev
gui
auxiliary
iterator
walker_widget.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2011 - 2024
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
18
#include "
gui/auxiliary/iterator/walker_widget.hpp
"
19
20
#include "
gui/widgets/widget.hpp
"
21
22
#include <cassert>
23
24
namespace
gui2::iteration::walker
25
{
26
27
widget::widget
(
gui2::widget
&
widget
) : widget_(&
widget
)
28
{
29
}
30
31
walker_base::state_t
widget::next
(
const
level
level
)
32
{
33
if
(
at_end
(
level
)) {
34
return
fail
;
35
}
36
37
switch
(
level
) {
38
case
self
:
39
if
(
widget_
) {
40
widget_
=
nullptr
;
41
return
invalid
;
42
}
43
[[fallthrough]];
44
case
internal
:
45
case
child
:
46
break
;
47
}
48
49
assert(
false
);
50
return
fail
;
51
}
52
53
bool
widget::at_end
(
const
level
level
)
const
54
{
55
switch
(
level
) {
56
case
self
:
57
return
widget_
==
nullptr
;
58
case
internal
:
59
case
child
:
60
return
true
;
61
}
62
63
assert(
false
);
64
return
true
;
65
}
66
67
gui2::widget
*
widget::get
(
const
level
level
)
68
{
69
switch
(
level
) {
70
case
self
:
71
return
widget_
;
72
case
internal
:
73
case
child
:
74
return
nullptr
;
75
}
76
77
assert(
false
);
78
return
nullptr
;
79
}
80
81
}
// namespace gui2::iteration::walker
gui2::iteration::walker::widget
A walker for a gui2::styled_widget.
Definition:
walker_widget.hpp:25
gui2::iteration::walker::widget::widget
widget(gui2::widget &widget)
Constructor.
Definition:
walker_widget.cpp:27
gui2::iteration::walker::widget::get
virtual gui2::widget * get(const level level)
Inherited from gui2::iteration::walker_base.
Definition:
walker_widget.cpp:67
gui2::iteration::walker::widget::widget_
gui2::widget * widget_
The styled_widget which the walker is attached to.
Definition:
walker_widget.hpp:45
gui2::iteration::walker::widget::at_end
virtual bool at_end(const level level) const
Inherited from gui2::iteration::walker_base.
Definition:
walker_widget.cpp:53
gui2::iteration::walker::widget::next
virtual state_t next(const level level)
Inherited from gui2::iteration::walker_base.
Definition:
walker_widget.cpp:31
gui2::iteration::walker_base::level
level
The level to walk at.
Definition:
walker.hpp:35
gui2::iteration::walker_base::child
@ child
Visit the children of its nested grid.
Definition:
walker.hpp:41
gui2::iteration::walker_base::state_t
state_t
The state of the walker.
Definition:
walker.hpp:49
gui2::iteration::walker_base::invalid
@ invalid
When calling next the following it has the following results.
Definition:
walker.hpp:69
gui2::iteration::walker_base::fail
@ fail
Definition:
walker.hpp:79
gui2::widget
Base class for all widgets.
Definition:
widget.hpp:55
widget.hpp
gui2::iteration::walker
Definition:
walker_widget.cpp:25
walker_widget.hpp
Generated by
1.9.1