diff --git a/widget/Cargo.toml b/widget/Cargo.toml index b953b1e..c7b5bac 100644 --- a/widget/Cargo.toml +++ b/widget/Cargo.toml @@ -11,7 +11,7 @@ reqwest = {version = "0.12.23", features = ["blocking", "json"] } toml = "0.9.7" dirs = "6.0.0" serde_json = "1.0.145" -iced = "0.13.1" +iced = {version="0.13.1", features = ["advanced"]} # slint = "1.14.1" # [build-dependencies] diff --git a/widget/src/show_popup.rs b/widget/src/show_popup.rs index daf55c0..fe36ed4 100644 --- a/widget/src/show_popup.rs +++ b/widget/src/show_popup.rs @@ -1,5 +1,5 @@ use iced::{ - Alignment, Font, Length, Point, Settings, Size, + Alignment, Font, Length, Point, Settings, Size, Task, alignment::{Horizontal, Vertical}, font::Family, widget::{Column, Row, Space, Text, column, row}, @@ -9,7 +9,6 @@ use iced::{ #[derive(Debug, Clone)] enum Message {} -#[derive(Default)] struct WeatherPopup { city: String, country: String, @@ -21,42 +20,84 @@ struct WeatherPopup { } impl WeatherPopup { - fn update(&mut self, _message: Message) {} + fn new( + city: String, + country: String, + weather_main: String, + weather_description: String, + icon_code: String, + temperature: String, + unit: char, + ) -> Self { + Self { + city, + country, + weather_main, + weather_description, + icon_code, + temperature, + unit, + } + } + + fn update(&mut self, _message: Message) -> Task { + Task::none() + } fn view(&self) -> iced::Element { + let default_font = "IosevkaTermSlab Nerd Font Mono"; column![ - // Proper string formatting + // City and country Row::with_children(vec![ Text::new(format!("{}, {}", self.city, self.country)) - .size(20) + .font(Font { + family: Family::Name(default_font), + ..Font::DEFAULT + }) + .size(16) .into(), - ]), + ]) + .width(Length::Fill), + // Weather icon and temperature Row::with_children(vec![ Text::new(icon_to_nerd_font(&self.icon_code)) .font(Font { - family: Family::Name("IosevkaTermSlab Nerd Font Mono"), + family: Family::Name(default_font), ..Font::DEFAULT }) + .align_x(Horizontal::Left) .size(40) .into(), - Space::with_width(Length::Fixed(8.0)).into(), + Space::with_width(Length::Fill).into(), Text::new(format!("{}°{}", self.temperature, self.unit)) + .font(Font { + family: Family::Name(default_font), + ..Font::DEFAULT + }) .size(32) .into(), - ]), + ]) + .width(Length::Fill), + // Weather description Row::with_children(vec![ Text::new(format!( "{} - {}", self.weather_main, self.weather_description )) + .font(Font { + family: Family::Name(default_font), + ..Font::DEFAULT + }) .size(16) .into(), - ]), + ]) + .width(Length::Fill), ] + .spacing(10) + .padding(20) + .align_x(Horizontal::Center) .into() } - - // Something } pub fn show_popup( @@ -68,17 +109,33 @@ pub fn show_popup( temperature: String, unit: char, ) -> iced::Result { - // Something - iced::application("OWMPopup", WeatherPopup::update, WeatherPopup::view) - .window(window::Settings { - size: Size { - width: 300., - height: 124., - }, - position: window::Position::Specific(Point { x: 200., y: 60. }), - ..window::Settings::default() - }) - .run() + iced::application( + "Weather Popup", // Title + WeatherPopup::update, + WeatherPopup::view, + ) + .window(window::Settings { + size: Size { + width: 300., + height: 150., + }, + position: window::Position::Specific(Point { x: 20., y: 20. }), + ..window::Settings::default() + }) + .run_with(move || { + ( + WeatherPopup::new( + city, + country, + weather_main, + weather_description, + icon_code, + temperature, + unit, + ), + Task::none(), + ) + }) } /// Convert OWM icon codes (e.g. "01d", "09n") to Nerd Font weather glyphs.