// // Copyright (C) <2026> // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . /* Scroll List iced widget implementation */ 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( items: &Vec, selected_id: Option, 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() }