mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
add mlb pane
This commit is contained in:
parent
67307043d6
commit
e55e2240dd
2 changed files with 56 additions and 14 deletions
|
|
@ -33,7 +33,9 @@ struct State {
|
|||
news: Vec<String>,
|
||||
weather: Vec<u8>,
|
||||
location: String,
|
||||
scores: Vec<Game>,
|
||||
nba_scores: Vec<Game>,
|
||||
mlb_scores: Vec<Game>,
|
||||
// nfl_scores: Vec<Game>,
|
||||
panes: pane_grid::State<PaneType>,
|
||||
}
|
||||
impl State {
|
||||
|
|
@ -53,7 +55,7 @@ impl State {
|
|||
pane_grid(&state.panes, |_panes, pane_state, _is_maximized| {
|
||||
let content: Element<'_, Message> = match pane_state {
|
||||
PaneType::NbaPane => {
|
||||
let games = &state.scores;
|
||||
let games = &state.nba_scores;
|
||||
column(games.iter().map(|game| {
|
||||
container(
|
||||
column![
|
||||
|
|
@ -94,7 +96,47 @@ impl State {
|
|||
.into()
|
||||
}
|
||||
PaneType::NflPane => text("NFL").into(),
|
||||
PaneType::MlbPane => text("MLB").into(),
|
||||
PaneType::MlbPane => {
|
||||
let games = &state.mlb_scores;
|
||||
column(games.iter().map(|game| {
|
||||
container(
|
||||
column![
|
||||
row![
|
||||
text(&game.team1).size(20).width(Fill),
|
||||
text(&game.team2).size(20).width(Fill),
|
||||
],
|
||||
row![
|
||||
text(&game.score1).size(20).width(Fill),
|
||||
text(&game.score2).size(20).width(Fill),
|
||||
],
|
||||
text(format!("Period: {}", game.period)).size(14),
|
||||
]
|
||||
.padding(10),
|
||||
)
|
||||
.padding(5)
|
||||
.width(Fill)
|
||||
.style(|_| container::Style {
|
||||
background: Some(iced::Background::Color(iced::Color::from_rgb(
|
||||
0.2, 0.2, 0.2,
|
||||
))),
|
||||
border: Border {
|
||||
width: 1.0,
|
||||
color: iced::Color::WHITE,
|
||||
radius: 0.0.into(),
|
||||
},
|
||||
text_color: Some(iced::Color::WHITE),
|
||||
snap: true,
|
||||
shadow: iced::Shadow {
|
||||
color: iced::Color::BLACK,
|
||||
offset: iced::Vector::new(0.0, 0.0),
|
||||
blur_radius: 10.0,
|
||||
},
|
||||
})
|
||||
.into()
|
||||
}))
|
||||
.padding(0)
|
||||
.into()
|
||||
}
|
||||
PaneType::Main => text("Main").into(),
|
||||
PaneType::Clock => text("clock").into(),
|
||||
PaneType::Weather => {
|
||||
|
|
@ -138,7 +180,8 @@ impl Default for State {
|
|||
news: Vec::new(),
|
||||
weather: text,
|
||||
location: "Sacramento".to_string(),
|
||||
scores: { sports::update_nba() },
|
||||
nba_scores: { sports::update_nba() },
|
||||
mlb_scores: { sports::update_mlb() },
|
||||
panes: {
|
||||
let (mut panes, nba) = pane_grid::State::new(PaneType::NbaPane);
|
||||
let (weather, _) = panes
|
||||
|
|
@ -151,7 +194,5 @@ impl Default for State {
|
|||
panes
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl Game {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_mlb() {
|
||||
pub fn update_mlb() -> Vec<Game> {
|
||||
let date = chrono::Local::now().format("%Y-%m-%d").to_string();
|
||||
let mlb_url = format!(
|
||||
"https://statsapi.mlb.com/api/v1/schedule?sportId=1&date={}",
|
||||
|
|
@ -62,11 +62,13 @@ pub fn update_mlb() {
|
|||
|
||||
for game in games {
|
||||
let home_team = game["teams"]["away"]["team"]["name"].as_str().unwrap();
|
||||
println!("Home Team: {}", home_team);
|
||||
let away_team = game["teams"]["home"]["team"]["name"].as_str().unwrap();
|
||||
println!("Away Team: {}", away_team);
|
||||
let home_score = game["teams"]["away"]["score"].as_str().unwrap_or_else(|| "0");
|
||||
let away_score = game["teams"]["home"]["score"].as_str().unwrap_or_else(|| "0");
|
||||
let home_score = game["teams"]["away"]["score"]
|
||||
.as_str()
|
||||
.unwrap_or_else(|| "0");
|
||||
let away_score = game["teams"]["home"]["score"]
|
||||
.as_str()
|
||||
.unwrap_or_else(|| "0");
|
||||
let period = game["status"]["period"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
|
|
@ -90,8 +92,7 @@ pub fn update_mlb() {
|
|||
println!("Period: {}", period);
|
||||
}
|
||||
|
||||
|
||||
// mlb_games_vec
|
||||
mlb_games_vec
|
||||
}
|
||||
|
||||
pub fn update_nba() -> Vec<Game> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue