StyleSheet

Inherited: None

Description

The StyleSheet class is responsible for handling CSS style rules, which can be applied to Widget objects. It includes functionality for storing, loading, saving, and resolving styles, along with utility methods to convert CSS color and length values.

Public Methods

std::string

data () const

void

resolve (Widget * widget)

void

setData (const std::string & data)

Static Methods

void

resolveInline (Widget * widget, const std::string & style)

void

setStyleProperty (Widget * widget, const std::string & key, const std::string & value)

Vector4

toColor (const std::string & value)

float

toLength (const std::string & value, bool & pixels)

Methods Description

std::string StyleSheet::data () const

Returns content as a string.

See also setData().


void StyleSheet::resolve (Widget * widget)

Resolves the styles for a given widget based on the parsed CSS rules. It iterates through the CSS selectors and applies matching rules to the widget.


void StyleSheet::resolveInline (Widget * widget, std::string & style)

Resolves inline style*s provided as a string (e.g., from the *style attribute in XML). The method splits the inline style*s into key-value pairs and applies them to the *widget.


void StyleSheet::setData (std::string & data)

Sets a new content data.

See also *data*().


void StyleSheet::setStyleProperty (Widget * widget, std::string & key, std::string & value)

Directly sets a style property for a widget. It adds the specified key and value pair to the widget’s style rules.


Vector4 StyleSheet::toColor (std::string & value)

Converts a CSS color value (e.g., named colors like “blue” or hexadecimal colors like “#ff0000”) to a Vector4 representing RGBA *value*s. It handles both named colors and hex codes (including short hex formats like #FFF).


float StyleSheet::toLength (std::string & value, bool & pixels)

Converts a length value (e.g., “10px” or “50%”) into a numeric value and returns whether the value is in pixels or percentages.