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

TString

data () const

void

resolve (Widget * widget)

void

setData (const TString & data)

Static Methods

void

resolveInline (Widget * widget, const TString & style)

void

setStyleProperty (Widget * widget, const TString & key, const TString & value)

Vector4

toColor (const TString & value)

float

toLength (const TString & value, bool & pixels)

Methods Description

TString 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, TString & style)

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


void StyleSheet::setData (TString & data)

Sets a new content data.

See also data().


void StyleSheet::setStyleProperty (Widget * widget, TString & key, TString & 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 (TString & value)

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


float StyleSheet::toLength (TString & 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.