get test image showing

This commit is contained in:
death916 2026-03-06 05:51:45 -08:00
parent 34a314df5a
commit a19a98c86c
3 changed files with 1793 additions and 65 deletions

1736
rust/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,4 +5,6 @@ edition = "2024"
[dependencies]
chrono = "0.4.44"
iced = "0.14.0"
iced = { version = "0.14.0", features = ["image"] }
reqwest = "0.13.2"
ureq = "3.2.0"

View file

@ -1,12 +1,8 @@
use iced::Application;
use iced::Center;
use iced::widget::{Column, PaneGrid, button, column, text, image,row,Row,};
use iced::Element;
use iced::executor;
use iced::widget::{Column, button, column,PaneGrid, text};
use iced::window;
pub fn main() -> iced::Result {
iced::run(Counter::update, Counter::view)
iced::application(State::default, State::update, State::view).run()
}
#[derive(Debug, Clone)]
@ -16,14 +12,61 @@ enum Sport {
MLB,
}
#[derive(Debug)]
struct State {
current_time: chrono::DateTime<chrono::Utc>,
next_alarm: Option<chrono::DateTime<chrono::Utc>>,
news: Vec<String>,
weather: String,
weather: Vec<u8>,
location: String,
scores: Vec<Game>,
}
impl State {
fn update(&mut self, scores: Vec<Game>) {
self.scores = scores;
}
fn view(&self) -> Element<'_, Vec<Game>> {
let game = sports();
let games = game.scores;
let weather_img = image::Handle::from_bytes(self.weather.clone());
column![
text("scores").size(50),
//text().size(20),
text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20),
text(format!("{} - {}", games[0].score1, games[0].score2)).size(20),
row![
text("Weather").size(20),
image(weather_img).width(50),
text(self.location.clone()).size(20),
]
]
.padding(20)
.align_x(Center)
.into()
}
}
impl Default for State {
fn default() -> Self {
let text = ureq::get("https://github.com/iced-rs/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true")
.call().unwrap()
.body_mut()
.read_to_vec().unwrap();
State {
current_time: chrono::Utc::now(),
next_alarm: None,
news: Vec::new(),
weather: text,
location: "Sacramento".to_string(),
scores: Vec::new(),
}
}
}
#[derive(Debug)]
struct Game {
sport: Sport,
@ -43,34 +86,20 @@ impl Game {
score2: score2.to_string(),
}
}
fn update(&mut self, score1: &str, score2: &str) {
self.score1 = score1.to_string();
self.score2 = score2.to_string();
}
fn view(&self) -> Column<'_, Message> {
let game = sports();
let games = game.scores;
column![
text("scores").size(50),
//text().size(20),
text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20),
text(format!("{} - {}", games[0].score1, games[0].score2)).size(20),
]
.padding(20)
.align_x(Center)
}
}
fn sports() -> State {
println!("Sports!");
let mut state = State {
current_time: chrono::Utc::now(),
next_alarm: Some(chrono::Utc::now() + chrono::Duration::hours(1)),
news: vec!["Breaking news!".to_string()],
weather: "Sunny".to_string(),
weather: Vec::new(),
location: "Sacramento".to_string(),
scores: Vec::new(),
};
@ -86,7 +115,8 @@ fn sports() -> State {
.push(Game::new(Sport::MLB, "Red Sox", "Yankees", "100", "95"));
println!("{:?}", state.current_time);
println!("---------------");
for game in &state.scores {
println!("+----------------------+");
println!("| Sport: {:?}", game.sport);
@ -96,41 +126,3 @@ fn sports() -> State {
}
state
}
#[derive(Default)]
struct Counter {
value: i64,
}
#[derive(Debug, Clone, Copy)]
enum Message {
Increment,
Decrement,
}
impl Counter {
fn update(&mut self, message: Message) {
match message {
Message::Increment => {
self.value += 1;
}
Message::Decrement => {
self.value -= 1;
}
}
}
fn view(&self) -> Column<'_, Message> {
let game = sports();
let games = game.scores;
column![
text(self.value).size(50),
//text().size(20),
text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20),
text(format!("{} - {}", games[0].score1, games[0].score2)).size(20),
]
.padding(20)
.align_x(Center)
}
}