Work on scroll list style. Tranfer scroll list to src root.

This commit is contained in:
2026-05-04 21:21:41 +02:00
parent d4c7e59cd6
commit 7365f95d20
4 changed files with 12 additions and 165 deletions
+92
View File
@@ -0,0 +1,92 @@
use std::fmt::Display;
use iced::widget::{Column, button, container, scrollable, text};
use iced::{Alignment, Color, Element, Length, Theme};
#[derive(Debug, Clone)]
pub enum ListViewMessage {
Select(usize),
}
fn unselected_button_style(theme: &Theme, status: button::Status) -> button::Style {
use iced::{Border, border::Radius};
let palette = theme.palette();
let mut res_stile = button::Style {
background: Some(iced::Background::Color(Color::TRANSPARENT)),
text_color: palette.text,
..button::primary(theme, button::Status::Active)
};
match status {
button::Status::Hovered => {
res_stile.border = Border {
color: Color::from_rgb(0.8, 0.3, 0.3),
width: 1.0,
radius: Radius::new(5.0),
};
},
_ => (),
}
return res_stile;
}
fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style {
use iced::{Border, border::Radius};
//let palette = theme.palette();
let mut res_stile = button::primary(theme, button::Status::Active);
match status {
button::Status::Hovered => {
res_stile.border = Border {
color: Color::from_rgb(0.8, 0.3, 0.3),
width: 1.0,
radius: Radius::new(5.0),
};
},
_ => (),
}
return res_stile;
}
// Assuming your Item struct or type implements Display or has a text representation
pub fn list_view<T: Display>(
items: &Vec<T>,
selected_id: Option<usize>,
container_height: Length,
) -> Element<'_, ListViewMessage> {
let mut column = Column::new()
.spacing(2)
.align_x(Alignment::Center)
.width(Length::Fill);
for (index, value) in items.iter().enumerate() {
// Create a row for each item, possibly with buttons or other controls
let list_item = if let Some(id) = selected_id
&& id == index
{
button(text(value.to_string())).style(selected_button_style)
} else {
button(text(value.to_string())).style(unselected_button_style)
};
let list_item = list_item
.width(Length::Fill)
.on_press(ListViewMessage::Select(index));
column = column.push(list_item);
}
// Wrap the column in a scrollable widget
container(scrollable(column).width(Length::Fill).spacing(5))
.style(container::bordered_box)
.height(container_height)
.padding(5)
.into()
}