On Thursday, 5 March 2020 at 06:48:53 UTC, Виталий Фадеев wrote:
Searching for beauty code implementation.
Goal is: Create new object with "custom initializer".
"custom initializer" - is function, executed in _ctor, in
object scope.
Main Goal is: "clean readable beauty code".
Like this and better:
class DataGrid : Base
{
this()
{
super();
CR!VBoxLayout({
sizeWidthMode = SIZE_MODE.PARENT;
sizeHeightMode = SIZE_MODE.PARENT;
CR!GridLayout({
id = "grid";
sizeWidthMode = SIZE_MODE.PARENT;
sizeHeightMode = SIZE_MODE.FIXED;
h = 400;
});
CR!HCenterLayout({
CR!(Pager!TextButton) ({
id = "pager";
});
});
});
}
}
class Base
{
T CR( T, F )( F func )
{
auto c = new T();
c.Apply( func );
return c;
}
void Apply( F )( F func )
{
func();
}
}
In code above created tree and configured nodes.
Trouble in code above is: "custom initializer" - executed in
DataGrid context.
How to execute "custom initializer" in VBoxLayout context and
keep readable beauty ?
Conceptual question.
How to implement next pseudo-code in D ?
VBoxLayout
sizeWidthMode = SIZE_MODE.PARENT
sizeHeightMode = SIZE_MODE.PARENT
GridLayout
id = "grid"
sizeWidthMode = SIZE_MODE.PARENT
sizeHeightMode = SIZE_MODE.FIXED
h = 400
HCenterLayout
Pager!TextButton
id = "pager"