The Battle for Wesnoth  1.15.12+dev
walker_widget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "gui/widgets/widget.hpp"
20 
21 #include <cassert>
22 
23 namespace gui2
24 {
25 
26 namespace iteration
27 {
28 
29 namespace walker
30 {
31 
32 widget::widget(gui2::widget& widget) : widget_(&widget)
33 {
34 }
35 
37 {
38  if(at_end(level)) {
39  return fail;
40  }
41 
42  switch(level) {
43  case self:
44  if(widget_) {
45  widget_ = nullptr;
46  return invalid;
47  }
48  [[fallthrough]];
49  case internal:
50  case child:
51  break;
52  }
53 
54  assert(false);
55  return fail;
56 }
57 
58 bool widget::at_end(const level level) const
59 {
60  switch(level) {
61  case self:
62  return widget_ == nullptr;
63  case internal:
64  case child:
65  return true;
66  }
67 
68  assert(false);
69  return true;
70 }
71 
73 {
74  switch(level) {
75  case self:
76  return widget_;
77  case internal:
78  case child:
79  return nullptr;
80  }
81 
82  assert(false);
83  return nullptr;
84 }
85 
86 } // namespace walker
87 
88 } // namespace iteration
89 
90 } // namespace gui2
When calling next the following it has the following results.
Definition: walker.hpp:68
level
The level to walk at.
Definition: walker.hpp:34
widget(gui2::widget &widget)
Constructor.
Base class for all widgets.
Definition: widget.hpp:49
Generic file dialog.
Definition: field-fwd.hpp:22
state_t
The state of the walker.
Definition: walker.hpp:48
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:40
gui2::widget * widget_
The styled_widget which the walker is attached to.