orbtk_theming/
selector.rsuse std::fmt;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Selector {
pub style: Option<String>,
pub state: Option<String>,
dirty: bool,
}
impl Selector {
pub fn new(style: impl Into<String>) -> Self {
Selector {
style: Some(style.into()),
state: None,
dirty: true,
}
}
pub fn set_state(&mut self, state: impl Into<String>) {
self.state = Some(state.into());
self.dirty = true;
}
pub fn clear_state(&mut self) {
self.state = None;
self.dirty = true;
}
pub fn dirty(&self) -> bool {
self.dirty
}
pub fn set_dirty(&mut self, dirty: bool) {
self.dirty = dirty;
}
pub fn has_state(&self, state: &str) -> bool {
if let Some(st) = &self.state {
if st.as_str() == state {
return true;
}
}
false
}
}
impl fmt::Display for Selector {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(style) = &self.style {
return write!(f, "Selector ( style: {} )", style);
}
write!(f, "Selector ( empty )")
}
}
impl From<&str> for Selector {
fn from(s: &str) -> Self {
Selector::new(s)
}
}
impl From<String> for Selector {
fn from(s: String) -> Self {
Selector::new(s)
}
}