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