26 using callback_type = notifier_type::callback_type;
27 using callback_proto = notifier_type::callback_proto;
30 unit::pixels_f height;
31 unit::pixels_f margin_left;
32 unit::pixels_f margin_bottom;
33 unit::pixels_f margin_right;
34 unit::pixels_f margin_top;
35 unit::pixels_f padding_left;
36 unit::pixels_f padding_bottom;
37 unit::pixels_f padding_right;
38 unit::pixels_f padding_top;
39 unit::pixels_f border_width;
40 unit::pixels_f border_bottom_left_radius;
41 unit::pixels_f border_bottom_right_radius;
42 unit::pixels_f border_top_left_radius;
43 unit::pixels_f border_top_right_radius;
48 float margin_bottom_px;
49 float margin_right_px;
51 float padding_left_px;
52 float padding_bottom_px;
53 float padding_right_px;
55 float border_width_px;
56 float border_bottom_left_radius_px;
57 float border_bottom_right_radius_px;
58 float border_top_left_radius_px;
59 float border_top_right_radius_px;
68 color foreground_color;
69 color background_color;
74 style& operator=(
style const&)
noexcept =
delete;
76 style()
noexcept =
default;
84 [[nodiscard]]
std::string const& name()
const noexcept
95 [[nodiscard]]
std::string const& id()
const noexcept
111 void set_parent_path(
style_path new_parent_path)
noexcept
113 _parent_path = new_parent_path;
117 [[nodiscard]]
style_path const &parent_path()
const noexcept
122 [[nodiscard]]
style_path path()
const noexcept
124 auto r = parent_path();
125 r.emplace_back(_name, _id, _classes);
150 if (
auto const optional_style = parse_style(style_string)) {
151 std::tie(_override_attributes, _id, _classes) = *optional_style;
153 }
else if (optional_style.has_error()) {
161 [[nodiscard]] attributes_from_theme_type
const& attributes_from_theme() const noexcept
163 return _attributes_from_theme;
166 void set_attributes_from_theme(attributes_from_theme_type new_attributes_from_theme)
168 _attributes_from_theme =
std::move(new_attributes_from_theme);
172 [[nodiscard]] unit::pixel_density pixel_density() const noexcept
174 return _pixel_density;
177 void set_pixel_density(unit::pixel_density new_pixel_density)
179 _pixel_density = new_pixel_density;
186 auto const old_pseudo_class = std::exchange(_pseudo_class, new_pseudo_class);
188 auto const i = std::to_underlying(old_pseudo_class);
189 auto const j = std::to_underlying(new_pseudo_class);
190 auto const mask = _pseudo_class_modifications[i + j * style_pseudo_class_size];
192 update_attributes(mask);
193 _notifier(mask,
false);
206 void reload(
bool path_has_changed =
false) noexcept
208 if (not _attributes_from_theme) {
214 for (
auto i =
size_t{0}; i != style_pseudo_class_size; ++i) {
215 _loaded_attributes[i] = _attributes_from_theme(path(),
static_cast<style_pseudo_class>(i));
216 _loaded_attributes[i].apply(_override_attributes);
219 for (
auto i =
size_t{0}; i != style_pseudo_class_size; ++i) {
220 auto const& src = _loaded_attributes[i];
221 for (
auto j =
size_t{0}; j != style_pseudo_class_size; ++j) {
222 auto const& dst = _loaded_attributes[j];
223 _pseudo_class_modifications[i + j * style_pseudo_class_size] = compare(src, dst);
245 template<forward_of<callback_proto> Func>
246 [[nodiscard]] callback_type
subscribe(Func&& func, callback_flags flags = callback_flags::synchronous)
noexcept
262 attributes_from_theme_type _attributes_from_theme;
280 notifier_type _notifier;
285 foreground_color = _attributes.foreground_color();
286 background_color = _attributes.background_color();
287 border_color = _attributes.border_color();
291 width = _attributes.width() * _pixel_density;
292 height = _attributes.height() * _pixel_density;
293 width_px = width.in(unit::pixels);
294 height_px = height.in(unit::pixels);
298 margin_left = _attributes.margin_left() * _pixel_density;
299 margin_bottom = _attributes.margin_bottom() * _pixel_density;
300 margin_right = _attributes.margin_right() * _pixel_density;
301 margin_top = _attributes.margin_top() * _pixel_density;
302 padding_left = _attributes.padding_left() * _pixel_density;
303 padding_bottom = _attributes.padding_bottom() * _pixel_density;
304 padding_right = _attributes.padding_right() * _pixel_density;
305 padding_top = _attributes.padding_top() * _pixel_density;
306 margin_left_px = margin_left.in(unit::pixels);
307 margin_bottom_px = margin_bottom.in(unit::pixels);
308 margin_right_px = margin_right.in(unit::pixels);
309 margin_top_px = margin_top.in(unit::pixels);
310 padding_left_px = padding_left.in(unit::pixels);
311 padding_bottom_px = padding_bottom.in(unit::pixels);
312 padding_right_px = padding_right.in(unit::pixels);
313 padding_top_px = padding_top.in(unit::pixels);
314 margins_px =
hi::margins{margin_left_px, margin_bottom_px, margin_right_px, margin_top_px};
315 padding_px = hi::margins{padding_left_px, padding_bottom_px, padding_right_px, padding_top_px};
319 border_width = _attributes.border_width() * _pixel_density;
320 border_bottom_left_radius = _attributes.border_bottom_left_radius() * _pixel_density;
321 border_bottom_right_radius = _attributes.border_bottom_right_radius() * _pixel_density;
322 border_top_left_radius = _attributes.border_top_left_radius() * _pixel_density;
323 border_top_right_radius = _attributes.border_top_right_radius() * _pixel_density;
324 border_width_px = border_width.in(unit::pixels);
325 border_bottom_left_radius_px = border_bottom_left_radius.in(unit::pixels);
326 border_bottom_right_radius_px = border_bottom_right_radius.in(unit::pixels);
327 border_top_left_radius_px = border_top_left_radius.in(unit::pixels);
328 border_top_right_radius_px = border_top_right_radius.in(unit::pixels);
329 border_radius_px = hi::corner_radii{
330 border_bottom_left_radius_px,
331 border_bottom_right_radius_px,
332 border_top_left_radius_px,
333 border_top_right_radius_px};
337 horizontal_alignment = _attributes.horizontal_alignment();
338 vertical_alignment = _attributes.vertical_alignment();