www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Nice readable code with initializer

reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
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
parent reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
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
parent =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Thursday, 5 March 2020 at 07:01:27 UTC, Виталий Фадеев wrote:
 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"
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"; } } }
Mar 06 2020