HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hi::v1::style Class Reference

Public Types

using attributes_from_theme_type = std::function<style_attributes(style_path, style_pseudo_class)>
using notifier_type = notifier<void(style_modify_mask, bool)>
using callback_type = notifier_type::callback_type
using callback_proto = notifier_type::callback_proto

Public Member Functions

 style (style const &) noexcept=delete
 style (style &&) noexcept=delete
style & operator= (style const &) noexcept=delete
style & operator= (style &&) noexcept=delete
void set_name (std::string name)
std::string const & name () const noexcept
void set_id (std::string id)
std::string const & id () const noexcept
void set_classes (std::vector< std::string > classes)
std::vector< std::string > const & classes () const noexcept
void set_parent_path (style_path new_parent_path) noexcept
style_path const & parent_path () const noexcept
style_path path () const noexcept
style & operator= (std::string style_string)
 Parse the given string to configure this style.
attributes_from_theme_type const & attributes_from_theme () const noexcept
void set_attributes_from_theme (attributes_from_theme_type new_attributes_from_theme)
unit::pixel_density pixel_density () const noexcept
void set_pixel_density (unit::pixel_density new_pixel_density)
void set_pseudo_class (style_pseudo_class new_pseudo_class)
void reload (bool path_has_changed=false) noexcept
 Reload the style attributes from the current theme.
template<forward_of< callback_proto > Func>
callback_type subscribe (Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
 Add a callback to the style.

Data Fields

unit::pixels_f width
unit::pixels_f height
unit::pixels_f margin_left
unit::pixels_f margin_bottom
unit::pixels_f margin_right
unit::pixels_f margin_top
unit::pixels_f padding_left
unit::pixels_f padding_bottom
unit::pixels_f padding_right
unit::pixels_f padding_top
unit::pixels_f border_width
unit::pixels_f border_bottom_left_radius
unit::pixels_f border_bottom_right_radius
unit::pixels_f border_top_left_radius
unit::pixels_f border_top_right_radius
float width_px
float height_px
float margin_left_px
float margin_bottom_px
float margin_right_px
float margin_top_px
float padding_left_px
float padding_bottom_px
float padding_right_px
float padding_top_px
float border_width_px
float border_bottom_left_radius_px
float border_bottom_right_radius_px
float border_top_left_radius_px
float border_top_right_radius_px
hi::margins margins_px
hi::margins padding_px
hi::corner_radii border_radius_px
hi::horizontal_alignment horizontal_alignment
hi::vertical_alignment vertical_alignment
color foreground_color
color background_color
color border_color

Member Function Documentation

◆ operator=()

style & hi::v1::style::operator= ( std::string style_string)
inline

Parse the given string to configure this style.

The style_string has the following format:

style_string := (id | class | attribute )*
id := '#' annex-31-minus
class := '.' annex-31-minus
attribute := annex-31-minus '=' value
value := color-value | length-value | horizontal-alignment-value | vertical-alignment-value
color-value := hex-color-value | rgb-color-value | rgba-color-value | named-color-value
hex-color-value := '#' [0-9A-Fa-f]{6,8}
rgb-color-value := 'rgb_color(' number ',' number ',' number ')'
rgba-color-value := 'rgb_color(' number ',' number ',' number ',' number ')'
named-color-value := annex-31-minus
length-value := number ('pd' | 'px' | 'pt' | 'in' | 'cm')?
horizontal-alignment-value := 'left' | 'right | 'center' | 'justified' | 'natural' | 'opposite'
vertical-alignment-value := 'bottom' | 'middle' | 'top'
@ middle
Align to the vertical-middle.
Definition alignment.hpp:36
@ bottom
Align to the bottom.
Definition alignment.hpp:40
@ top
Align to the top.
Definition alignment.hpp:32
@ justified
Stretch the text to be flush to both sides.
Definition alignment.hpp:130
@ center
Align the text in the center.
Definition alignment.hpp:124
This is a RGBA floating point color.
Definition color_intf.hpp:49
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244

◆ reload()

void hi::v1::style::reload ( bool path_has_changed = false)
inlinenoexcept

Reload the style attributes from the current theme.

Reload is called automatically after:

  • changing the attributes_from_theme function.
  • changing the parent of the style (or of its ancestors).
  • changing the name, id, classes of a style (or of its ancestors).

But must by called manually for children when the notifier is called with style_modify_mask::path.

◆ subscribe()

template<forward_of< callback_proto > Func>
callback_type hi::v1::style::subscribe ( Func && func,
callback_flags flags = callback_flags::synchronous )
inlinenodiscardnoexcept

Add a callback to the style.

After the call the caller will take ownership of the returned callback object.

The callback object is a move-only RAII object that will automatically unsubscribe the callback when the token is destroyed.

Parameters
flagsThe callback-flags used to determine how the callback is called.
callbackA callable object with prototype void(style_modify_mask, bool) being called when the style changes. The first argument is the mask of which attributes have changed. The second argument is true when the path of the style has changed.
Returns
A RAII object which when destroyed will unsubscribe the callback.

The documentation for this class was generated from the following file: