use egui::{Color32, Rect, Response, Ui};
use super::visuals::ListVisuals;
pub struct ContentContext<'a> {
pub rect: Rect,
pub bg_color: Color32,
pub selected: bool,
pub hovered: bool,
pub list_item: &'a ListItem,
pub response: &'a egui::Response,
pub visuals: ListVisuals,
}
pub trait ListItemContent {
fn ui(self, ui: &mut Ui, context: &ContentContext<'_>) -> Response;
}
pub struct ListItem {
pub(crate) selected: bool,
pub(crate) interactive: bool,
pub(crate) draggable: bool,
pub(crate) height: Option<f32>,
pub(crate) show_separator: bool,
}
impl Default for ListItem {
fn default() -> Self {
Self {
selected: false,
interactive: true,
draggable: false,
height: None,
show_separator: false,
}
}
}
impl ListItem {
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
#[must_use]
pub fn interactive(mut self, interactive: bool) -> Self {
self.interactive = interactive;
self
}
#[must_use]
pub fn draggable(mut self, draggable: bool) -> Self {
self.draggable = draggable;
self
}
#[must_use]
pub fn height(mut self, height: f32) -> Self {
self.height = Some(height);
self
}
#[must_use]
pub fn show_separator(mut self, show: bool) -> Self {
self.show_separator = show;
self
}
pub fn is_selected(&self) -> bool {
self.selected
}
pub fn is_interactive(&self) -> bool {
self.interactive
}
}