#[derive(Debug, Clone)]
pub struct Style {
pub indent: f32,
pub icon_spacing: f32,
pub row_height: f32,
pub expand_icon_size: f32,
pub action_icon_size: f32,
pub selection_color: Option<egui::Color32>,
pub hover_color: Option<egui::Color32>,
pub expand_icon_style: ExpandIconStyle,
}
impl Default for Style {
fn default() -> Self {
Self {
indent: 16.0,
icon_spacing: 4.0,
row_height: 20.0,
expand_icon_size: 12.0,
action_icon_size: 16.0,
selection_color: Some(egui::Color32::from_rgba_unmultiplied(100, 150, 200, 100)),
hover_color: Some(egui::Color32::from_rgba_unmultiplied(100, 150, 200, 50)),
expand_icon_style: ExpandIconStyle::Arrow,
}
}
}
impl Style {
pub fn with_indent(mut self, indent: f32) -> Self {
self.indent = indent;
self
}
pub fn with_icon_spacing(mut self, spacing: f32) -> Self {
self.icon_spacing = spacing;
self
}
pub fn with_row_height(mut self, height: f32) -> Self {
self.row_height = height;
self
}
pub fn with_expand_icon_size(mut self, size: f32) -> Self {
self.expand_icon_size = size;
self
}
pub fn with_action_icon_size(mut self, size: f32) -> Self {
self.action_icon_size = size;
self
}
pub fn with_selection_color(mut self, color: egui::Color32) -> Self {
self.selection_color = Some(color);
self
}
pub fn with_hover_color(mut self, color: egui::Color32) -> Self {
self.hover_color = Some(color);
self
}
pub fn with_expand_icon_style(mut self, style: ExpandIconStyle) -> Self {
self.expand_icon_style = style;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExpandIconStyle {
Arrow,
PlusMinus,
ChevronRight,
Custom {
collapsed: String,
expanded: String,
},
}
impl ExpandIconStyle {
pub fn collapsed_str(&self) -> &str {
match self {
ExpandIconStyle::Arrow => "▶",
ExpandIconStyle::PlusMinus => "+",
ExpandIconStyle::ChevronRight => "›",
ExpandIconStyle::Custom { collapsed, .. } => collapsed,
}
}
pub fn expanded_str(&self) -> &str {
match self {
ExpandIconStyle::Arrow => "▼",
ExpandIconStyle::PlusMinus => "-",
ExpandIconStyle::ChevronRight => "⌄",
ExpandIconStyle::Custom { expanded, .. } => expanded,
}
}
}
impl Default for ExpandIconStyle {
fn default() -> Self {
Self::Arrow
}
}