The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
walker_widget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2017 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 <cassert>
20 #include "gui/widgets/widget.hpp"
21 
22 namespace gui2
23 {
24 
25 namespace iteration
26 {
27 
28 namespace walker
29 {
30 
31 widget::widget(gui2::widget& widget) : widget_(&widget)
32 {
33 }
34 
36 {
37  if(at_end(level)) {
38  return fail;
39  }
40 
41  switch(level) {
42  case self:
43  if(widget_) {
44  widget_ = nullptr;
45  return invalid;
46  }
47  FALLTHROUGH;
48  case internal:
49  case child:
50  break;
51  }
52 
53  assert(false);
54  return fail;
55 }
56 
57 bool widget::at_end(const level level) const
58 {
59  switch(level) {
60  case self:
61  return widget_ == nullptr;
62  case internal:
63  case child:
64  return true;
65  }
66 
67  assert(false);
68  return true;
69 }
70 
72 {
73  switch(level) {
74  case self:
75  return widget_;
76  case internal:
77  case child:
78  return nullptr;
79  }
80 
81  assert(false);
82  return nullptr;
83 }
84 
85 } // namespace walker
86 
87 } // namespace iteration
88 
89 } // 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 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.
virtual bool at_end(const level level) const
Inherited from gui2::iteration::walker_base.