Start converting slint to iced
- Port the `slint` code to `iced` - Display basic window and text
This commit is contained in:
parent
020be1d5e9
commit
90aca71e57
@ -2,7 +2,7 @@
|
|||||||
name = "openweatherwidget"
|
name = "openweatherwidget"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
build = "build.rs"
|
#build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
owm-rs = { git = "https://git.candifloss.cc/candifloss/OpenWeatherMapSDK.git" }
|
owm-rs = { git = "https://git.candifloss.cc/candifloss/OpenWeatherMapSDK.git" }
|
||||||
@ -11,7 +11,8 @@ 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"
|
||||||
slint = "1.14.1"
|
iced = "0.13.1"
|
||||||
|
# slint = "1.14.1"
|
||||||
|
|
||||||
[build-dependencies]
|
# [build-dependencies]
|
||||||
slint-build = "1.14.1"
|
# slint-build = "1.14.1"
|
||||||
|
|||||||
@ -45,7 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
"standard" => 'K',
|
"standard" => 'K',
|
||||||
_ => '?',
|
_ => '?',
|
||||||
};
|
};
|
||||||
|
|
||||||
show_popup::show_popup(
|
show_popup::show_popup(
|
||||||
city,
|
city,
|
||||||
country,
|
country,
|
||||||
|
|||||||
@ -1,8 +1,64 @@
|
|||||||
use slint::SharedString;
|
use iced::{
|
||||||
|
Alignment, Font, Length, Point, Settings, Size,
|
||||||
|
alignment::{Horizontal, Vertical},
|
||||||
|
font::Family,
|
||||||
|
widget::{Column, Row, Space, Text, column, row},
|
||||||
|
window,
|
||||||
|
};
|
||||||
|
|
||||||
slint::include_modules!();
|
#[derive(Debug, Clone)]
|
||||||
|
enum Message {}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct WeatherPopup {
|
||||||
|
city: String,
|
||||||
|
country: String,
|
||||||
|
weather_main: String,
|
||||||
|
weather_description: String,
|
||||||
|
icon_code: String,
|
||||||
|
temperature: String,
|
||||||
|
unit: char,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WeatherPopup {
|
||||||
|
fn update(&mut self, _message: Message) {}
|
||||||
|
|
||||||
|
fn view(&self) -> iced::Element<Message> {
|
||||||
|
column![
|
||||||
|
// Proper string formatting
|
||||||
|
Row::with_children(vec![
|
||||||
|
Text::new(format!("{}, {}", self.city, self.country))
|
||||||
|
.size(20)
|
||||||
|
.into(),
|
||||||
|
]),
|
||||||
|
Row::with_children(vec![
|
||||||
|
Text::new(icon_to_nerd_font(&self.icon_code))
|
||||||
|
.font(Font {
|
||||||
|
family: Family::Name("IosevkaTermSlab Nerd Font Mono"),
|
||||||
|
..Font::DEFAULT
|
||||||
|
})
|
||||||
|
.size(40)
|
||||||
|
.into(),
|
||||||
|
Space::with_width(Length::Fixed(8.0)).into(),
|
||||||
|
Text::new(format!("{}°{}", self.temperature, self.unit))
|
||||||
|
.size(32)
|
||||||
|
.into(),
|
||||||
|
]),
|
||||||
|
Row::with_children(vec![
|
||||||
|
Text::new(format!(
|
||||||
|
"{} - {}",
|
||||||
|
self.weather_main, self.weather_description
|
||||||
|
))
|
||||||
|
.size(16)
|
||||||
|
.into(),
|
||||||
|
]),
|
||||||
|
]
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Something
|
||||||
|
}
|
||||||
|
|
||||||
/// Create and show the UI window populated with weather data.
|
|
||||||
pub fn show_popup(
|
pub fn show_popup(
|
||||||
city: String,
|
city: String,
|
||||||
country: String,
|
country: String,
|
||||||
@ -11,18 +67,18 @@ pub fn show_popup(
|
|||||||
icon_code: String,
|
icon_code: String,
|
||||||
temperature: String,
|
temperature: String,
|
||||||
unit: char,
|
unit: char,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> iced::Result {
|
||||||
let ui = MainWindow::new()?;
|
// Something
|
||||||
ui.set_city(SharedString::from(city));
|
iced::application("OWMPopup", WeatherPopup::update, WeatherPopup::view)
|
||||||
ui.set_country(SharedString::from(country));
|
.window(window::Settings {
|
||||||
ui.set_weather_main(SharedString::from(weather_main));
|
size: Size {
|
||||||
ui.set_weather_description(SharedString::from(weather_description));
|
width: 300.,
|
||||||
ui.set_weather_icon(SharedString::from(icon_to_nerd_font(&icon_code)));
|
height: 124.,
|
||||||
ui.set_temperature(SharedString::from(temperature));
|
},
|
||||||
ui.set_unit(SharedString::from(unit));
|
position: window::Position::Specific(Point { x: 200., y: 60. }),
|
||||||
|
..window::Settings::default()
|
||||||
ui.run()?;
|
})
|
||||||
Ok(())
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
|||||||
44
widget/src/show_popup.rs.old
Normal file
44
widget/src/show_popup.rs.old
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use slint::SharedString;
|
||||||
|
|
||||||
|
slint::include_modules!();
|
||||||
|
|
||||||
|
/// Create and show the UI window populated with weather data.
|
||||||
|
pub fn show_popup(
|
||||||
|
city: String,
|
||||||
|
country: String,
|
||||||
|
weather_main: String,
|
||||||
|
weather_description: String,
|
||||||
|
icon_code: String,
|
||||||
|
temperature: String,
|
||||||
|
unit: char,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let ui = MainWindow::new()?;
|
||||||
|
ui.set_city(SharedString::from(city));
|
||||||
|
ui.set_country(SharedString::from(country));
|
||||||
|
ui.set_weather_main(SharedString::from(weather_main));
|
||||||
|
ui.set_weather_description(SharedString::from(weather_description));
|
||||||
|
ui.set_weather_icon(SharedString::from(icon_to_nerd_font(&icon_code)));
|
||||||
|
ui.set_temperature(SharedString::from(temperature));
|
||||||
|
ui.set_unit(SharedString::from(unit));
|
||||||
|
|
||||||
|
ui.run()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert OWM icon codes (e.g. "01d", "09n") to Nerd Font weather glyphs.
|
||||||
|
fn icon_to_nerd_font(code: &str) -> String {
|
||||||
|
match code {
|
||||||
|
"01d" => "", // clear day
|
||||||
|
"01n" => "", // clear night
|
||||||
|
"02d" | "02n" => "", // few clouds
|
||||||
|
"03d" | "03n" => "", // scattered clouds
|
||||||
|
"04d" | "04n" => "", // broken clouds
|
||||||
|
"09d" | "09n" => "", // shower rain
|
||||||
|
"10d" | "10n" => "", // rain
|
||||||
|
"11d" | "11n" => "", // thunderstorm
|
||||||
|
"13d" | "13n" => "", // snow
|
||||||
|
"50d" | "50n" => "", // mist
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user