split panes

This commit is contained in:
death916 2026-03-11 03:57:17 -07:00
parent 7d0429ebb0
commit d8688b8fc8

View file

@ -15,7 +15,10 @@ enum Sport {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Pane { enum Pane {
Main, Main,
Sports, MlbPane,
NflPane,
NbaPane,
Weather,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -50,29 +53,25 @@ impl State {
fn view(state: &State) -> Element<'_, Message> { fn view(state: &State) -> Element<'_, Message> {
pane_grid(&state.panes, |_pane, pane_state, _is_maximized| { pane_grid(&state.panes, |_pane, pane_state, _is_maximized| {
let content: Element<'_, Message> = match pane_state { let content: Element<'_, Message> = match pane_state {
Pane::Main => { Pane::NbaPane => {
let games = &state.scores; let games = &state.scores;
let weather_img = image::Handle::from_bytes(state.weather.clone());
column![ column![
text("scores").size(50), text("NBA").size(50),
text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20), text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20),
text(format!("{} - {}", games[0].score1, games[0].score2)).size(20), text(format!("{} - {}", games[0].score1, games[0].score2)).size(20),
row![
text("Weather").size(20),
image(weather_img).width(50),
text(state.location.clone()).size(20),
]
] ]
.padding(20) .padding(20)
.align_x(Center)
.into() .into()
} }
Pane::Sports => { Pane::NflPane => text("NFL").into(),
let games = &state.scores; Pane::MlbPane => text("MLB").into(),
Pane::Main => text("Main").into(),
Pane::Weather => {
let weather_img = image::Handle::from_bytes(state.weather.clone());
column![ column![
text("Scores").size(50), text("Weather").size(50),
text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20), image(weather_img).width(50),
text(format!("{} - {}", games[0].score1, games[0].score2)).size(20), text(state.location.clone()).size(20),
] ]
.padding(20) .padding(20)
.into() .into()
@ -106,8 +105,14 @@ impl Default for State {
location: "Sacramento".to_string(), location: "Sacramento".to_string(),
scores: sports().scores, scores: sports().scores,
panes: { panes: {
let (mut panes, first) = pane_grid::State::new(Pane::Main); let (mut panes, nba) = pane_grid::State::new(Pane::NbaPane);
panes.split(pane_grid::Axis::Vertical, first, Pane::Sports); let (weather, _) = panes
.split(pane_grid::Axis::Vertical, nba, Pane::Weather)
.unwrap();
let (nfl, _) = panes
.split(pane_grid::Axis::Vertical, weather, Pane::NflPane)
.unwrap();
panes.split(pane_grid::Axis::Horizontal, nfl, Pane::MlbPane);
panes panes
}, },
} }