Skip to main content

rustmotion_core/traits/
backgrounded.rs

1/// Trait for components that support a background color.
2pub trait Backgrounded {
3    fn background(&self) -> Option<&str>;
4}
5
6/// Mutable access to background — needed by builder traits.
7pub trait BackgroundedMut: Backgrounded {
8    fn set_background(&mut self, bg: Option<String>);
9}
10
11/// Builder API for background.
12pub trait BackgroundedExt: BackgroundedMut + Sized {
13    fn bg(mut self, color: impl Into<String>) -> Self {
14        self.set_background(Some(color.into()));
15        self
16    }
17
18    fn bg_none(mut self) -> Self {
19        self.set_background(None);
20        self
21    }
22}
23
24impl<T: BackgroundedMut + Sized> BackgroundedExt for T {}