use crate::{Flag, Plane, Style, ToStyleSet, color::Color};
pub trait StyleAttribute {
type Value: Default;
#[must_use]
fn set_in_style(self, style: Style, value: Self::Value) -> Style;
#[must_use]
fn get_from_style(self, style: &Style) -> Self::Value;
}
pub trait StyleSet: ToStyleSet<StyleSet = Self> {
#[must_use]
fn set_flag(self, flag: Flag, value: bool) -> Self {
self.set(flag, value)
}
#[must_use]
fn get_flag(&self, flag: Flag) -> bool {
self.get(flag)
}
#[must_use]
fn get_flags(&self) -> GetFlags<'_>;
#[must_use]
fn set_color(self, plane: Plane, color: Option<impl Into<Color>>) -> Self {
let color: Option<Color> = color.map(Into::into);
self.set(plane, color)
}
#[must_use]
fn get_color(&self, plane: Plane) -> Option<Color> {
self.get(plane)
}
#[must_use]
fn set<A: StyleAttribute>(self, attr: A, value: A::Value) -> Self;
#[must_use]
fn get<A: StyleAttribute>(&self, attr: A) -> A::Value;
#[must_use]
fn unset<A: StyleAttribute>(self, attr: A) -> Self {
self.set(attr, A::Value::default())
}
}
pub struct GetFlags<'a> {
pub(crate) inner: enum_iterator::All<Flag>,
pub(crate) style: &'a Style,
}
impl Iterator for GetFlags<'_> {
type Item = Flag;
fn next(&mut self) -> Option<Self::Item> {
self.inner.by_ref().find(|&flag| self.style.get_flag(flag))
}
}