Fix: Text output
- Display weather details instead of empty strings
This commit is contained in:
parent
90aca71e57
commit
da209164c7
@ -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]
|
||||
|
||||
@ -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<Message> {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> iced::Element<Message> {
|
||||
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)
|
||||
iced::application(
|
||||
"Weather Popup", // Title
|
||||
WeatherPopup::update,
|
||||
WeatherPopup::view,
|
||||
)
|
||||
.window(window::Settings {
|
||||
size: Size {
|
||||
width: 300.,
|
||||
height: 124.,
|
||||
height: 150.,
|
||||
},
|
||||
position: window::Position::Specific(Point { x: 200., y: 60. }),
|
||||
position: window::Position::Specific(Point { x: 20., y: 20. }),
|
||||
..window::Settings::default()
|
||||
})
|
||||
.run()
|
||||
.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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user