Webdar 1.0.0
Web user interface to libdar
css.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef CSS_HPP
25#define CSS_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <string>
36#include <deque>
37#include <map>
38
39 // webdar headers
40#include "css_property.hpp"
41
43
46
47class css
48{
49public:
50
51 css() { clear(); };
52 css(const css & ref) = default;
53 css(css && ref) noexcept = default;
54 css & operator = (const css & ref) = default;
55 css & operator = (css && ref) noexcept = default;
56 virtual ~css() = default;
57
59 void update_from(const css & ref);
60
62 void clear();
63
64 // colors
65
66 void css_color(const std::string & col);
67 void css_background_color(const std::string & col);
68 void css_background_color() { bg_col.clear(); }; // unset previously set value
69
70 // background image
71
72 void css_background_image(const std::string & url,
73 bool repeat_x,
74 bool repeat_y,
75 bool fixed);
76 void css_background_image() { bg_img.clear(); };
77
78 void css_background_position(const std::string & x,
79 const std::string & y);
80 void css_background_position() { img_pos.clear(); };
81
82 // shadow
83 void css_box_shadow() { box_shadow.clear(); };
84 void css_box_shadow(const std::string & x_shift,
85 const std::string & y_shift,
86 const std::string & blur_size,
87 const std::string & color = "#444444");
88
89 void css_text_shadow() { text_shadow.clear(); };
90 void css_text_shadow(const std::string & x_shift,
91 const std::string & y_shift,
92 const std::string & blur_size,
93 const std::string & color = "#444444");
94
95 // position in the window
96
97 void css_margin(const std::string & all);
98 void css_margin() { css_margin_top(); css_margin_right(); css_margin_bottom(); css_margin_left(); };
99 void css_margin_top(const std::string & top);
100 void css_margin_top() { margin_top.clear(); };
101 void css_margin_right(const std::string & right);
102 void css_margin_right() { margin_right.clear(); };
103 void css_margin_bottom(const std::string & bottom);
104 void css_margin_bottom() { margin_bottom.clear(); };
105 void css_margin_left(const std::string & left);
106 void css_margin_left() { margin_left.clear(); };
107 void css_height(const std::string & val,
108 bool center);
109 void css_height() { height.clear(); };
110 void css_min_height(const std::string & val);
111 void css_min_height() { min_height.clear(); };
112 void css_max_height(const std::string & val);
113 void css_max_height() { max_height.clear(); };
114 void css_width(const std::string & val,
115 bool center);
116 void css_width() { width.clear(); };
117 void css_min_width(const std::string & val);
118 void css_min_width() { min_width.clear(); };
119 void css_max_width(const std::string & val);
120 void css_max_width() { max_width.clear(); };
121 void css_z_index(unsigned int index);
122 void css_z_index() { z_index.clear(); };
123
128 };
129
130 void css_position_type(positionning val);
131 void css_position_type() { position_type.clear(); };
132 void css_position_top(const std::string & top);
133 void css_position_top() { position_top.clear(); };
134 void css_position_left(const std::string & left);
135 void css_position_left() { position_left.clear(); };
136 void css_position_bottom(const std::string & bottom);
137 void css_position_bottom() { position_bottom.clear(); };
138 void css_position_right(const std::string & right);
139 void css_position_right() { position_right.clear(); };
140
141 enum overflowing { ov_visible, // show even what exceed the parent dimensions
142 ov_hidden, //< do not show what exceeds the parent dimensions
143 ov_scroll, //< alsways add a scrollbar to see what's hidden
144 ov_auto, //< scrollbar shows only if necessary
145 ov_inherit }; //< inherited from HTML parent
146
148
150 void css_overflow(overflowing val);
151
153 void css_overflow_x(overflowing val);
154
156 void css_overflow_y(overflowing val);
157
159 void css_overflow() { overflow.clear(); };
160
161 // floating
162
163 enum floating { fl_left,
164 fl_right,
165 fl_none };
166
167 enum floatclear { fc_left,
168 fc_right,
169 fc_both,
170 fc_none };
171
172 void css_float(floating val);
173 void css_float() { float_pos.clear(); };
174 void css_float_clear(floatclear val);
175 void css_float_clear() { float_clear.clear(); };
176
177 // opacity
178
179 void css_opacity(const std::string & opacity);
180
181
182 // padding
183
185 {
187 bx_border
188 };
189
190 void css_box_sizing(bx_sizing val);
191
192 void css_display(const std::string & val);
193
194 void css_padding(const std::string & val);
195 void css_padding() { css_padding_top(); css_padding_right(); css_padding_bottom(); css_padding_left(); };
196 void css_padding_top(const std::string & top);
197 void css_padding_top() { padding_top.clear(); };
198 void css_padding_right(const std::string & right);
199 void css_padding_right() { padding_right.clear(); };
200 void css_padding_bottom(const std::string & bottom);
201 void css_padding_bottom() { padding_bottom.clear(); };
202 void css_padding_left(const std::string & left);
203 void css_padding_left() { padding_left.clear(); };
204
205 // text
206
207 enum h_align
208 {
209 al_right,
210 al_left,
211 al_center,
212 al_justify
213 };
214
215 enum v_align
216 {
217 al_top,
218 al_middle,
219 al_bottom,
220 al_baseline,
221 al_sub,
222 al_super,
223 al_text_top,
224 al_text_bottom
225 };
226
227 enum decoration
228 {
229 dc_underline,
230 dc_overline,
231 dc_line_through,
232 dc_none
233 };
234
235 void css_font_size(const std::string & val);
236 void css_font_style_italic();
237 void css_font_style_normal();
238 void css_font_style() { font_style.clear(); };
239 void css_font_weight_bold();
240 void css_font_weight_normal();
241 void css_font_weight() { font_weight.clear(); };
242 void css_text_h_align(h_align val);
243 void css_text_h_align() { text_h_align.clear(); };
244 void css_text_v_align(v_align val);
245 void css_text_v_align() { text_v_align.clear(); };
246 void css_text_decoration(decoration val);
247 void css_text_decoration() { text_deco.clear(); };
248
249 // border
250
251 enum border { bd_top,
252 bd_right,
253 bd_bottom,
254 bd_left,
255 bd_all,
256 bd_clear }; //< remove specifications for any border
257
258 enum bd_width { bd_thin,
259 bd_medium,
260 bd_thick };
261
262 enum bd_style { bd_dotted,
263 bd_dashed,
264 bd_solid,
265 bd_double,
266 bd_groove,
267 bd_ridge,
268 bd_inset,
269 bd_outset,
270 bd_none };
271
272 void css_border_width(border which, bd_width val);
273 void css_border_width(border which, const std::string & val);
274 void css_border_width() { border_width.clear(); };
275 void css_border_color(border which, const std::string & col);
276 void css_border_color() { border_color.clear(); };
277 void css_border_style(border which, bd_style val);
278 void css_border_style() { border_style.clear(); };
279
280 // round corners
281 void css_corner_radius(const std::string & all);
282 void css_corner_radius(const std::string & topleft,
283 const std::string & topright,
284 const std::string & botright,
285 const std::string & botleft);
286
287 // clear all css_corner radius relative information
288 void css_corner_radius() { corner_radius.clear(); };
289
291
297 void css_visibility(bool val);
298
300 void css_content(const std::string & name);
301
303
305 {
306 ease,
307 linear,
308 ease_in,
309 ease_out,
310 ease_in_out
311 };
312
314 void css_transition(const std::string & duration,
315 const std::string & delay = "0s",
316 transition_function funct = ease);
317
319 void css_transition() { transition.clear(); };
320
321
323 std::string css_get_raw_string() const;
324
325protected:
326
328 virtual void css_updated() {};
329
331
335
337 void declare_custom_css(const std::string & label);
338
340 void set_custom_css(const std::string & label, const std::string & val);
341
343 void clear_custom_css(const std::string & label);
344
345
346private:
347
348 // colors properties
349 css_property color;
350 css_property bg_col;
351
352 // background image properties
353 css_property bg_img;
354 css_property img_pos;
355
356 // shadowing
357 css_property box_shadow;
358 css_property text_shadow;
359
360 // position properties
361 css_property box_sizing;
362 css_property display;
363 css_property margin_top;
364 css_property margin_right;
365 css_property margin_bottom;
366 css_property margin_left;
367 css_property height;
368 css_property min_height;
369 css_property max_height;
370 css_property width;
371 css_property min_width;
372 css_property max_width;
373 css_property z_index;
374 css_property position_type;
375 css_property position_top;
376 css_property position_left;
377 css_property position_bottom;
378 css_property position_right;
379 css_property overflow;
380
381 // floating properties
382 css_property float_pos;
383 css_property float_clear;
384 css_property opacity;
385
386 // padding properties
387 css_property padding_top;
388 css_property padding_right;
389 css_property padding_bottom;
390 css_property padding_left;
391
392 // text properties
393 css_property font_size;
394 css_property font_style;
395 css_property font_weight;
396 css_property text_h_align;
397 css_property text_v_align;
398 css_property text_deco;
399
400 // border properties
401 css_property border_width;
402 css_property border_color;
403 css_property border_style;
404
405 // round corners
406 css_property corner_radius;
407
408 // CSS visibility
409 css_property visibility;
410
411 // content
412 css_property content;
413
414 // transition
415 css_property transition;
416
417 // custom css
418 std::map<std::string, css_property> custom_css;
419
420 std::string border_to_string(border val);
421 std::string overflow_to_string(overflowing val);
422};
423
424#endif
class css_property hold the value of a single css property
Definition: css_property.hpp:46
class managing Cascading Style Sheets attributes
Definition: css.hpp:48
void css_transition()
clear transition property
Definition: css.hpp:319
std::string css_get_raw_string() const
returns the css raw string
Definition: css.cpp:766
void css_visibility(bool val)
css_visibility does not prevent sending HTML code to the browser
Definition: css.cpp:722
void declare_custom_css(const std::string &label)
custom css properties, method available for inherited classes
Definition: css.cpp:838
void css_overflow()
clear both x and y overflow (default value)
Definition: css.hpp:159
void clear_custom_css(const std::string &label)
unset value of a previously declared custom css
Definition: css.cpp:858
void css_overflow_x(overflowing val)
set only x overflow
Definition: css.cpp:388
void css_content(const std::string &name)
css content property for "::after" and "::before" pseudo-elements
Definition: css.cpp:729
transition_function
css transition, this concerns all properties that changed within CSS style (hover,...
Definition: css.hpp:305
bx_sizing
Definition: css.hpp:185
@ bx_border
width and height define the box size (reduce content space to fit within the border+padding)
Definition: css.hpp:187
@ bx_content
width and height define the content (add padding and border size for the real size)
Definition: css.hpp:186
positionning
Definition: css.hpp:124
@ pos_fixed
fixed in the viewport
Definition: css.hpp:126
@ pos_absolute
absolute in the document
Definition: css.hpp:124
@ pos_relative
shifted relative to its expected position
Definition: css.hpp:125
@ pos_sticky
either relative or fixed depending on scrolling of parent object
Definition: css.hpp:127
void update_from(const css &ref)
update current object with argument ignoring all fields which are unset
Definition: css.cpp:45
void clear()
set css attributes to their default
Definition: css.cpp:116
void css_overflow_y(overflowing val)
set only y overflow
Definition: css.cpp:395
void set_custom_css(const std::string &label, const std::string &val)
set value to a previously declared custom css
Definition: css.cpp:848
virtual void css_updated()
this method is called when a property has been modified
Definition: css.hpp:328