Photon 1.0.0
Loading...
Searching...
No Matches
borders.h
Go to the documentation of this file.
1#ifndef LH_BORDERS_H
2#define LH_BORDERS_H
3
4#include "css_length.h"
5#include "types.h"
6#include "web_color.h"
7
8namespace litehtml
9{
11 {
15
20
22 {
23 width = val.width;
24 style = val.style;
25 color = val.color;
26 }
27
28 css_border& operator=(const css_border& val) = default;
29
30 string to_string() const;
31 };
32
33 struct border
34 {
35 int width;
38
40 {
41 width = 0;
43 }
44 border(const border& val)
45 {
46 width = val.width;
47 style = val.style;
48 color = val.color;
49 }
50 border(const css_border& val)
51 {
52 width = (int) val.width.val();
53 style = val.style;
54 color = val.color;
55 }
56 border& operator=(const border& val) = default;
58 {
59 width = (int) val.width.val();
60 style = val.style;
61 color = val.color;
62 return *this;
63 }
64 };
65
67 {
70
73
76
79
81 {
82 top_left_x = 0;
83 top_left_y = 0;
84 top_right_x = 0;
85 top_right_y = 0;
88 bottom_left_x = 0;
89 bottom_left_y = 0;
90 }
103 void operator += (const margins& mg)
104 {
105 top_left_x += mg.left;
106 top_left_y += mg.top;
107 top_right_x += mg.right;
108 top_right_y += mg.top;
109 bottom_right_x += mg.right;
111 bottom_left_x += mg.left;
112 bottom_left_y += mg.bottom;
113 fix_values();
114 }
115 void operator -= (const margins& mg)
116 {
117 top_left_x -= mg.left;
118 top_left_y -= mg.top;
119 top_right_x -= mg.right;
120 top_right_y -= mg.top;
121 bottom_right_x -= mg.right;
123 bottom_left_x -= mg.left;
124 bottom_left_y -= mg.bottom;
125 fix_values();
126 }
128 {
129 if (top_left_x < 0) top_left_x = 0;
130 if (top_left_y < 0) top_left_y = 0;
131 if (top_right_x < 0) top_right_x = 0;
132 if (top_right_y < 0) top_right_y = 0;
133 if (bottom_right_x < 0) bottom_right_x = 0;
134 if (bottom_right_y < 0) bottom_right_y = 0;
135 if (bottom_left_x < 0) bottom_left_x = 0;
136 if (bottom_left_y < 0) bottom_left_y = 0;
137 }
138 void fix_values(int width, int height)
139 {
140 fix_values();
141 int half_width = width / 2;
142 int half_height = height / 2;
143 auto fix_one = [&](int& radii_x, int& radii_y)
144 {
145 double factor = std::min((double) half_width / (double) radii_x, (double) half_height / (double) radii_y);
146 radii_x = (int) ((double) radii_x * factor);
147 radii_y = (int) ((double) radii_y * factor);
148 };
149
150 if(top_left_x > half_width || top_left_y > half_height)
151 {
152 fix_one(top_left_x, top_left_y);
153 }
154 if(top_right_x > half_width || top_right_y > half_height)
155 {
156 fix_one(top_right_x, top_right_y);
157 }
158 if(bottom_right_x > half_width || bottom_right_y > half_height)
159 {
161 }
162 if(bottom_left_x > half_width || bottom_left_y > half_height)
163 {
165 }
166 }
167 };
168
214
216 {
222
223 css_borders() = default;
224
225 bool is_visible() const
226 {
227 return left.width.val() != 0 || right.width.val() != 0 || top.width.val() != 0 || bottom.width.val() != 0;
228 }
229
231 {
232 left = val.left;
233 right = val.right;
234 top = val.top;
235 bottom = val.bottom;
236 radius = val.radius;
237 }
238
239 css_borders& operator=(const css_borders& val) = default;
240 string to_string() const
241 {
242 return "left: " + left.to_string() +
243 ", top: " + top.to_string() +
244 ", right: " + top.to_string() +
245 ", bottom: " + bottom.to_string();
246 }
247 };
248
249 struct borders
250 {
256
257 borders() = default;
258
259 borders(const borders& val)
260 {
261 left = val.left;
262 right = val.right;
263 top = val.top;
264 bottom = val.bottom;
265 radius = val.radius;
266 }
267
269 {
270 left = val.left;
271 right = val.right;
272 top = val.top;
273 bottom = val.bottom;
274 }
275
276 bool is_visible() const
277 {
278 return left.width != 0 || right.width != 0 || top.width != 0 || bottom.width != 0;
279 }
280
281 borders& operator=(const borders& val) = default;
282
284 {
285 left = val.left;
286 right = val.right;
287 top = val.top;
288 bottom = val.bottom;
289 return *this;
290 }
291 };
292}
293
294#endif // LH_BORDERS_H
Definition css_length.h:22
float val() const
Definition css_length.h:101
int calc_percent(int width) const
Definition css_length.h:115
Definition style.h:40
Definition background.h:12
border_style
Definition types.h:465
@ border_style_none
Definition types.h:466
Definition Bitmap.h:10
Definition borders.h:67
int bottom_right_y
Definition borders.h:75
int top_left_y
Definition borders.h:69
int bottom_right_x
Definition borders.h:74
border_radiuses()
Definition borders.h:80
int bottom_left_y
Definition borders.h:78
int top_left_x
Definition borders.h:68
int top_right_x
Definition borders.h:71
int top_right_y
Definition borders.h:72
void operator-=(const margins &mg)
Definition borders.h:115
border_radiuses & operator=(const border_radiuses &val)=default
void fix_values(int width, int height)
Definition borders.h:138
void fix_values()
Definition borders.h:127
border_radiuses(const border_radiuses &val)
Definition borders.h:91
void operator+=(const margins &mg)
Definition borders.h:103
int bottom_left_x
Definition borders.h:77
Definition borders.h:34
border()
Definition borders.h:39
border(const css_border &val)
Definition borders.h:50
border_style style
Definition borders.h:36
border(const border &val)
Definition borders.h:44
int width
Definition borders.h:35
border & operator=(const css_border &val)
Definition borders.h:57
web_color color
Definition borders.h:37
border & operator=(const border &val)=default
Definition borders.h:250
borders & operator=(const borders &val)=default
border_radiuses radius
Definition borders.h:255
borders(const borders &val)
Definition borders.h:259
borders & operator=(const css_borders &val)
Definition borders.h:283
bool is_visible() const
Definition borders.h:276
borders(const css_borders &val)
Definition borders.h:268
border left
Definition borders.h:251
border top
Definition borders.h:252
border right
Definition borders.h:253
border bottom
Definition borders.h:254
Definition borders.h:170
css_border_radius & operator=(const css_border_radius &val)=default
css_length top_right_x
Definition borders.h:174
css_border_radius(const css_border_radius &val)
Definition borders.h:185
css_length bottom_left_y
Definition borders.h:181
css_length bottom_right_y
Definition borders.h:178
css_length bottom_right_x
Definition borders.h:177
css_length bottom_left_x
Definition borders.h:180
css_length top_left_y
Definition borders.h:172
css_length top_right_y
Definition borders.h:175
css_length top_left_x
Definition borders.h:171
border_radiuses calc_percents(int width, int height) const
Definition borders.h:199
Definition borders.h:11
border_style style
Definition borders.h:13
web_color color
Definition borders.h:14
css_border & operator=(const css_border &val)=default
css_length width
Definition borders.h:12
css_border(const css_border &val)
Definition borders.h:21
string to_string() const
Definition css_borders.cpp:4
css_border()
Definition borders.h:16
Definition borders.h:216
css_border right
Definition borders.h:219
css_border left
Definition borders.h:217
bool is_visible() const
Definition borders.h:225
css_border_radius radius
Definition borders.h:221
string to_string() const
Definition borders.h:240
css_borders & operator=(const css_borders &val)=default
css_border top
Definition borders.h:218
css_borders(const css_borders &val)
Definition borders.h:230
css_border bottom
Definition borders.h:220
Definition types.h:62
int bottom
Definition types.h:66
int left
Definition types.h:63
int right
Definition types.h:64
int top
Definition types.h:65
Definition web_color.h:9