www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - b.content.x - get property of ...structure|class|...

reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
Main goal is: get content "xywh" from given rect and padding.
Of course content.x is dynamic.

//
import core.sys.windows.windows;
import std.stdio;


class Base
{
     RECT rect    = { 0, 0, 500, 400 };
     RECT padding = { 10, 10, 10, 10 };

     // ...content...
     ??? content
     {
          property int x() const { return rect.left + 
padding.left; }
     }
}

int main()
{
     auto b = new Base();
     writeln( b.content.x );
}



How to implement "b.content.x" ( sequence call "content" of the 
"b" and then "x" of that ) ?
How to implement beauty ?
Mar 17 2020
parent =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Tuesday, 17 March 2020 at 09:31:21 UTC, Виталий Фадеев wrote:
 Main goal is: get content "xywh" from given rect and padding.
 Of course content.x is dynamic.

 //
 import core.sys.windows.windows;
 import std.stdio;


 class Base
 {
     RECT rect    = { 0, 0, 500, 400 };
     RECT padding = { 10, 10, 10, 10 };

     // ...content...
     ??? content
     {
          property int x() const { return rect.left + 
 padding.left; }
     }
 }

 int main()
 {
     auto b = new Base();
     writeln( b.content.x );
 }



 How to implement "b.content.x" ( sequence call "content" of the 
 "b" and then "x" of that ) ?
 How to implement beauty ?
Now working with this variant: struct Content { Base This; int left() { return This.rect.left + This.padding.left; } int right() { return This.rect.right - This.padding.right; } int top() { return This.rect.top + This.padding.top; } int bottom() { return This.rect.bottom - This.padding.bottom; } int x() { return left; } int y() { return top; } int w() { return right - left; } int h() { return bottom - top; } RECT rect() { return This.rect; } } class Base { RECT rect; RECT padding; Content content() { return Content( this ); } }
Mar 17 2020