ElementBox: wire the standard implementation for size allocation

...if the strategy does not impose an explicit size constraint,
then use the inherited layout functions from GTK
This commit is contained in:
Fischlurch 2022-09-25 22:17:44 +02:00
parent acaeb330c3
commit 36594cd774
3 changed files with 124 additions and 36 deletions

View file

@ -62,17 +62,11 @@ namespace widget {
ElementBoxWidget::~ElementBoxWidget() { }
ElementBoxWidget::Strategy
ElementBoxWidget::Config::buildLayoutStrategy()
{
return Strategy{"LoLoLo"};
}
Literal
ElementBoxWidget::Config::getIconID() const
{
///////////////////////////////////////////////////////////////////////////TICKET #1185 : implement logic to pick suitable icon...
return "track_enabled"; //////////////////////////////////////////////TICKET #1219 : maybe at leas a better generic placeholder icon...?
return "track_enabled"; //////////////////////////////////////////////TICKET #1219 : maybe at least a better generic placeholder icon...?
}
Gtk::IconSize
@ -83,9 +77,19 @@ namespace widget {
}
ElementBoxWidget::Strategy
ElementBoxWidget::Config::buildLayoutStrategy(ElementBoxWidget& widget)
{
Strategy strategy; //NOTE: relying on return-value-optimisation
///////////////////////////////////////////////////////////////////////////TICKET #1235 : evaluate size constraint here
return strategy;
}
ElementBoxWidget::ElementBoxWidget (Config config)
: Frame{}
, strategy_{config.buildLayoutStrategy()}
, strategy_{config.buildLayoutStrategy(*this)}
, label_{Gtk::ORIENTATION_HORIZONTAL}
, icon_{Gtk::StockID{config.getIconID()} ///////////////////////////////TICKET #1030 : use of stockIDs is deprecated; care for a more modern icon naming scheme
, config.getIconSize()}
@ -106,6 +110,56 @@ namespace widget {
}
/**
* Layout trend for ElementBoxWidget is nailed down (`final`) to "height-for-width".
* The reason is, some of the use cases entail placing the element box onto a canvas
* with horizontal extension calibrated to time units; doing so requires us to control
* the extension, which is delegated through the strategy
*/
Gtk::SizeRequestMode
ElementBoxWidget::get_request_mode_vfunc() const
{
return Gtk::SizeRequestMode::SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
/**
* Layout preferences are delegated through the Strategy
* - by default, the strategy will just invoke the inherited vfuncs
* - however, when a size constraint for the ElementBoxWidget must be observed,
* the strategy will control the extension of our child widgets (side-effect)
* and then just return the extension as dictated by the constraints
* @remark Based on the GTK-3.22 implementation code, we know that the minimum_width
* is only used for consistency checks (and otherwise ignored), while the natural_width
* will always be respected. The GKT layout management might _increase_ that value...
* - do adjust for additional border and margin settings from CSS
* - and to expand the widget when used within a container with fill-alignment
* Moreover the #get_preferred_height_for_width_vfunc will be invoked with the
* results from this function. The possible adjustment is done by invoking the
* vfunc `adjust_size_allocation` on the GTK-class, which typically delegates to
* gtk_widget_real_adjust_size_allocation, and the latter invokes
* - adjust_for_margin
* - adjust_for_align
* After these adjustments and some sanity checks, the resulting size allocation
* is passed to the `size_allocate` vfunc, which could be tapped on the Gtk::Widget
* C++ wrapper, but usually just stores this allocation into the widget private data.
*/
void
ElementBoxWidget::get_preferred_width_vfunc (int& minimum_width, int& natural_width) const
{
if (strategy_.is_size_constrained())
minimum_width = natural_width = strategy_.getWidth();
else
_Base::get_preferred_width_vfunc (minimum_width,natural_width);
}
void
ElementBoxWidget::get_preferred_height_for_width_vfunc (int width, int& minimum_height, int& natural_height) const
{
if (strategy_.is_size_constrained() and strategy_.shall_control_height())
minimum_height = natural_height = strategy_.getHeight();
else
_Base::get_preferred_height_for_width_vfunc (width, minimum_height,natural_height);
}

View file

@ -30,7 +30,7 @@
** that they combine some icon with a possibly abridged text and render
** them with a given indicator style, configurable via CSS. There is
** support for picking the icon and the indicator style based on some
** notion of _"type"._
** notion of _"type"._
**
** @todo WIP-WIP-WIP as of 11/2018 ///////////////////////////////////////////////////////////////////////TICKET #1185
** @todo WIP-WIP-WIP as of 9/2022 ///////////////////////////////////////////////////////////////////////TICKET #1219
@ -51,6 +51,7 @@
//#include <memory>
//#include <vector>
#include <functional>
#include <string> //////TODO debugging
@ -89,13 +90,21 @@ namespace widget {
* possibly a content renderer (e.g. for a video clip). Depending on the presentation intent,
* the widget can extend to a defined time range horizontally. Pre-defined styling and bindings
* to expand the display and to invoke a menu are provided
* @todo consider policy based design, //////////////////////////////////////////////////////////////////TICKET #1239 : re-evaluate Design, maybe use Policy Based Design
* but need more exposure and real world usage as of 9/22
*/
class ElementBoxWidget
: public Gtk::Frame
{
using _Base = Gtk::Frame;
using SizeGetter = std::function<int()>;
struct Strategy
{
string lambdaLaLa;
SizeGetter getWidth{};
SizeGetter getHeight{};
bool is_size_constrained() const { return bool(getWidth); }
bool shall_control_height() const { return bool(getHeight); }
};
/** actual layout strategy binding for this widget */
@ -115,11 +124,17 @@ namespace widget {
~ElementBoxWidget();
// default copy acceptable
private:/* ===== Internals ===== */
Gtk::SizeRequestMode get_request_mode_vfunc() const final;
void get_preferred_width_vfunc (int&, int&) const override;
void get_preferred_height_for_width_vfunc (int, int&,int&) const override;
_Base& getBase() { return *this; }
};
class ElementBoxWidget::Config
: lib::BuilderQualifierSupport<Config>
{
@ -140,7 +155,7 @@ namespace widget {
}
/** decide upon the presentation strategy */
Strategy buildLayoutStrategy();
Strategy buildLayoutStrategy(ElementBoxWidget&);
Literal getIconID() const;
Gtk::IconSize getIconSize() const;

View file

@ -17955,6 +17955,10 @@
<node CREATED="1664029840817" ID="ID_1206826425" MODIFIED="1664029866386" TEXT="dynamic Head-Placement"/>
</node>
</node>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1664132799979" ID="ID_1304690112" MODIFIED="1664133192469" TEXT="#1239 consider Policy Based Design for ElementBoxWidget">
<linktarget COLOR="#8d81ac" DESTINATION="ID_1304690112" ENDARROW="Default" ENDINCLINATION="654;32;" ID="Arrow_ID_1945811186" SOURCE="ID_1356714491" STARTARROW="None" STARTINCLINATION="942;-96;"/>
<icon BUILTIN="hourglass"/>
</node>
<node CREATED="1541087843514" ID="ID_1798999985" MODIFIED="1557498707223" TEXT="weit verbreiteter Grundbaustein">
<icon BUILTIN="idea"/>
<node CREATED="1541087865477" ID="ID_1163649496" MODIFIED="1557498707223" TEXT="f&#xfc;r Marker"/>
@ -18536,8 +18540,8 @@
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1661721393893" ID="ID_293134573" MODIFIED="1661721423931" TEXT="Validierungs-Funktion">
<linktarget COLOR="#c63166" DESTINATION="ID_293134573" ENDARROW="Default" ENDINCLINATION="64;-83;" ID="Arrow_ID_543159170" SOURCE="ID_1192772963" STARTARROW="None" STARTINCLINATION="-313;15;"/>
<linktarget COLOR="#404289" DESTINATION="ID_293134573" ENDARROW="Default" ENDINCLINATION="175;-873;" ID="Arrow_ID_1989504612" SOURCE="ID_1939158808" STARTARROW="None" STARTINCLINATION="768;94;"/>
<linktarget COLOR="#c63166" DESTINATION="ID_293134573" ENDARROW="Default" ENDINCLINATION="64;-83;" ID="Arrow_ID_543159170" SOURCE="ID_1192772963" STARTARROW="None" STARTINCLINATION="-313;15;"/>
<icon BUILTIN="flag-yellow"/>
<node CREATED="1662051084085" ID="ID_906734828" MODIFIED="1662051103543" TEXT="Strategy::configure()"/>
</node>
@ -18590,8 +18594,8 @@
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1662241925929" ID="ID_217944947" MODIFIED="1662241933868" TEXT="horizontale Ausdehnung">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1662241925929" ID="ID_217944947" MODIFIED="1664136727535" TEXT="horizontale Ausdehnung">
<icon BUILTIN="pencil"/>
<node CREATED="1663945598778" ID="ID_1866891133" MODIFIED="1663945862337" TEXT="Ansatz">
<icon BUILTIN="idea"/>
<node CREATED="1663945603065" ID="ID_1792803134" MODIFIED="1663945629088" TEXT="Mechanismus zur Gr&#xf6;&#xdf;enbeschr&#xe4;nkung auf dem Haupt-Widget"/>
@ -18630,8 +18634,8 @@
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664027101386" ID="ID_325165287" MODIFIED="1664027119181" TEXT="erforderliche Ausdehnung feststellen">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1664027101386" ID="ID_325165287" MODIFIED="1664136719643" TEXT="erforderliche Ausdehnung feststellen">
<icon BUILTIN="pencil"/>
<node CREATED="1664027121220" ID="ID_1123910943" MODIFIED="1664027234710" TEXT="f&#xfc;r das ElementBoxWidget stets in Pixel">
<richcontent TYPE="NOTE"><html>
<head>
@ -18645,8 +18649,8 @@
</html></richcontent>
<icon BUILTIN="yes"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664027274328" ID="ID_1533967380" MODIFIED="1664027327221" TEXT="Interaktionsmuster der Schnittstelle">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1664027274328" ID="ID_1533967380" MODIFIED="1664136711917" TEXT="Interaktionsmuster der Schnittstelle">
<icon BUILTIN="pencil"/>
<node COLOR="#435e98" CREATED="1664027342687" ID="ID_987588934" MODIFIED="1664028893912" TEXT="Analyse">
<icon BUILTIN="info"/>
<node CREATED="1664027374909" ID="ID_1916479707" MODIFIED="1664027563708" TEXT="Information wird von den GTK-Callbacks ben&#xf6;tigt">
@ -18771,9 +18775,9 @@
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664028811314" ID="ID_1790496772" MODIFIED="1664028821834" TEXT="die H&#xf6;hen-Angabe optional machen">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664028833680" ID="ID_822885755" MODIFIED="1664029036890" TEXT="Pr&#xe4;dikat: Erkennung size-constrained">
<node COLOR="#338800" CREATED="1664028833680" ID="ID_822885755" MODIFIED="1664136676337" TEXT="Pr&#xe4;dikat: Erkennung size-constrained">
<linktarget COLOR="#fff78b" DESTINATION="ID_822885755" ENDARROW="Default" ENDINCLINATION="-71;5;" ID="Arrow_ID_502040558" SOURCE="ID_10961106" STARTARROW="None" STARTINCLINATION="67;7;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
@ -18788,19 +18792,19 @@
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664029105419" ID="ID_1976797471" MODIFIED="1664029125271" TEXT="entweder per &#x3bb;">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664029112435" ID="ID_82095109" MODIFIED="1664030643111" TEXT="oder die Basis-Impl verwenden">
<node COLOR="#338800" CREATED="1664029112435" ID="ID_82095109" MODIFIED="1664136681131" TEXT="oder die Basis-Impl verwenden">
<arrowlink COLOR="#6873c6" DESTINATION="ID_986565985" ENDARROW="Default" ENDINCLINATION="31;1;" ID="Arrow_ID_1518071893" STARTARROW="None" STARTINCLINATION="-102;26;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664029128360" ID="ID_986565985" MODIFIED="1664030643111" TEXT="Aufruf der Basis-Impl vorsehen">
<node COLOR="#338800" CREATED="1664029128360" ID="ID_986565985" MODIFIED="1664136684354" TEXT="Aufruf der Basis-Impl vorsehen">
<linktarget COLOR="#6873c6" DESTINATION="ID_986565985" ENDARROW="Default" ENDINCLINATION="31;1;" ID="Arrow_ID_1518071893" SOURCE="ID_82095109" STARTARROW="None" STARTINCLINATION="-102;26;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664029223580" ID="ID_825294836" MODIFIED="1664029246522" TEXT="Framework zur Steuerung der Ausdehnung">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1664029223580" ID="ID_825294836" MODIFIED="1664136733333" TEXT="Framework zur Steuerung der Ausdehnung">
<icon BUILTIN="pencil"/>
<node CREATED="1664029250424" ID="ID_1097443082" MODIFIED="1664029265588" TEXT="hier erst mal nur das Fundament legen">
<icon BUILTIN="yes"/>
</node>
@ -18889,13 +18893,15 @@
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664054365436" ID="ID_74006008" MODIFIED="1664054707374" TEXT="Shared Strategy">
<linktarget COLOR="#fde2be" DESTINATION="ID_74006008" ENDARROW="Default" ENDINCLINATION="6;128;" ID="Arrow_ID_1045794051" SOURCE="ID_1399625126" STARTARROW="None" STARTINCLINATION="-266;36;"/>
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1664055105139" ID="ID_594735349" MODIFIED="1664055121994" TEXT="sind mehrfache Indirektionen ein Problem?">
<node COLOR="#435e98" CREATED="1664055105139" ID="ID_594735349" MODIFIED="1664136644965" TEXT="sind mehrfache Indirektionen ein Problem?">
<icon BUILTIN="help"/>
<node CREATED="1664055185035" ID="ID_1386788488" MODIFIED="1664055198439" TEXT="wir h&#xe4;tten konkrete Clip-delegates">
<icon BUILTIN="idea"/>
</node>
<node CREATED="1664055199606" ID="ID_1356714491" MODIFIED="1664055210233" TEXT="also doch policy based design?">
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1664055199606" ID="ID_1356714491" MODIFIED="1664133207079" TEXT="also doch policy based design?">
<arrowlink COLOR="#8d81ac" DESTINATION="ID_1304690112" ENDARROW="Default" ENDINCLINATION="654;32;" ID="Arrow_ID_1945811186" STARTARROW="None" STARTINCLINATION="942;-96;"/>
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
<icon BUILTIN="help"/>
<node CREATED="1664055305064" ID="ID_794765074" MODIFIED="1664055318882" TEXT="dann m&#xfc;&#xdf;te ElementBoxWidget von der Strategy erben"/>
<node CREATED="1664055333428" ID="ID_383670287" MODIFIED="1664055344687" TEXT="denn GTK verwendet bereits die VTable zur Differenzierung"/>
</node>
@ -18918,8 +18924,21 @@
<node CREATED="1664055541961" ID="ID_1385566332" MODIFIED="1664055595693" TEXT="reRender &#x27f9; bereits festgelegte Konfiguration + berechnetes Content-Pixmap"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664060239692" ID="ID_1617851912" MODIFIED="1664060250875" TEXT="also doch erst mal &quot;bodenst&#xe4;ndig&quot; beginnen">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
Aua!
</p>
<p>
f&#228;llt mir schwer... ich sehe andauernd die sp&#228;teren Probleme
</p>
</body>
</html></richcontent>
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="yes"/>
</node>
</node>
<node CREATED="1664054377646" ID="ID_309729651" MODIFIED="1664054397978" TEXT="nur eine Instanz pro Render-Methode">
@ -18935,8 +18954,8 @@
<icon BUILTIN="yes"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664055731547" ID="ID_1438169680" MODIFIED="1664055749953" TEXT="Daten der individuellen Instanz">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#435e98" CREATED="1664055731547" ID="ID_1438169680" MODIFIED="1664136751044" TEXT="Daten der individuellen Instanz">
<icon BUILTIN="info"/>
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1664055752785" ID="ID_1076715259" MODIFIED="1664055785130">
<richcontent TYPE="NODE"><html>
<head>
@ -19016,8 +19035,8 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1664060277055" ID="ID_319446276" MODIFIED="1664060297750" TEXT="Strategy als lokales Front-End anlegen">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1664060277055" ID="ID_319446276" MODIFIED="1664136766596" TEXT="Strategy als lokales Front-End anlegen">
<icon BUILTIN="pencil"/>
<node CREATED="1664060308706" ID="ID_346748114" MODIFIED="1664060333637" TEXT="gruppiert die w&#xe4;hlbaren Detail-Strategien und Binding-&#x3bb;"/>
<node CREATED="1664060335335" ID="ID_210836901" MODIFIED="1664060373437" TEXT="h&#xe4;lt die Informationen f&#xfc;r den Zugang zu den individuellen Instanz-Werten"/>
<node CREATED="1664060379716" ID="ID_853921300" MODIFIED="1664060395210" TEXT="und zwar insofern diese zur Verwendung der generischen Strategy notwendig sind"/>
@ -52473,8 +52492,8 @@
<node CREATED="1482524516371" ID="ID_396707258" MODIFIED="1557498707236" TEXT="Event-Sourcing">
<node CREATED="1539135156755" ID="ID_1302245670" MODIFIED="1557498707236" TEXT="vermittelnder Tr&#xe4;ger">
<node CREATED="1539134733747" ID="ID_1189184036" MODIFIED="1557498707236" TEXT="DiffConstituent">
<linktarget COLOR="#4e31e2" DESTINATION="ID_1189184036" ENDARROW="Default" ENDINCLINATION="-432;-65;" ID="Arrow_ID_1794591374" SOURCE="ID_1179407482" STARTARROW="None" STARTINCLINATION="-1379;-131;"/>
<linktarget COLOR="#4e31e2" DESTINATION="ID_1189184036" ENDARROW="Default" ENDINCLINATION="-767;-123;" ID="Arrow_ID_156898929" SOURCE="ID_353086867" STARTARROW="None" STARTINCLINATION="-1608;-84;"/>
<linktarget COLOR="#4e31e2" DESTINATION="ID_1189184036" ENDARROW="Default" ENDINCLINATION="-432;-65;" ID="Arrow_ID_1794591374" SOURCE="ID_1179407482" STARTARROW="None" STARTINCLINATION="-1379;-131;"/>
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
<node CREATED="1539134841549" ID="ID_818387120" MODIFIED="1557498707236" TEXT="neues Konzept">
<icon BUILTIN="idea"/>