digitalmars.D.learn - Nice readable code with initializer
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (46/46) Mar 04 2020 Searching for beauty code implementation.
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (14/60) Mar 04 2020 Conceptual question.
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (22/97) Mar 06 2020 Thank!
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 ?
Mar 04 2020
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"
Mar 04 2020
On Thursday, 5 March 2020 at 07:01:27 UTC, Виталий Фадеев wrote:On Thursday, 5 March 2020 at 06:48:53 UTC, Виталий Фадеев wrote:Thank! Now using like this: with ( CR!VBoxLayout ) { sizeWidthMode = SIZE_MODE.PARENT; sizeHeightMode = SIZE_MODE.PARENT; with ( CR!GridLayout ) { id = "grid"; sizeWidthMode = SIZE_MODE.PARENT; sizeHeightMode = SIZE_MODE.FIXED; h = 400; } with ( CR!HCenterLayout ) { with ( CR!( Pager!TextButton ) ) { id = "pager"; } } }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"
Mar 06 2020