sidebar improvements: split value and list calendar files
This commit is contained in:
parent
fdc08e9806
commit
a3c8e60872
24
src/app.rs
24
src/app.rs
|
@ -21,6 +21,8 @@ use iced::{
|
||||||
Element,
|
Element,
|
||||||
Length,
|
Length,
|
||||||
widget::{
|
widget::{
|
||||||
|
column,
|
||||||
|
container,
|
||||||
Column,
|
Column,
|
||||||
Container,
|
Container,
|
||||||
text,
|
text,
|
||||||
|
@ -56,7 +58,9 @@ pub struct CalendarApp {
|
||||||
controls: Controls,
|
controls: Controls,
|
||||||
grid_state: pane_grid::State<PaneGridState>,
|
grid_state: pane_grid::State<PaneGridState>,
|
||||||
main_pane: pane_grid::Pane,
|
main_pane: pane_grid::Pane,
|
||||||
|
split_value: f32,
|
||||||
events: EventsCollection,
|
events: EventsCollection,
|
||||||
|
calendars: std::vec::Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CalendarApp {
|
impl Default for CalendarApp {
|
||||||
|
@ -69,7 +73,9 @@ impl Default for CalendarApp {
|
||||||
controls: Controls::default(),
|
controls: Controls::default(),
|
||||||
grid_state,
|
grid_state,
|
||||||
main_pane,
|
main_pane,
|
||||||
|
split_value: 0.20,
|
||||||
events: EventsCollection::default(),
|
events: EventsCollection::default(),
|
||||||
|
calendars: std::vec::Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,9 +83,13 @@ impl Default for CalendarApp {
|
||||||
impl CalendarApp {
|
impl CalendarApp {
|
||||||
pub fn with_files(calendar_paths: std::vec::Vec<path::PathBuf>) -> Self {
|
pub fn with_files(calendar_paths: std::vec::Vec<path::PathBuf>) -> Self {
|
||||||
let view_date = Utc::now().date_naive();
|
let view_date = Utc::now().date_naive();
|
||||||
|
let calendars = calendar_paths.iter()
|
||||||
|
.map(|path| {std::string::String::from(path.file_name().unwrap().to_str().unwrap_or("<>"))})
|
||||||
|
.collect();
|
||||||
let mut app = CalendarApp {
|
let mut app = CalendarApp {
|
||||||
view_date,
|
view_date,
|
||||||
events: EventsCollection::new(),
|
events: EventsCollection::new(),
|
||||||
|
calendars,
|
||||||
..CalendarApp::default()
|
..CalendarApp::default()
|
||||||
};
|
};
|
||||||
for calendar_path in calendar_paths {
|
for calendar_path in calendar_paths {
|
||||||
|
@ -115,6 +125,7 @@ impl CalendarApp {
|
||||||
self.toggle_sidebar();
|
self.toggle_sidebar();
|
||||||
},
|
},
|
||||||
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
||||||
|
self.split_value = ratio;
|
||||||
self.grid_state.resize(split, ratio);
|
self.grid_state.resize(split, ratio);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -129,7 +140,10 @@ impl CalendarApp {
|
||||||
// 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
|
||||||
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, self.main_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);
|
let root = self.grid_state.layout();
|
||||||
|
if let pane_grid::Node::Split { id, axis: _, ratio: _, a: _, b: _ } = root {
|
||||||
|
self.grid_state.resize(*id, self.split_value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +166,13 @@ impl CalendarApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_sidebar_view(&self) -> Container<Message> {
|
fn get_sidebar_view(&self) -> Container<Message> {
|
||||||
Container::new(text("TODO"))
|
//container(self.calendars.iter().map(|name| {text(name.as_str())}))
|
||||||
|
let mut col = column!("Calendars:")
|
||||||
|
.align_x(Alignment::Start);
|
||||||
|
for calendar_name in &self.calendars {
|
||||||
|
col = col.push(text(calendar_name.as_str()));
|
||||||
|
}
|
||||||
|
container(col)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<Message> {
|
pub fn view(&self) -> Element<Message> {
|
||||||
|
|
Loading…
Reference in New Issue