Lumiera  0.pre.03
»edit your freedom«
element-box-widget.hpp
Go to the documentation of this file.
1 /*
2  ELEMENT-BOX-WIDGET.hpp - fundamental UI building block to represent a placed element
3 
4  Copyright (C) Lumiera.org
5  2018, 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 
49 #ifndef STAGE_WIDGET_ELEMENT_BOX_WIDGET_H
50 #define STAGE_WIDGET_ELEMENT_BOX_WIDGET_H
51 
52 #include "stage/gtk-base.hpp"
55 
56 #include "lib/format-string.hpp"
57 #include "lib/symbol.hpp"
58 
59 #include <functional>
60 #include <utility>
61 #include <string>
62 #include "lib/format-cout.hpp"
63 
64 
65 
66 namespace stage {
67 namespace widget {
68 
69  using std::move;
70  using lib::Literal;
71  using std::string;
72  using util::_Fmt;
73 
75  enum Kind { MARK
76  , SPAN
77  , ITEM
79  };
80 
82  enum Type { VIDEO
83  , AUDIO
84  , TEXT
85  , AUTO
86  , EVENT
87  , EFFECT
88  , LABEL
89  , RULER
90  , GROUP
91  , META
92  };
93 
94  using SizeGetter = std::function<int()>;
95 
96 
97 
108  class IDLabel
109  : public Gtk::Box
110  {
111  Gtk::Image imgIcon_;
112  Gtk::Image imgMenu_;
113  Gtk::Button icon_;
114  Gtk::Button menu_;
115  Gtk::Label name_;
116 
117  public:
118  ~IDLabel();
119  IDLabel(Literal iconID, Literal menuSymb, Gtk::IconSize);
120 
121  cuString getCaption() const;
122  void setCaption(cuString&);
123 
124  void imposeSizeConstraint(int, int);
125 
126  private:
127  Gtk::Requisition labelFullSize_{};
128  void adaptSize (int, int);
129  };
130 
131 
132 
133  /*************************************************************************/
144  : public Gtk::EventBox
145  {
146  using _Base = Gtk::EventBox;
147  struct Strategy
148  {
149  SizeGetter getWidth{};
150  SizeGetter getHeight{};
151 
152  bool is_size_constrained() const { return bool(getWidth); }
153  bool shall_control_height() const { return bool(getHeight); }
154  };
155 
158 
159  IDLabel label_;
160  Gtk::Frame frame_;
161 
162  public:
163  class Config;
164 
165  template<class... QS>
166  ElementBoxWidget (Kind kind, Type type, QS ...qualifiers);
167 
169  ~ElementBoxWidget();
170 
171  // default copy acceptable
172 
173  void setName(cuString&);
174  cuString getName() const;
175 
177  void set_label(cuString& s) { setName(s); }
178  cuString get_label() const { return getName(); }
179 
180  private:/* ===== Internals ===== */
181 
182  Gtk::SizeRequestMode get_request_mode_vfunc() const final;
183  void get_preferred_width_vfunc (int&, int&) const override;
184  void get_preferred_height_vfunc (int&, int&) const override;
185  void get_preferred_height_for_width_vfunc (int, int&,int&) const override;
186  void on_size_allocate (Gtk::Allocation&) override;
187 
188  void imposeSizeConstraint(int, int);
189  };
190 
191 
194  {
195  Type type_;
196  uString nameID_{"∅"};
197  SizeGetter widthConstraint_;
198  SizeGetter heightConstraint_;
199  string logTODO_{nameID_};
200 
201  friend Qualifier kind(Kind);
202  friend Qualifier name(string id);
203  friend Qualifier expander(model::Expander&);
204  friend Qualifier constrained(SizeGetter);
205  friend Qualifier constrained(SizeGetter,SizeGetter);
206 
207  public:
208  template<class... QS>
209  Config(Type type, Qualifier qual, QS... qs)
210  : type_{type}
211  {
212  qualify(*this, qual, qs...);
213  }
214 
216  Strategy buildLayoutStrategy(ElementBoxWidget&);
217 
218  Literal getIconID() const;
219  Literal getMenuSymb() const;
220  Gtk::IconSize getIconSize() const;
221 
222  cuString
223  getName() const
224  {
225  return nameID_;
226  }
227  };
228 
229 
231  inline ElementBoxWidget::Config::Qualifier
233  {
234  return ElementBoxWidget::Config::Qualifier{
235  [=](ElementBoxWidget::Config& config)
236  {
237  config.logTODO_ += util::_Fmt{"+kind(%s)"} % kind;
238  }};
239  }
240 
242  inline ElementBoxWidget::Config::Qualifier
243  name(string id)
244  {
245  return ElementBoxWidget::Config::Qualifier{
246  [=](ElementBoxWidget::Config& config)
247  {
248  config.nameID_ = id;
249  }};
250  }
251 
253  inline ElementBoxWidget::Config::Qualifier
255  {
256  return ElementBoxWidget::Config::Qualifier{
257  [&](ElementBoxWidget::Config& config)
258  {
259  config.logTODO_ += util::_Fmt{"+expander(%s)"} % &expander;
260  }};
261  }
262 
268  inline ElementBoxWidget::Config::Qualifier
269  constrained(SizeGetter widthConstraint)
270  {
271  return ElementBoxWidget::Config::Qualifier{
272  [wC=move(widthConstraint)](ElementBoxWidget::Config& config) -> void
273  {
274  config.widthConstraint_ = move(wC);
275  }};
276  }
277 
282  inline ElementBoxWidget::Config::Qualifier
283  constrained(SizeGetter widthConstraint, SizeGetter heightConstraint)
284  {
285  return ElementBoxWidget::Config::Qualifier{
286  [wC=move(widthConstraint),hC=move(heightConstraint)]
287  (ElementBoxWidget::Config& config) -> void
288  {
289  config.widthConstraint_ = move(wC);
290  config.heightConstraint_ = move(hC);
291  }};
292  }
293 
294 
295 
301  template<class... QS>
302  inline ElementBoxWidget::ElementBoxWidget (Kind widgetKind, Type type, QS ...qualifiers)
303  : ElementBoxWidget{Config(type, kind(widgetKind), qualifiers...)}
304  { }
305 
306 
307 }}// namespace stage::widget
308 #endif /*STAGE_WIDGET_ELEMENT_BOX_WIDGET_H*/
void set_label(cuString &s)
redirect Gtk::Frame setters to ElementBoxWidget
Automatically use custom string conversion in C++ stream output.
void adaptSize(int, int)
Multi-step procedure to keep this IDLabel widget within the given screen size constraints.
represents a container to group other entities
represents sound data
represents an overview ruler or TOC
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
A basic building block of the Lumiera UI.
Front-end for printf-style string template interpolation.
represents event streams or live connections
Widget represents an entity within a collection (Bin)
ElementBoxWidget(Kind kind, Type type, QS ...qualifiers)
setup an ElementBoxWidget with suitable presentation style.
Widget arrangement to represent an entity for manipulation.
A front-end for using printf-style formatting.
Mix-in to accept and apply an arbitrary sequence of qualifier functors.
Helper components to implement some standard UI-element actions by installing a functor.
Type
the type of content object to derive suitable styling (background colour, icon)
void imposeSizeConstraint(int, int)
Ensure the IDLabel stays within a given size constraint.
Marker types to indicate a literal string and a Symbol.
represents some meta entity
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
ElementBoxWidget::Config::Qualifier kind(Kind kind)
qualify the basic use case for the new ElementBoxWidget
represents text content
Widget spans a time range.
Widget is a pin or marks a position.
Strategy strategy_
actual layout strategy binding for this widget
represents moving (or still) image data
Mix-in to support builder functions to accept optional qualifier terms.
ElementBoxWidget::Config::Qualifier expander(model::Expander &expander)
provide an expand/collapse button, wired with the given Expander
represents automation
Functor component to support the default implementation of expanding/collapsing.
represents a label or descriptor
represents a processor or transformer
Widget serves to represent a piece of content (Clip)
A set of basic GTK includes for the UI.
ElementBoxWidget::Config::Qualifier constrained(SizeGetter widthConstraint)
switch in to size-constrained layout mode.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
Kind
the presentation intent for the ElementBoxWidget