The Battle for Wesnoth  1.19.5+dev
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 
19 
20 #include "gui/widgets/widget.hpp"
21 
22 #include <cassert>
23 
25 {
26 
28 {
29 }
30 
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 
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
A walker for a gui2::styled_widget.
widget(gui2::widget &widget)
Constructor.
virtual gui2::widget * get(const level level)
Inherited from gui2::iteration::walker_base.
gui2::widget * widget_
The styled_widget which the walker is attached to.
virtual bool at_end(const level level) const
Inherited from gui2::iteration::walker_base.
virtual state_t next(const level level)
Inherited from gui2::iteration::walker_base.
level
The level to walk at.
Definition: walker.hpp:35
@ 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
Base class for all widgets.
Definition: widget.hpp:55