Lumiera  0.pre.03
»edit your freedom«
tangible.hpp
Go to the documentation of this file.
1 /*
2  TANGIBLE.hpp - a tangible element of the user interface
3 
4  Copyright (C) Lumiera.org
5  2015, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
129 #ifndef STAGE_MODEL_TANGIBLE_H
130 #define STAGE_MODEL_TANGIBLE_H
131 
132 
133 #include "lib/error.hpp"
134 #include "lib/nocopy.hpp"
135 #include "stage/ctrl/bus-term.hpp"
137 #include "lib/diff/diff-mutable.hpp"
138 #include "lib/idi/entry-id.hpp"
139 #include "lib/symbol.hpp"
140 
141 #include <sigc++/trackable.h>
142 #include <utility>
143 #include <string>
144 
145 
146 namespace stage {
147 namespace model {
148 
149  using std::string;
150  using lib::Symbol;
151 
152 
165  class Tangible
166  : public sigc::trackable
167  , public lib::diff::DiffMutable
169  {
170  public:
171  using ID = ctrl::BusTerm::ID;
172  using LuidH = lib::hash::LuidH;
173  protected:
174  using Rec = lib::diff::Rec;
175  using GenNode = lib::diff::GenNode;
176 
177  ctrl::BusTerm uiBus_;
178 
179  Expander expand_;
180  Revealer reveal_;
181 
182 
183  Tangible(ID identity, ctrl::BusTerm& nexus)
184  : uiBus_{nexus.attach(identity, *this)}
185  , expand_{}
186  , reveal_{}
187  { }
188 
189  public:
190  virtual ~Tangible();
191 
192  operator string() const;
193  operator LuidH() const { return uiBus_.getID().getHash(); }
194 
195  ID getID() const { return uiBus_.getID();}
196 
197  void reset();
198  void clearMsg();
199  void clearErr();
200 
201  template<typename...ARGS>
202  void invoke (Symbol cmdID, ARGS&&...);
203  void invoke (Symbol cmdID, Rec&& arguments);
204 
205  void slotExpand();
206  void slotCollapse();
207  void slotReveal();
208 
209  void markFlash();
210  void markMsg (string message);
211  void markErr (string error);
212  void mark(GenNode const&);
213 
214  void installExpander (Expander::ProbeFun, Expander::ChangeFun);
215  void installRevealer (Revealer::RevealeItFun);
216 
217  protected:
218  virtual bool doReset() =0;
219  virtual bool doClearMsg() =0;
220  virtual bool doClearErr() =0;
221  virtual bool doExpand (bool yes);
222  virtual void doReveal ();
223 
224  virtual bool doMsg (string) =0;
225  virtual bool doErr (string) =0;
226  virtual void doFlash() =0;
227  virtual void doMark(GenNode const&) =0;
228 
229  public:
231 
232 
237  friend constexpr size_t
239  {
240  return 512;
241  }
242  };
243 
244 
245 
249  template<typename...ARGS>
250  inline lib::diff::GenNode
251  commandMessage (Symbol cmdID, ARGS&&... args)
252  {
253  using lib::diff::Rec;
254  using lib::diff::GenNode;
255  using GenNodeIL = std::initializer_list<GenNode>;
256 
257 
258  return GenNode (string{cmdID},
259  Rec(Rec::TYPE_NIL_SYM
260  ,GenNodeIL{}
261  ,GenNodeIL {std::forward<ARGS> (args)...}));
262  } // not typed, no attributes, all arguments as children
263 
264 
266  template<typename...ARGS>
267  inline void
268  Tangible::invoke (Symbol cmdID, ARGS&&... args)
269  {
270  uiBus_.act (commandMessage (cmdID, std::forward<ARGS> (args)...));
271  }
272 
273 
281  inline void
282  Tangible::installExpander (Expander::ProbeFun detectCurrExpansionState,
283  Expander::ChangeFun howto_expand_collapse)
284  {
285  expand_ = Expander{move (detectCurrExpansionState), move (howto_expand_collapse)};
286  }
287 
288 
296  inline void
297  Tangible::installRevealer (Revealer::RevealeItFun how_to_uncover_the_element)
298  {
299  reveal_ = Revealer{move (how_to_uncover_the_element)};
300  }
301 
302 
303 
304 
305 }} // namespace stage::model
306 #endif /*STAGE_MODEL_TANGIBLE_H*/
Abstraction or descriptor interface for a data structure exposing the ability for mutation by receivi...
virtual ~Tangible()
this is an interface
Definition: tangible.cpp:46
friend constexpr size_t treeMutatorSize(const Tangible *)
override default size traits for diff application.
Definition: tangible.hpp:238
void slotExpand()
Expand this element and remember the expanded state.
Definition: tangible.cpp:170
connection point at the UI-Bus.
Definition: bus-term.hpp:105
void installRevealer(Revealer::RevealeItFun)
Configure the (optional) functionality to bring the UI-Element into sight.
Definition: tangible.hpp:297
virtual void buildMutator(lib::diff::TreeMutator::Handle)=0
build a custom implementation of the TreeMutator interface, suitably wired to cause appropriate chang...
void reset()
invoke the generic reset hook
Definition: tangible.cpp:74
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
void mark(GenNode const &)
generic handler for all incoming "state mark" messages
Definition: tangible.cpp:260
Helper components to implement some standard UI-element actions by installing a functor.
Functor component to support the default implementation of revealing an UI-Element.
virtual bool doExpand(bool yes)
generic default implementation of the expand/collapse functionality.
Definition: tangible.cpp:196
Attachment point to the UI-Bus.
void clearMsg()
invoke the hook to clear notification messages
Definition: tangible.cpp:107
Token or Atom with distinct identity.
Definition: symbol.hpp:126
BusTerm attach(ID, Tangible &newNode)
Builder function: establish and wire a new BusTerm.
Definition: ui-bus.cpp:112
Mix-Ins to allow or prohibit various degrees of copying and cloning.
void markMsg(string message)
push a notification (or warning) message to the element.
Definition: tangible.cpp:139
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:113
void markFlash()
highlight the element visually to catch the user&#39;s attention
Definition: tangible.cpp:119
Marker types to indicate a literal string and a Symbol.
void markErr(string error)
push an error state tag to the element
Definition: tangible.cpp:150
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
virtual void doMark(GenNode const &)=0
default implementation and catch-all handler for receiving »state mark« messages. ...
Definition: tangible.cpp:295
lib::diff::GenNode commandMessage(Symbol cmdID, ARGS &&... args)
convenience shortcut to build a message suitable for command invocation
Definition: tangible.hpp:251
virtual void doReveal()
generic default implementation of the "reveal" functionality.
Definition: tangible.cpp:234
void slotCollapse()
Collapse or minimise this element and remember the collapsed state.
Definition: tangible.cpp:182
void installExpander(Expander::ProbeFun, Expander::ChangeFun)
Configure the (optional) functionality to expand or collapse the UI-Element.
Definition: tangible.hpp:282
Lumiera error handling (C++ interface).
Hash implementation based on a lumiera unique object id (LUID) When invoking the default ctor...
Functor component to support the default implementation of expanding/collapsing.
Bare symbolic and hash ID used for accounting of asset like entries.
Interface common to all UI elements of relevance for the Lumiera application.
Definition: tangible.hpp:165
void clearErr()
invoke the hook to clear error markers
Definition: tangible.cpp:96
object-like record of data.
Definition: record.hpp:150
virtual void act(GenNode const &command)
prepare or trigger invocation of a command.
Definition: ui-bus.cpp:139
generic data element node within a tree
Definition: gen-node.hpp:231
Marker or capability interface: an otherwise not further disclosed data structure, which can be transformed through "tree diff messages".
void slotReveal()
Cause the element to be brought into sight.
Definition: tangible.cpp:222