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>(self, color: C) -> Stylewhere
C: Into<PackedRgba>,
pub fn fg<C>(self, color: C) -> Stylewhere
C: Into<PackedRgba>,
Set foreground color.
Sourcepub fn bg<C>(self, color: C) -> Stylewhere
C: Into<PackedRgba>,
pub fn bg<C>(self, color: C) -> Stylewhere
C: Into<PackedRgba>,
Set background color.
Sourcepub fn strikethrough(self) -> Style
pub fn strikethrough(self) -> Style
Add strikethrough attribute.
Add hidden attribute.
Sourcepub fn double_underline(self) -> Style
pub fn double_underline(self) -> Style
Add double underline attribute.
Sourcepub fn curly_underline(self) -> Style
pub fn curly_underline(self) -> Style
Add curly underline attribute.
Sourcepub const fn underline_color(self, color: PackedRgba) -> Style
pub const fn underline_color(self, color: PackedRgba) -> Style
Set underline color.
Sourcepub const fn attrs(self, attrs: StyleFlags) -> Style
pub const fn attrs(self, attrs: StyleFlags) -> Style
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.
Trait Implementations§
impl Copy for Style
impl Eq for Style
impl StructuralPartialEq for Style
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnsafeUnpin for Style
impl UnwindSafe for Style
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().