Fix: Text output

- Display weather details instead of empty strings
This commit is contained in:
Candifloss 2025-11-07 11:44:36 +05:30
parent 90aca71e57
commit da209164c7
2 changed files with 81 additions and 24 deletions

View File

@ -11,7 +11,7 @@ reqwest = {version = "0.12.23", features = ["blocking", "json"] }
toml = "0.9.7" toml = "0.9.7"
dirs = "6.0.0" dirs = "6.0.0"
serde_json = "1.0.145" serde_json = "1.0.145"
iced = "0.13.1" iced = {version="0.13.1", features = ["advanced"]}
# slint = "1.14.1" # slint = "1.14.1"
# [build-dependencies] # [build-dependencies]

View File

@ -1,5 +1,5 @@
use iced::{ use iced::{
Alignment, Font, Length, Point, Settings, Size, Alignment, Font, Length, Point, Settings, Size, Task,
alignment::{Horizontal, Vertical}, alignment::{Horizontal, Vertical},
font::Family, font::Family,
widget::{Column, Row, Space, Text, column, row}, widget::{Column, Row, Space, Text, column, row},
@ -9,7 +9,6 @@ use iced::{
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Message {} enum Message {}
#[derive(Default)]
struct WeatherPopup { struct WeatherPopup {
city: String, city: String,
country: String, country: String,
@ -21,42 +20,84 @@ struct WeatherPopup {
} }
impl 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<Message> {
Task::none()
}
fn view(&self) -> iced::Element<Message> { fn view(&self) -> iced::Element<Message> {
let default_font = "IosevkaTermSlab Nerd Font Mono";
column![ column![
// Proper string formatting // City and country
Row::with_children(vec![ Row::with_children(vec![
Text::new(format!("{}, {}", self.city, self.country)) Text::new(format!("{}, {}", self.city, self.country))
.size(20) .font(Font {
family: Family::Name(default_font),
..Font::DEFAULT
})
.size(16)
.into(), .into(),
]), ])
.width(Length::Fill),
// Weather icon and temperature
Row::with_children(vec![ Row::with_children(vec![
Text::new(icon_to_nerd_font(&self.icon_code)) Text::new(icon_to_nerd_font(&self.icon_code))
.font(Font { .font(Font {
family: Family::Name("IosevkaTermSlab Nerd Font Mono"), family: Family::Name(default_font),
..Font::DEFAULT ..Font::DEFAULT
}) })
.align_x(Horizontal::Left)
.size(40) .size(40)
.into(), .into(),
Space::with_width(Length::Fixed(8.0)).into(), Space::with_width(Length::Fill).into(),
Text::new(format!("{}°{}", self.temperature, self.unit)) Text::new(format!("{}°{}", self.temperature, self.unit))
.font(Font {
family: Family::Name(default_font),
..Font::DEFAULT
})
.size(32) .size(32)
.into(), .into(),
]), ])
.width(Length::Fill),
// Weather description
Row::with_children(vec![ Row::with_children(vec![
Text::new(format!( Text::new(format!(
"{} - {}", "{} - {}",
self.weather_main, self.weather_description self.weather_main, self.weather_description
)) ))
.font(Font {
family: Family::Name(default_font),
..Font::DEFAULT
})
.size(16) .size(16)
.into(), .into(),
]), ])
.width(Length::Fill),
] ]
.spacing(10)
.padding(20)
.align_x(Horizontal::Center)
.into() .into()
} }
// Something
} }
pub fn show_popup( pub fn show_popup(
@ -68,17 +109,33 @@ pub fn show_popup(
temperature: String, temperature: String,
unit: char, unit: char,
) -> iced::Result { ) -> iced::Result {
// Something iced::application(
iced::application("OWMPopup", WeatherPopup::update, WeatherPopup::view) "Weather Popup", // Title
.window(window::Settings { WeatherPopup::update,
size: Size { WeatherPopup::view,
width: 300., )
height: 124., .window(window::Settings {
}, size: Size {
position: window::Position::Specific(Point { x: 200., y: 60. }), width: 300.,
..window::Settings::default() height: 150.,
}) },
.run() 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. /// Convert OWM icon codes (e.g. "01d", "09n") to Nerd Font weather glyphs.