use bevy::{prelude::*, ui_widgets::observe};
use jackdaw_widgets::list_view::{ListItem, ListItemContent, ListView};
use crate::tokens;
pub fn list_view() -> impl Bundle {
(
ListView,
Node {
flex_direction: FlexDirection::Column,
padding: UiRect::left(px(tokens::SPACING_LG)),
..default()
},
)
}
pub fn list_item(index: usize) -> impl Bundle {
(
ListItem { index },
Node {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
column_gap: px(tokens::SPACING_SM),
padding: UiRect::axes(px(tokens::SPACING_XS), px(1.0)),
width: percent(100),
..default()
},
BackgroundColor(Color::NONE),
children![
(
Text::new(format!("[{index}]")),
TextFont {
font_size: tokens::FONT_SM,
..default()
},
TextColor(tokens::TEXT_SECONDARY),
Node {
min_width: px(28.0),
flex_shrink: 0.0,
..default()
},
),
(
ListItemContent,
Node {
flex_grow: 1.0,
..default()
},
)
],
observe(
|hover: On<Pointer<Over>>, mut q: Query<&mut BackgroundColor, With<ListItem>>| {
if let Ok(mut bg) = q.get_mut(hover.event_target()) {
bg.0 = tokens::HOVER_BG;
}
},
),
observe(
|out: On<Pointer<Out>>, mut q: Query<&mut BackgroundColor, With<ListItem>>| {
if let Ok(mut bg) = q.get_mut(out.event_target()) {
bg.0 = Color::NONE;
}
},
),
)
}