The Battle for Wesnoth  1.15.0-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 http://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 "global.hpp"
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:68
level
The level to walk at.
Definition: walker.hpp:34
widget(gui2::widget &widget)
Constructor.
Base class for all widgets.
Definition: widget.hpp:48
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.