pub struct StyleSheet { /* private fields */ }Expand description
A registry of named styles for consistent theming.
StyleSheet allows defining styles by name and looking them up later. This decouples visual appearance from widget logic, allowing themes to override the stylesheet without changing widget code.
§Thread Safety
StyleSheet uses an internal RwLock for thread-safe read access after initialization. Multiple readers can access styles concurrently.
Implementations§
Source§impl StyleSheet
impl StyleSheet
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a StyleSheet with default semantic styles.
This provides a base set of commonly-used style names:
error: Red, boldwarning: Orange/yellowinfo: Bluesuccess: Greenmuted: Gray/dimhighlight: Yellow backgroundlink: Blue, underline
Sourcepub fn define(&self, name: impl Into<String>, style: Style)
pub fn define(&self, name: impl Into<String>, style: Style)
Define a named style.
If a style with this name already exists, it is replaced.
Sourcepub fn remove(&self, name: &str) -> Option<Style>
pub fn remove(&self, name: &str) -> Option<Style>
Remove a named style.
Returns the removed style if it existed.
Sourcepub fn get(&self, name: &str) -> Option<Style>
pub fn get(&self, name: &str) -> Option<Style>
Get a named style.
Returns None if the style is not defined.
Sourcepub fn get_or_default(&self, name: &str) -> Style
pub fn get_or_default(&self, name: &str) -> Style
Get a named style, returning a default if not found.
Sourcepub fn compose(&self, names: &[&str]) -> Style
pub fn compose(&self, names: &[&str]) -> Style
Compose multiple styles by name, merging them in order.
Styles are merged left-to-right, with later styles taking precedence over earlier ones for conflicting properties.
Missing style names are silently ignored.
§Example
use ftui_style::{Style, StyleSheet};
use ftui_render::cell::PackedRgba;
let sheet = StyleSheet::new();
sheet.define("base", Style::new().fg(PackedRgba::WHITE));
sheet.define("bold", Style::new().bold());
// Compose: base + bold = white text that's bold
let composed = sheet.compose(&["base", "bold"]);Sourcepub fn compose_strict(&self, names: &[&str]) -> Option<Style>
pub fn compose_strict(&self, names: &[&str]) -> Option<Style>
Compose styles with fallback for missing names.
Like compose, but returns None if any named style is missing.
Sourcepub fn extend(&self, other: &StyleSheet)
pub fn extend(&self, other: &StyleSheet)
Extend this stylesheet with styles from another.
Styles from other override styles with the same name in self.