use crate::*;
use waft_foundation::App;
use waft_widgets::*;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub(crate) enum SortIndicatorDirection {
#[default]
None,
Ascending,
Descending,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct SortIndicator {
pub(crate) direction: SortIndicatorDirection,
}
impl SortIndicator {
pub(crate) fn new(direction: SortIndicatorDirection) -> Self {
Self { direction }
}
}
impl StatelessWidget for SortIndicator {
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
let r = ThemeResources::of(app, context);
let (has_sort, glyph) = match self.direction {
SortIndicatorDirection::Ascending => (true, FluentSymbol::ChevronUp),
SortIndicatorDirection::Descending => (true, FluentSymbol::ChevronDown),
SortIndicatorDirection::None => (false, FluentSymbol::ChevronUp),
};
let glyph_icon = FontIcon::symbol(glyph)
.font_size(r.sort_indicator_glyph_size)
.foreground(r.sort_indicator_foreground);
let layout_root =
Opacity::new(if has_sort { 1.0 } else { 0.0 }).child(Center::new().child(glyph_icon));
IgnorePointer::new()
.child(
SizedBox::new()
.width(r.sort_indicator_size)
.height(r.sort_indicator_size)
.child(layout_root),
)
.into_widget()
}
}