2026-05-25 13:30:16 +02:00
|
|
|
// <Kira Installer - universal Linux installer.>
|
|
|
|
|
// Copyright (C) <2026> <Kira Foundation>
|
|
|
|
|
|
|
|
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Scroll List iced widget implementation
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-01 00:29:15 +02:00
|
|
|
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};
|
|
|
|
|
|
2026-05-03 23:13:25 +02:00
|
|
|
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)
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-01 00:29:15 +02:00
|
|
|
match status {
|
2026-05-03 23:13:25 +02:00
|
|
|
button::Status::Hovered => {
|
|
|
|
|
res_stile.border = Border {
|
2026-05-01 00:29:15 +02:00
|
|
|
color: Color::from_rgb(0.8, 0.3, 0.3),
|
2026-05-04 21:21:41 +02:00
|
|
|
width: 1.0,
|
2026-05-01 00:29:15 +02:00
|
|
|
radius: Radius::new(5.0),
|
2026-05-03 23:13:25 +02:00
|
|
|
};
|
2026-05-01 00:29:15 +02:00
|
|
|
},
|
2026-05-03 23:13:25 +02:00
|
|
|
_ => (),
|
2026-05-01 00:29:15 +02:00
|
|
|
}
|
2026-05-03 23:13:25 +02:00
|
|
|
|
|
|
|
|
return res_stile;
|
2026-05-01 00:29:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
2026-05-03 23:13:25 +02:00
|
|
|
use iced::{Border, border::Radius};
|
|
|
|
|
|
|
|
|
|
//let palette = theme.palette();
|
|
|
|
|
|
|
|
|
|
let mut res_stile = button::primary(theme, button::Status::Active);
|
|
|
|
|
|
2026-05-01 00:29:15 +02:00
|
|
|
|
|
|
|
|
match status {
|
2026-05-03 23:13:25 +02:00
|
|
|
button::Status::Hovered => {
|
|
|
|
|
res_stile.border = Border {
|
|
|
|
|
color: Color::from_rgb(0.8, 0.3, 0.3),
|
2026-05-04 21:21:41 +02:00
|
|
|
width: 1.0,
|
2026-05-03 23:13:25 +02:00
|
|
|
radius: Radius::new(5.0),
|
|
|
|
|
};
|
2026-05-01 00:29:15 +02:00
|
|
|
},
|
2026-05-03 23:13:25 +02:00
|
|
|
_ => (),
|
2026-05-01 00:29:15 +02:00
|
|
|
}
|
2026-05-03 23:13:25 +02:00
|
|
|
|
|
|
|
|
return res_stile;
|
2026-05-01 00:29:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
2026-05-03 23:13:25 +02:00
|
|
|
container(scrollable(column).width(Length::Fill).spacing(5))
|
2026-05-01 00:29:15 +02:00
|
|
|
.style(container::bordered_box)
|
|
|
|
|
.height(container_height)
|
2026-05-03 23:13:25 +02:00
|
|
|
.padding(5)
|
2026-05-01 00:29:15 +02:00
|
|
|
.into()
|
|
|
|
|
}
|