use crate::Theme;
#[derive(Clone, Copy)]
pub enum ButtonState {
Default,
Pressed,
Active,
Inactive,
Error,
}
#[derive(Clone)]
pub struct Button {
pub(crate) text: String,
pub(crate) icon: Option<&'static str>,
pub(crate) state: ButtonState,
pub(crate) theme: Option<Theme>,
}
impl Button {
pub fn new(text: String, icon: Option<&'static str>, state: ButtonState) -> Self {
Button {
text,
icon,
state,
theme: None,
}
}
pub fn text(text: String) -> Self {
Button {
text,
icon: None,
state: ButtonState::Default,
theme: None,
}
}
pub fn with_icon(text: String, icon: &'static str) -> Self {
Button {
text,
icon: Some(icon),
state: ButtonState::Default,
theme: None,
}
}
pub fn with_state(text: String, state: ButtonState) -> Self {
Button {
text,
icon: None,
state,
theme: None,
}
}
pub fn with_icon_and_state(text: String, icon: &'static str, state: ButtonState) -> Self {
Button {
text,
icon: Some(icon),
state,
theme: None,
}
}
pub fn updated_text(&self, text: String) -> Self {
Button {
text,
icon: self.icon,
state: self.state,
theme: self.theme.clone(),
}
}
pub fn updated_icon(&self, icon: &'static str) -> Self {
Button {
text: self.text.clone(),
icon: Some(icon),
state: self.state,
theme: self.theme.clone(),
}
}
pub fn updated_state(&self, state: ButtonState) -> Self {
Button {
text: self.text.clone(),
icon: self.icon,
state,
theme: self.theme.clone(),
}
}
pub fn with_theme(self, theme: Theme) -> Self {
Button {
theme: Some(theme),
..self
}
}
}
impl Default for Button {
fn default() -> Self {
Button {
text: "".to_string(),
icon: None,
state: ButtonState::Default,
theme: None,
}
}
}