Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
expander-revealer.hpp
Go to the documentation of this file.
1/*
2 EXPANDER-REVEALER.hpp - functor components for standard UI element actions
3
4 Copyright (C)
5 2018, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
53#ifndef STAGE_MODEL_EXPANDER_REVEALER_H
54#define STAGE_MODEL_EXPANDER_REVEALER_H
55
56
57#include "lib/error.hpp"
58
59#include <functional>
60#include <utility>
61
62
63namespace stage {
64namespace model {
65
66 using std::move;
67
68
77 {
78 public:
79 using ProbeFun = std::function<bool(void)>;
80 using ChangeFun = std::function<void(bool)>;
81
82 private:
85
86 public:
88 Expander(ProbeFun detectCurrExpansionState, ChangeFun expand_collapse)
89 : probeState_{move (detectCurrExpansionState)}
90 , changeState_{move (expand_collapse)}
91 {
92 ENSURE (canExpand());
93 }
94
95 bool
96 canExpand() const
97 {
98 return bool{probeState_}
99 and bool{changeState_};
100 }
101
102 explicit
103 operator bool() const
104 {
105 REQUIRE (canExpand());
106 return probeState_();
107 }
108
109 bool
110 operator() (bool shallExpand)
111 {
112 REQUIRE (canExpand());
113 bool currState = probeState_();
114 if (currState != shallExpand)
115 changeState_(shallExpand);
116 return currState;
117 }
118
119 /* === alternate "expressive" API === */
120 bool
121 expand (bool yes =true)
122 {
123 return this->operator() (yes);
124 }
125
126 bool
128 {
129 return expand (false);
130 }
131
132 bool
134 {
135 return bool{*this};
136 }
137 };
138
139
140
148 {
149 public:
150 using RevealeItFun = std::function<void()>;
151
152 private:
154
155 public:
157 Revealer(RevealeItFun how_to_uncover_the_element)
158 : revealIt_{move (how_to_uncover_the_element)}
159 {
160 ENSURE (canReveal());
161 }
162
163 bool
164 canReveal() const
165 {
166 return bool{revealIt_};
167 }
168
169 void
171 {
172 REQUIRE (canReveal());
173 revealIt_();
174 }
175 };
176
177
178
179}} // namespace stage::model
180#endif /*STAGE_MODEL_EXPANDER_REVEALER_H*/
Functor component to support the default implementation of expanding/collapsing.
std::function< bool(void)> ProbeFun
Expander(ProbeFun detectCurrExpansionState, ChangeFun expand_collapse)
bool expand(bool yes=true)
bool operator()(bool shallExpand)
std::function< void(bool)> ChangeFun
Functor component to support the default implementation of revealing an UI-Element.
std::function< void()> RevealeItFun
Revealer(RevealeItFun how_to_uncover_the_element)
Lumiera error handling (C++ interface).
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37