1 module rpui.primitives;
2 
3 import gapi.vec;
4 import std.conv : to;
5 import std.math;
6 public import rpui.alignment;
7 
8 alias utf32char = dchar;
9 alias utf32string = dstring;
10 
11 enum Orientation {horizontal, vertical}
12 
13 struct FrameRect {
14     float left = 0;
15     float top = 0;
16     float right = 0;
17     float bottom = 0;
18 
19     this(in float left, in float top, in float right, in float bottom) {
20         this.left = left;
21         this.top = top;
22         this.right = right;
23         this.bottom = bottom;
24     }
25 
26     this(in vec4 rect) {
27         this.left = rect.x;
28         this.top = rect.y;
29         this.right = rect.z;
30         this.bottom = rect.w;
31     }
32 
33     this(in Rect rect) {
34         this.left = rect.left;
35         this.top = rect.top;
36         this.right = rect.left + rect.width;
37         this.bottom = rect.top + rect.height;
38     }
39 }
40 
41 const emptyRect = Rect(0, 0, 0, 0);
42 const emptyFrameRect = FrameRect(0, 0, 0, 0);
43 
44 struct Rect {
45     float left;
46     float top;
47     float width;
48     float height;
49 
50     @property void point(in vec2 val) {
51         left = val.x;
52         top = val.y;
53     }
54 
55     @property void size(in vec2 val) {
56         width = val.x;
57         height = val.y;
58     }
59 
60     @property vec2 point() const {
61         return vec2(left, top);
62     }
63 
64     @property vec2 size() const {
65         return vec2(width, height);
66     }
67 
68     // piar of points: (left, top), (right, bottom)
69     @property FrameRect absolute() const {
70         return FrameRect(left, top, left + width, top + height);
71     }
72 
73     this(in float left, in float top, in float width, in float height) {
74         this.left = left;
75         this.top = top;
76         this.width = width;
77         this.height = height;
78     }
79 
80     this(in vec4 rect) {
81         this.left = rect.x;
82         this.top = rect.y;
83         this.width = rect.z;
84         this.height = rect.w;
85     }
86 
87     this(in FrameRect rect) {
88         this.left = rect.left;
89         this.top = rect.top;
90         this.width = abs(rect.right - rect.left);
91         this.height = abs(rect.bottom - rect.top);
92     }
93 
94     this(in vec2 point, in vec2 size) {
95         this.left = point.x;
96         this.top = point.y;
97         this.width = size.x;
98         this.height = size.y;
99     }
100 }
101 
102 struct IntRect {
103     int left;
104     int top;
105     int width;
106     int height;
107 
108     @property void point(in vec2i val) {
109         left = val.x;
110         top = val.y;
111     }
112 
113     @property void size(in vec2i val) {
114         width = val.x;
115         height = val.y;
116     }
117 
118     this(in int left, in int top, in int width, in int height) {
119         this.left = left;
120         this.top = top;
121         this.width = width;
122         this.height = height;
123     }
124 
125     this(in float left, in float top, in float width, in float height) {
126         this.left = to!(int)(left);
127         this.top = to!(int)(top);
128         this.width = to!(int)(width);
129         this.height = to!(int)(height);
130     }
131 
132     this(in Rect rect) {
133         this.left = to!(int)(rect.left);
134         this.top = to!(int)(rect.top);
135         this.width = to!(int)(rect.width);
136         this.height = to!(int)(rect.height);
137     }
138 
139     this(in vec4i rect) {
140         this.left = rect.x;
141         this.top = rect.y;
142         this.width = rect.z;
143         this.height = rect.w;
144     }
145 
146     this(in vec4 rect) {
147         this.left = to!(int)(rect.x);
148         this.top = to!(int)(rect.y);
149         this.width = to!(int)(rect.z);
150         this.height = to!(int)(rect.w);
151     }
152 
153     this(in vec2i point, in vec2i size) {
154         this.left = point.x;
155         this.top = point.y;
156         this.width = size.x;
157         this.height = size.y;
158     }
159 
160     this(in vec2 point, in vec2 size) {
161         this.left = to!(int)(point.x);
162         this.top = to!(int)(point.y);
163         this.width = to!(int)(size.x);
164         this.height = to!(int)(size.y);
165     }
166 
167     this(in FrameRect rect) {
168         this.left = to!int(rect.left);
169         this.top = to!int(rect.top);
170         this.width = abs(to!int(rect.right - rect.left));
171         this.height = abs(to!int(rect.bottom - rect.top));
172     }
173 }