pub struct Style {
pub fg: Option<PackedRgba>,
pub bg: Option<PackedRgba>,
pub attrs: Option<StyleFlags>,
pub underline_color: Option<PackedRgba>,
}Expand description
Unified styling type with CSS-like cascading semantics.
§Design Rationale
- Option fields allow inheritance (None = inherit from parent)
- Explicit masks track which properties are intentionally set
- Copy + small size for cheap passing
- Builder pattern for ergonomic construction
§Example
use ftui_style::{Style, StyleFlags};
use ftui_render::cell::PackedRgba;
let style = Style::new()
.fg(PackedRgba::rgb(255, 0, 0))
.bg(PackedRgba::rgb(0, 0, 0))
.bold()
.underline();Fields§
§fg: Option<PackedRgba>Foreground color (text color).
bg: Option<PackedRgba>Background color.
attrs: Option<StyleFlags>Text attributes (bold, italic, etc.).
underline_color: Option<PackedRgba>Underline color (separate from fg for flexibility).
Implementations§
Source§impl Style
impl Style
Sourcepub fn fg<C: Into<PackedRgba>>(self, color: C) -> Self
pub fn fg<C: Into<PackedRgba>>(self, color: C) -> Self
Set foreground color.
Sourcepub fn bg<C: Into<PackedRgba>>(self, color: C) -> Self
pub fn bg<C: Into<PackedRgba>>(self, color: C) -> Self
Set background color.
Sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Add strikethrough attribute.
Add hidden attribute.
Sourcepub fn double_underline(self) -> Self
pub fn double_underline(self) -> Self
Add double underline attribute.
Sourcepub fn curly_underline(self) -> Self
pub fn curly_underline(self) -> Self
Add curly underline attribute.
Sourcepub const fn underline_color(self, color: PackedRgba) -> Self
pub const fn underline_color(self, color: PackedRgba) -> Self
Set underline color.
Sourcepub const fn attrs(self, attrs: StyleFlags) -> Self
pub const fn attrs(self, attrs: StyleFlags) -> Self
Set attributes directly.
Sourcepub fn merge(&self, parent: &Style) -> Style
pub fn merge(&self, parent: &Style) -> Style
Cascade merge: Fill in None fields from parent.
child.merge(parent) returns a style where child’s Some values
take precedence, and parent fills in any None values.
For attributes, the flags are combined (OR operation) so both parent and child attributes apply.
§Example
use ftui_style::Style;
use ftui_render::cell::PackedRgba;
let parent = Style::new().fg(PackedRgba::rgb(255, 0, 0)).bold();
let child = Style::new().bg(PackedRgba::rgb(0, 0, 255));
let merged = child.merge(&parent);
// merged has: fg=RED (from parent), bg=BLUE (from child), bold (from parent)Sourcepub fn patch(&self, child: &Style) -> Style
pub fn patch(&self, child: &Style) -> Style
Patch merge: Override parent with child’s Some values.
parent.patch(&child) returns a style where child’s Some values
replace parent’s values.
This is the inverse perspective of merge().
Sourcepub fn has_attr(&self, flag: StyleFlags) -> bool
pub fn has_attr(&self, flag: StyleFlags) -> bool
Check if a specific attribute is set.