Nice readable code with initializer

Виталий Фадеев vital.fadeev at gmail.com
Fri Mar 6 16:02:35 UTC 2020


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";
                 }
             }
         }




More information about the Digitalmars-d-learn mailing list