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)
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 
40 #ifndef STAGE_WIDGET_ELEMENT_BOX_WIDGET_H
41 #define STAGE_WIDGET_ELEMENT_BOX_WIDGET_H
42 
43 #include "stage/gtk-base.hpp"
46 
47 #include "lib/format-string.hpp"
48 #include "lib/symbol.hpp"
49 
50 #include <functional>
51 #include <utility>
52 #include <string>
53 #include "lib/format-cout.hpp"
54 
55 
56 
57 namespace stage {
58 namespace widget {
59 
60  using std::move;
61  using lib::Literal;
62  using std::string;
63  using util::_Fmt;
64 
66  enum Kind { MARK
67  , SPAN
68  , ITEM
70  };
71 
73  enum Type { VIDEO
74  , AUDIO
75  , TEXT
76  , AUTO
77  , EVENT
78  , EFFECT
79  , LABEL
80  , RULER
81  , GROUP
82  , META
83  };
84 
85  using SizeGetter = std::function<int()>;
86 
87 
88 
99  class IDLabel
100  : public Gtk::Box
101  {
102  Gtk::Image imgIcon_;
103  Gtk::Image imgMenu_;
104  Gtk::Button icon_;
105  Gtk::Button menu_;
106  Gtk::Label name_;
107 
108  public:
109  ~IDLabel();
110  IDLabel(Literal iconID, Literal menuSymb, Gtk::IconSize);
111 
112  cuString getCaption() const;
113  void setCaption(cuString&);
114 
115  void imposeSizeConstraint(int, int);
116 
117  private:
118  Gtk::Requisition labelFullSize_{};
119  void adaptSize (int, int);
120  };
121 
122 
123 
124  /*************************************************************************/
135  : public Gtk::EventBox
136  {
137  using _Base = Gtk::EventBox;
138  struct Strategy
139  {
140  SizeGetter getWidth{};
141  SizeGetter getHeight{};
142 
143  bool is_size_constrained() const { return bool(getWidth); }
144  bool shall_control_height() const { return bool(getHeight); }
145  };
146 
149 
150  IDLabel label_;
151  Gtk::Frame frame_;
152 
153  public:
154  class Config;
155 
156  template<class... QS>
157  ElementBoxWidget (Kind kind, Type type, QS ...qualifiers);
158 
160  ~ElementBoxWidget();
161 
162  // default copy acceptable
163 
164  void setName(cuString&);
165  cuString getName() const;
166 
168  void set_label(cuString& s) { setName(s); }
169  cuString get_label() const { return getName(); }
170 
171  private:/* ===== Internals ===== */
172 
173  Gtk::SizeRequestMode get_request_mode_vfunc() const final;
174  void get_preferred_width_vfunc (int&, int&) const override;
175  void get_preferred_height_vfunc (int&, int&) const override;
176  void get_preferred_height_for_width_vfunc (int, int&,int&) const override;
177  void on_size_allocate (Gtk::Allocation&) override;
178 
179  void imposeSizeConstraint(int, int);
180  };
181 
182 
185  {
186  Type type_;
187  uString nameID_{"∅"};
188  SizeGetter widthConstraint_;
189  SizeGetter heightConstraint_;
190  string logTODO_{nameID_};
191 
192  friend Qualifier kind(Kind);
193  friend Qualifier name(string id);
194  friend Qualifier expander(model::Expander&);
195  friend Qualifier constrained(SizeGetter);
196  friend Qualifier constrained(SizeGetter,SizeGetter);
197 
198  public:
199  template<class... QS>
200  Config(Type type, Qualifier qual, QS... qs)
201  : type_{type}
202  {
203  qualify(*this, qual, qs...);
204  }
205 
207  Strategy buildLayoutStrategy(ElementBoxWidget&);
208 
209  Literal getIconID() const;
210  Literal getMenuSymb() const;
211  Gtk::IconSize getIconSize() const;
212 
213  cuString
214  getName() const
215  {
216  return nameID_;
217  }
218  };
219 
220 
222  inline ElementBoxWidget::Config::Qualifier
224  {
225  return ElementBoxWidget::Config::Qualifier{
226  [=](ElementBoxWidget::Config& config)
227  {
228  config.logTODO_ += util::_Fmt{"+kind(%s)"} % kind;
229  }};
230  }
231 
233  inline ElementBoxWidget::Config::Qualifier
234  name(string id)
235  {
236  return ElementBoxWidget::Config::Qualifier{
237  [=](ElementBoxWidget::Config& config)
238  {
239  config.nameID_ = id;
240  }};
241  }
242 
244  inline ElementBoxWidget::Config::Qualifier
246  {
247  return ElementBoxWidget::Config::Qualifier{
248  [&](ElementBoxWidget::Config& config)
249  {
250  config.logTODO_ += util::_Fmt{"+expander(%s)"} % &expander;
251  }};
252  }
253 
259  inline ElementBoxWidget::Config::Qualifier
260  constrained(SizeGetter widthConstraint)
261  {
262  return ElementBoxWidget::Config::Qualifier{
263  [wC=move(widthConstraint)](ElementBoxWidget::Config& config) -> void
264  {
265  config.widthConstraint_ = move(wC);
266  }};
267  }
268 
273  inline ElementBoxWidget::Config::Qualifier
274  constrained(SizeGetter widthConstraint, SizeGetter heightConstraint)
275  {
276  return ElementBoxWidget::Config::Qualifier{
277  [wC=move(widthConstraint),hC=move(heightConstraint)]
278  (ElementBoxWidget::Config& config) -> void
279  {
280  config.widthConstraint_ = move(wC);
281  config.heightConstraint_ = move(hC);
282  }};
283  }
284 
285 
286 
292  template<class... QS>
293  inline ElementBoxWidget::ElementBoxWidget (Kind widgetKind, Type type, QS ...qualifiers)
294  : ElementBoxWidget{Config(type, kind(widgetKind), qualifiers...)}
295  { }
296 
297 
298 }}// namespace stage::widget
299 #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:76
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:37
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