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::{
|
||||
Column,
|
||||
Container,
|
||||
button,
|
||||
text,
|
||||
pane_grid::{self, PaneGrid}
|
||||
},
|
||||
@ -56,18 +55,20 @@ pub struct CalendarApp {
|
||||
view_date: NaiveDate,
|
||||
controls: Controls,
|
||||
grid_state: pane_grid::State<PaneGridState>,
|
||||
main_pane: pane_grid::Pane,
|
||||
events: EventsCollection,
|
||||
}
|
||||
|
||||
impl Default for CalendarApp {
|
||||
|
||||
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 {
|
||||
view_date: NaiveDate::default(),
|
||||
controls: Controls::default(),
|
||||
grid_state,
|
||||
main_pane,
|
||||
events: EventsCollection::default(),
|
||||
}
|
||||
}
|
||||
@ -126,8 +127,7 @@ impl CalendarApp {
|
||||
self.grid_state.close(sidebar_pane);
|
||||
} else {
|
||||
// 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, pane, PaneGridState{pane_type: PaneType::Sidebar}) {
|
||||
if let Some((new_pane, split)) = self.grid_state.split(pane_grid::Axis::Vertical, self.main_pane, PaneGridState{pane_type: PaneType::Sidebar}) {
|
||||
self.grid_state.move_to_edge(new_pane, pane_grid::Edge::Left);
|
||||
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 {
|
||||
CalendarView::new(
|
||||
self.controls.mode.unwrap_or(ViewMode::Year),
|
||||
|
@ -16,7 +16,7 @@ use iced::{
|
||||
alignment,
|
||||
theme::palette,
|
||||
border,
|
||||
widget::{Row, button::{Status, Style, secondary}, row, text, button}
|
||||
widget::{button::{Status, Style, secondary}, row, text, button}
|
||||
};
|
||||
|
||||
//#[derive(Default)]
|
||||
@ -41,33 +41,29 @@ impl Controls {
|
||||
Some(ViewMode::Week) => view_date.format_localized("%B", self.locale).to_string(),
|
||||
_ => "".to_string()
|
||||
};
|
||||
Row::new()
|
||||
.align_y(Alignment::Center)
|
||||
.padding(5)
|
||||
.spacing(10)
|
||||
.push(button(text("=")).on_press(Message::ToggleSidebar).style(secondary))
|
||||
.push(row![
|
||||
row![
|
||||
button(text("=")).on_press(Message::ToggleSidebar).style(secondary),
|
||||
row![
|
||||
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("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_next()).style(secondary),
|
||||
].spacing(0).padding(0)
|
||||
)
|
||||
.push(
|
||||
text(description)
|
||||
.width(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Left)
|
||||
.size(24),
|
||||
)
|
||||
.push(
|
||||
text(view_date.year().to_string())
|
||||
.width(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Right)
|
||||
.size(40),
|
||||
)
|
||||
].spacing(0).padding(0),
|
||||
text(description)
|
||||
.width(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Left)
|
||||
.size(24),
|
||||
text(view_date.year().to_string())
|
||||
.width(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Right)
|
||||
.size(40),
|
||||
]
|
||||
.align_y(Alignment::Center)
|
||||
.padding(5)
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user