Work on scroll list style. Tranfer scroll list to src root.
This commit is contained in:
@@ -23,7 +23,7 @@ fn unselected_button_style(theme: &Theme, status: button::Status) -> button::Sty
|
||||
button::Status::Hovered => {
|
||||
res_stile.border = Border {
|
||||
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
width: 2.0,
|
||||
width: 1.0,
|
||||
radius: Radius::new(5.0),
|
||||
};
|
||||
},
|
||||
@@ -45,7 +45,7 @@ fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style
|
||||
button::Status::Hovered => {
|
||||
res_stile.border = Border {
|
||||
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
width: 2.0,
|
||||
width: 1.0,
|
||||
radius: Radius::new(5.0),
|
||||
};
|
||||
},
|
||||
@@ -55,32 +55,6 @@ fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style
|
||||
return res_stile;
|
||||
}
|
||||
|
||||
// fn view() -> container::Style {
|
||||
// container::Style {
|
||||
// text_color: None,
|
||||
// background: None,
|
||||
// border: Border {
|
||||
// color: Color::BLACK,
|
||||
// width: 2.0,
|
||||
// radius: Radius::new(5.0),
|
||||
// },
|
||||
// shadow: None,
|
||||
// snap: false,
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn border_style(theme: &Theme) -> container::Style {
|
||||
// use iced::{Border, border::Radius};
|
||||
|
||||
// container::Style {
|
||||
// border: Border {
|
||||
// color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
// width: 2.0,
|
||||
// radius: Radius::new(5.0),
|
||||
// },
|
||||
// ..container::bordered_box(theme)
|
||||
// }
|
||||
// }
|
||||
|
||||
// Assuming your Item struct or type implements Display or has a text representation
|
||||
pub fn list_view<T: Display>(
|
||||
+2
-19
@@ -33,6 +33,7 @@ use crate::stages::welcome::WelcomeStage;
|
||||
|
||||
rust_i18n::i18n!("src/locales", fallback = "en");
|
||||
mod kira_theming;
|
||||
mod kira_scroll_list;
|
||||
mod stage;
|
||||
mod stages;
|
||||
|
||||
@@ -90,17 +91,6 @@ impl KiraState {
|
||||
}
|
||||
}
|
||||
|
||||
// impl KiraState {
|
||||
// fn new(toml_config: toml::Table) -> Self {
|
||||
|
||||
// Self {
|
||||
// current_view: Views::Start,
|
||||
// toml_config: toml_config,
|
||||
// config: KiraConfig { config_trail: Vec::new() }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
fn view(k_state: &KiraState) -> Element<'_, Message> {
|
||||
match &k_state.current_view {
|
||||
@@ -232,15 +222,8 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn main_interface() -> iced::Result {
|
||||
// iced::run(WellcomeStage::update, WellcomeStage::view)
|
||||
// }
|
||||
|
||||
pub fn main() -> ExitCode {
|
||||
// let app_init = || {
|
||||
// let mut k_state = KiraState::default()
|
||||
// k_state.current_view = Views::Welcome(WelcomeStage::new());
|
||||
// k_stateapp_init
|
||||
// };
|
||||
|
||||
let iced_result = iced::application(KiraState::boot, update, view)
|
||||
.window(iced::window::Settings {
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
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 {
|
||||
//let palette = theme.extended_palette();
|
||||
use iced::{Border, border::Radius};
|
||||
|
||||
match status {
|
||||
button::Status::Hovered => button::Style {
|
||||
border: Border {
|
||||
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
width: 2.0,
|
||||
radius: Radius::new(5.0),
|
||||
},
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
button::Status::Active => button::Style {
|
||||
background: Some(iced::Background::Color(crate::kira_theming::change_lightnes(
|
||||
&theme.palette().primary,
|
||||
-0.1,
|
||||
))),
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
_ => button::primary(theme, status),
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||
//let palette = theme.extended_palette();
|
||||
|
||||
match status {
|
||||
button::Status::Active => button::Style {
|
||||
background: Some(iced::Background::Color(Color::from_rgb(0.8, 0.3, 0.3))),
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
_ => button::Style {
|
||||
background: Some(iced::Background::Color(Color::from_rgb(0.8, 0.3, 0.3))),
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// fn view() -> container::Style {
|
||||
// container::Style {
|
||||
// text_color: None,
|
||||
// background: None,
|
||||
// border: Border {
|
||||
// color: Color::BLACK,
|
||||
// width: 2.0,
|
||||
// radius: Radius::new(5.0),
|
||||
// },
|
||||
// shadow: None,
|
||||
// snap: false,
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn border_style(theme: &Theme) -> container::Style {
|
||||
// use iced::{Border, border::Radius};
|
||||
|
||||
// container::Style {
|
||||
// border: Border {
|
||||
// color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
// width: 2.0,
|
||||
// radius: Radius::new(5.0),
|
||||
// },
|
||||
// ..container::bordered_box(theme)
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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))
|
||||
.style(container::bordered_box)
|
||||
.height(container_height)
|
||||
.padding(8)
|
||||
.into()
|
||||
}
|
||||
@@ -23,7 +23,7 @@ use iced::{Alignment, Length, widget};
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod scroll_list;
|
||||
use crate::kira_scroll_list;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TimeZoneData {
|
||||
@@ -61,8 +61,8 @@ pub struct TimeZoneStage {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectRegion(scroll_list::ListViewMessage),
|
||||
SelectZone(scroll_list::ListViewMessage),
|
||||
SelectRegion(kira_scroll_list::ListViewMessage),
|
||||
SelectZone(kira_scroll_list::ListViewMessage),
|
||||
Next,
|
||||
Back,
|
||||
}
|
||||
@@ -177,7 +177,7 @@ impl TimeZoneStage {
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
match message {
|
||||
Message::SelectRegion(scroll_list::ListViewMessage::Select(region_id)) => {
|
||||
Message::SelectRegion(kira_scroll_list::ListViewMessage::Select(region_id)) => {
|
||||
let region = self.regions.get(region_id).unwrap();
|
||||
self.zones = self
|
||||
.time_zones
|
||||
@@ -191,7 +191,7 @@ impl TimeZoneStage {
|
||||
//self.selected_zone_text.clear();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectZone(scroll_list::ListViewMessage::Select(zone_id)) => {
|
||||
Message::SelectZone(kira_scroll_list::ListViewMessage::Select(zone_id)) => {
|
||||
let zone = TimeZoneData {
|
||||
region: self.regions[self.region_id.unwrap()].clone(),
|
||||
zone: self.zones[zone_id].clone(),
|
||||
@@ -218,12 +218,12 @@ impl TimeZoneStage {
|
||||
widget::column![
|
||||
widget::text(t!("timezone.select_timezone")),
|
||||
widget::row![
|
||||
scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||
kira_scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||
.map(Message::SelectRegion),
|
||||
scroll_list::list_view(&self.zones, self.zone_id, Length::FillPortion(1))
|
||||
kira_scroll_list::list_view(&self.zones, self.zone_id, Length::FillPortion(1))
|
||||
.map(Message::SelectZone),
|
||||
]
|
||||
.padding(20)
|
||||
.padding([0,10])
|
||||
.spacing(10)
|
||||
.height(Length::Shrink),
|
||||
widget::text(self.selected_zone_text.clone())
|
||||
|
||||
Reference in New Issue
Block a user