mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
get test image showing
This commit is contained in:
parent
34a314df5a
commit
a19a98c86c
3 changed files with 1793 additions and 65 deletions
1736
rust/Cargo.lock
generated
1736
rust/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,4 +5,6 @@ edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.44"
|
chrono = "0.4.44"
|
||||||
iced = "0.14.0"
|
iced = { version = "0.14.0", features = ["image"] }
|
||||||
|
reqwest = "0.13.2"
|
||||||
|
ureq = "3.2.0"
|
||||||
|
|
|
||||||
118
rust/src/main.rs
118
rust/src/main.rs
|
|
@ -1,12 +1,8 @@
|
||||||
use iced::Application;
|
|
||||||
use iced::Center;
|
use iced::Center;
|
||||||
|
use iced::widget::{Column, PaneGrid, button, column, text, image,row,Row,};
|
||||||
use iced::Element;
|
use iced::Element;
|
||||||
use iced::executor;
|
|
||||||
use iced::widget::{Column, button, column,PaneGrid, text};
|
|
||||||
use iced::window;
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
iced::run(Counter::update, Counter::view)
|
iced::application(State::default, State::update, State::view).run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
@ -16,14 +12,61 @@ enum Sport {
|
||||||
MLB,
|
MLB,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct State {
|
struct State {
|
||||||
current_time: chrono::DateTime<chrono::Utc>,
|
current_time: chrono::DateTime<chrono::Utc>,
|
||||||
next_alarm: Option<chrono::DateTime<chrono::Utc>>,
|
next_alarm: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
news: Vec<String>,
|
news: Vec<String>,
|
||||||
weather: String,
|
weather: Vec<u8>,
|
||||||
location: String,
|
location: String,
|
||||||
scores: Vec<Game>,
|
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)]
|
#[derive(Debug)]
|
||||||
struct Game {
|
struct Game {
|
||||||
sport: Sport,
|
sport: Sport,
|
||||||
|
|
@ -43,34 +86,20 @@ impl Game {
|
||||||
score2: score2.to_string(),
|
score2: score2.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, score1: &str, score2: &str) {
|
fn update(&mut self, score1: &str, score2: &str) {
|
||||||
self.score1 = score1.to_string();
|
self.score1 = score1.to_string();
|
||||||
self.score2 = score2.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 {
|
fn sports() -> State {
|
||||||
println!("Sports!");
|
println!("Sports!");
|
||||||
|
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
current_time: chrono::Utc::now(),
|
current_time: chrono::Utc::now(),
|
||||||
next_alarm: Some(chrono::Utc::now() + chrono::Duration::hours(1)),
|
next_alarm: Some(chrono::Utc::now() + chrono::Duration::hours(1)),
|
||||||
news: vec!["Breaking news!".to_string()],
|
news: vec!["Breaking news!".to_string()],
|
||||||
weather: "Sunny".to_string(),
|
weather: Vec::new(),
|
||||||
location: "Sacramento".to_string(),
|
location: "Sacramento".to_string(),
|
||||||
scores: Vec::new(),
|
scores: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
@ -86,7 +115,8 @@ fn sports() -> State {
|
||||||
.push(Game::new(Sport::MLB, "Red Sox", "Yankees", "100", "95"));
|
.push(Game::new(Sport::MLB, "Red Sox", "Yankees", "100", "95"));
|
||||||
println!("{:?}", state.current_time);
|
println!("{:?}", state.current_time);
|
||||||
println!("---------------");
|
println!("---------------");
|
||||||
|
|
||||||
|
|
||||||
for game in &state.scores {
|
for game in &state.scores {
|
||||||
println!("+----------------------+");
|
println!("+----------------------+");
|
||||||
println!("| Sport: {:?}", game.sport);
|
println!("| Sport: {:?}", game.sport);
|
||||||
|
|
@ -96,41 +126,3 @@ fn sports() -> State {
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue