#[must_use]
pub struct Button<'a> {
pub(crate) text: egui::WidgetText,
pub(crate) variant: crate::tokens::button_variant::ButtonVariant,
pub(crate) size: crate::tokens::component_size::ComponentSize,
pub(crate) enabled: bool,
pub(crate) icon: Option<crate::icons::lucide_icon::LucideIcon>,
pub(crate) shortcut_text: Option<String>,
pub(crate) selected: bool,
pub(crate) full_width: bool,
pub(crate) fixed_width: Option<f32>,
pub(crate) wrap: Option<crate::text::Wrap>,
pub(crate) min_height: f32,
_phantom: std::marker::PhantomData<&'a ()>,
}
impl Button<'_> {
pub fn new(text: impl Into<egui::WidgetText>) -> Self {
Self {
text: text.into(),
variant: crate::tokens::button_variant::ButtonVariant::Default,
size: crate::tokens::component_size::ComponentSize::Default,
enabled: true,
icon: None,
shortcut_text: None,
selected: false,
full_width: false,
fixed_width: None,
wrap: None,
min_height: 0.0,
_phantom: std::marker::PhantomData,
}
}
pub fn icon_only(icon: crate::icons::lucide_icon::LucideIcon) -> Self {
Self {
text: "".into(),
variant: crate::tokens::button_variant::ButtonVariant::Default,
size: crate::tokens::component_size::ComponentSize::Default,
enabled: true,
icon: Some(icon),
shortcut_text: None,
selected: false,
full_width: false,
fixed_width: None,
wrap: None,
min_height: 0.0,
_phantom: std::marker::PhantomData,
}
}
pub fn variant(mut self, variant: crate::tokens::button_variant::ButtonVariant) -> Self {
self.variant = variant;
self
}
pub fn size(mut self, size: crate::tokens::component_size::ComponentSize) -> Self {
self.size = size;
self
}
pub fn enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
pub fn icon(mut self, icon: crate::icons::lucide_icon::LucideIcon) -> Self {
self.icon = Some(icon);
self
}
pub fn shortcut_text(mut self, text: impl Into<String>) -> Self {
self.shortcut_text = Some(text.into());
self
}
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
pub fn full_width(mut self) -> Self {
self.full_width = true;
self
}
pub fn fixed_width(mut self, width: f32) -> Self {
self.fixed_width = Some(width);
self
}
pub fn wrap(mut self, wrap: crate::text::Wrap) -> Self {
self.wrap = Some(wrap);
self
}
pub fn min_height(mut self, height: f32) -> Self {
self.min_height = height;
self
}
pub fn single_line(mut self) -> Self {
self.wrap = Some(crate::text::Wrap::Truncate);
self
}
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
ui.add_enabled(self.enabled, self)
}
}