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)
5  2015, 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 
120 #ifndef STAGE_MODEL_TANGIBLE_H
121 #define STAGE_MODEL_TANGIBLE_H
122 
123 
124 #include "lib/error.hpp"
125 #include "lib/nocopy.hpp"
126 #include "stage/ctrl/bus-term.hpp"
128 #include "lib/diff/diff-mutable.hpp"
129 #include "lib/idi/entry-id.hpp"
130 #include "lib/symbol.hpp"
131 
132 #include <sigc++/trackable.h>
133 #include <utility>
134 #include <string>
135 
136 
137 namespace stage {
138 namespace model {
139 
140  using std::string;
141  using lib::Symbol;
142 
143 
156  class Tangible
157  : public sigc::trackable
158  , public lib::diff::DiffMutable
160  {
161  public:
162  using ID = ctrl::BusTerm::ID;
163  using LuidH = lib::hash::LuidH;
164  protected:
165  using Rec = lib::diff::Rec;
166  using GenNode = lib::diff::GenNode;
167 
168  ctrl::BusTerm uiBus_;
169 
170  Expander expand_;
171  Revealer reveal_;
172 
173 
174  Tangible(ID identity, ctrl::BusTerm& nexus)
175  : uiBus_{nexus.attach(identity, *this)}
176  , expand_{}
177  , reveal_{}
178  { }
179 
180  public:
181  virtual ~Tangible();
182 
183  operator string() const;
184  operator LuidH() const { return uiBus_.getID().getHash(); }
185 
186  ID getID() const { return uiBus_.getID();}
187 
188  void reset();
189  void clearMsg();
190  void clearErr();
191 
192  template<typename...ARGS>
193  void invoke (Symbol cmdID, ARGS&&...);
194  void invoke (Symbol cmdID, Rec&& arguments);
195 
196  void slotExpand();
197  void slotCollapse();
198  void slotReveal();
199 
200  void markFlash();
201  void markMsg (string message);
202  void markErr (string error);
203  void mark(GenNode const&);
204 
205  void installExpander (Expander::ProbeFun, Expander::ChangeFun);
206  void installRevealer (Revealer::RevealeItFun);
207 
208  protected:
209  virtual bool doReset() =0;
210  virtual bool doClearMsg() =0;
211  virtual bool doClearErr() =0;
212  virtual bool doExpand (bool yes);
213  virtual void doReveal ();
214 
215  virtual bool doMsg (string) =0;
216  virtual bool doErr (string) =0;
217  virtual void doFlash() =0;
218  virtual void doMark(GenNode const&) =0;
219 
220  public:
222 
223 
228  friend constexpr size_t
230  {
231  return 512;
232  }
233  };
234 
235 
236 
240  template<typename...ARGS>
241  inline lib::diff::GenNode
242  commandMessage (Symbol cmdID, ARGS&&... args)
243  {
244  using lib::diff::Rec;
245  using lib::diff::GenNode;
246  using GenNodeIL = std::initializer_list<GenNode>;
247 
248 
249  return GenNode (string{cmdID},
250  Rec(Rec::TYPE_NIL_SYM
251  ,GenNodeIL{}
252  ,GenNodeIL {std::forward<ARGS> (args)...}));
253  } // not typed, no attributes, all arguments as children
254 
255 
257  template<typename...ARGS>
258  inline void
259  Tangible::invoke (Symbol cmdID, ARGS&&... args)
260  {
261  uiBus_.act (commandMessage (cmdID, std::forward<ARGS> (args)...));
262  }
263 
264 
272  inline void
273  Tangible::installExpander (Expander::ProbeFun detectCurrExpansionState,
274  Expander::ChangeFun howto_expand_collapse)
275  {
276  expand_ = Expander{move (detectCurrExpansionState), move (howto_expand_collapse)};
277  }
278 
279 
287  inline void
288  Tangible::installRevealer (Revealer::RevealeItFun how_to_uncover_the_element)
289  {
290  reveal_ = Revealer{move (how_to_uncover_the_element)};
291  }
292 
293 
294 
295 
296 }} // namespace stage::model
297 #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:37
friend constexpr size_t treeMutatorSize(const Tangible *)
override default size traits for diff application.
Definition: tangible.hpp:229
void slotExpand()
Expand this element and remember the expanded state.
Definition: tangible.cpp:161
connection point at the UI-Bus.
Definition: bus-term.hpp:96
void installRevealer(Revealer::RevealeItFun)
Configure the (optional) functionality to bring the UI-Element into sight.
Definition: tangible.hpp:288
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:65
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
void mark(GenNode const &)
generic handler for all incoming "state mark" messages
Definition: tangible.cpp:251
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:187
Attachment point to the UI-Bus.
void clearMsg()
invoke the hook to clear notification messages
Definition: tangible.cpp:98
Token or Atom with distinct identity.
Definition: symbol.hpp:117
BusTerm attach(ID, Tangible &newNode)
Builder function: establish and wire a new BusTerm.
Definition: ui-bus.cpp:103
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:130
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:104
void markFlash()
highlight the element visually to catch the user&#39;s attention
Definition: tangible.cpp:110
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:141
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
virtual void doMark(GenNode const &)=0
default implementation and catch-all handler for receiving »state mark« messages. ...
Definition: tangible.cpp:286
lib::diff::GenNode commandMessage(Symbol cmdID, ARGS &&... args)
convenience shortcut to build a message suitable for command invocation
Definition: tangible.hpp:242
virtual void doReveal()
generic default implementation of the "reveal" functionality.
Definition: tangible.cpp:225
void slotCollapse()
Collapse or minimise this element and remember the collapsed state.
Definition: tangible.cpp:173
void installExpander(Expander::ProbeFun, Expander::ChangeFun)
Configure the (optional) functionality to expand or collapse the UI-Element.
Definition: tangible.hpp:273
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:156
void clearErr()
invoke the hook to clear error markers
Definition: tangible.cpp:87
object-like record of data.
Definition: record.hpp:141
virtual void act(GenNode const &command)
prepare or trigger invocation of a command.
Definition: ui-bus.cpp:130
generic data element node within a tree
Definition: gen-node.hpp:222
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:213