small refactor
This commit is contained in:
parent
e9a002ccc1
commit
fdc08e9806
13
src/app.rs
13
src/app.rs
|
@ -23,7 +23,6 @@ use iced::{
|
||||||
widget::{
|
widget::{
|
||||||
Column,
|
Column,
|
||||||
Container,
|
Container,
|
||||||
button,
|
|
||||||
text,
|
text,
|
||||||
pane_grid::{self, PaneGrid}
|
pane_grid::{self, PaneGrid}
|
||||||
},
|
},
|
||||||
|
@ -56,18 +55,20 @@ pub struct CalendarApp {
|
||||||
view_date: NaiveDate,
|
view_date: NaiveDate,
|
||||||
controls: Controls,
|
controls: Controls,
|
||||||
grid_state: pane_grid::State<PaneGridState>,
|
grid_state: pane_grid::State<PaneGridState>,
|
||||||
|
main_pane: pane_grid::Pane,
|
||||||
events: EventsCollection,
|
events: EventsCollection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CalendarApp {
|
impl Default for CalendarApp {
|
||||||
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let (grid_state, _) = pane_grid::State::new(PaneGridState{pane_type: PaneType::Calendar});
|
let (grid_state, main_pane) = pane_grid::State::new(PaneGridState{pane_type: PaneType::Calendar});
|
||||||
|
|
||||||
CalendarApp {
|
CalendarApp {
|
||||||
view_date: NaiveDate::default(),
|
view_date: NaiveDate::default(),
|
||||||
controls: Controls::default(),
|
controls: Controls::default(),
|
||||||
grid_state,
|
grid_state,
|
||||||
|
main_pane,
|
||||||
events: EventsCollection::default(),
|
events: EventsCollection::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,8 +127,7 @@ impl CalendarApp {
|
||||||
self.grid_state.close(sidebar_pane);
|
self.grid_state.close(sidebar_pane);
|
||||||
} else {
|
} else {
|
||||||
// no sidebar: split the main pane (calendar) and move the new pane to the left
|
// no sidebar: split the main pane (calendar) and move the new pane to the left
|
||||||
let pane = self.get_main_pane();
|
if let Some((new_pane, split)) = self.grid_state.split(pane_grid::Axis::Vertical, self.main_pane, PaneGridState{pane_type: PaneType::Sidebar}) {
|
||||||
if let Some((new_pane, split)) = self.grid_state.split(pane_grid::Axis::Vertical, pane, PaneGridState{pane_type: PaneType::Sidebar}) {
|
|
||||||
self.grid_state.move_to_edge(new_pane, pane_grid::Edge::Left);
|
self.grid_state.move_to_edge(new_pane, pane_grid::Edge::Left);
|
||||||
self.grid_state.resize(split, 0.25);
|
self.grid_state.resize(split, 0.25);
|
||||||
};
|
};
|
||||||
|
@ -143,11 +143,6 @@ impl CalendarApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_main_pane(&self) -> pane_grid::Pane {
|
|
||||||
// TODO: assuming there is always a calendar pane
|
|
||||||
*(self.grid_state.iter().find(|&(_, pgs)| {pgs.pane_type == PaneType::Calendar}).unwrap().0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_calendar_view(&self) -> CalendarView {
|
fn get_calendar_view(&self) -> CalendarView {
|
||||||
CalendarView::new(
|
CalendarView::new(
|
||||||
self.controls.mode.unwrap_or(ViewMode::Year),
|
self.controls.mode.unwrap_or(ViewMode::Year),
|
||||||
|
|
|
@ -16,7 +16,7 @@ use iced::{
|
||||||
alignment,
|
alignment,
|
||||||
theme::palette,
|
theme::palette,
|
||||||
border,
|
border,
|
||||||
widget::{Row, button::{Status, Style, secondary}, row, text, button}
|
widget::{button::{Status, Style, secondary}, row, text, button}
|
||||||
};
|
};
|
||||||
|
|
||||||
//#[derive(Default)]
|
//#[derive(Default)]
|
||||||
|
@ -41,33 +41,29 @@ impl Controls {
|
||||||
Some(ViewMode::Week) => view_date.format_localized("%B", self.locale).to_string(),
|
Some(ViewMode::Week) => view_date.format_localized("%B", self.locale).to_string(),
|
||||||
_ => "".to_string()
|
_ => "".to_string()
|
||||||
};
|
};
|
||||||
Row::new()
|
row![
|
||||||
.align_y(Alignment::Center)
|
button(text("=")).on_press(Message::ToggleSidebar).style(secondary),
|
||||||
.padding(5)
|
row![
|
||||||
.spacing(10)
|
|
||||||
.push(button(text("=")).on_press(Message::ToggleSidebar).style(secondary))
|
|
||||||
.push(row![
|
|
||||||
button(text("Week")).on_press(Message::ViewModeSelected(ViewMode::Week)).style(self.get_mode_style(ViewMode::Week)),
|
button(text("Week")).on_press(Message::ViewModeSelected(ViewMode::Week)).style(self.get_mode_style(ViewMode::Week)),
|
||||||
button(text("Month")).on_press(Message::ViewModeSelected(ViewMode::Month)).style(self.get_mode_style(ViewMode::Month)),
|
button(text("Month")).on_press(Message::ViewModeSelected(ViewMode::Month)).style(self.get_mode_style(ViewMode::Month)),
|
||||||
button(text("Year")).on_press(Message::ViewModeSelected(ViewMode::Year)).style(self.get_mode_style(ViewMode::Year)),
|
button(text("Year")).on_press(Message::ViewModeSelected(ViewMode::Year)).style(self.get_mode_style(ViewMode::Year)),
|
||||||
])
|
],
|
||||||
.push(row![
|
row![
|
||||||
button(text("<")).on_press(self.get_msg_prev()).style(secondary),
|
button(text("<")).on_press(self.get_msg_prev()).style(secondary),
|
||||||
button(text(">")).on_press(self.get_msg_next()).style(secondary),
|
button(text(">")).on_press(self.get_msg_next()).style(secondary),
|
||||||
].spacing(0).padding(0)
|
].spacing(0).padding(0),
|
||||||
)
|
|
||||||
.push(
|
|
||||||
text(description)
|
text(description)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.align_x(alignment::Horizontal::Left)
|
.align_x(alignment::Horizontal::Left)
|
||||||
.size(24),
|
.size(24),
|
||||||
)
|
|
||||||
.push(
|
|
||||||
text(view_date.year().to_string())
|
text(view_date.year().to_string())
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.align_x(alignment::Horizontal::Right)
|
.align_x(alignment::Horizontal::Right)
|
||||||
.size(40),
|
.size(40),
|
||||||
)
|
]
|
||||||
|
.align_y(Alignment::Center)
|
||||||
|
.padding(5)
|
||||||
|
.spacing(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue