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,
|
||||
Length,
|
||||
widget::{
|
||||
column,
|
||||
container,
|
||||
Column,
|
||||
Container,
|
||||
text,
|
||||
|
@ -56,7 +58,9 @@ pub struct CalendarApp {
|
|||
controls: Controls,
|
||||
grid_state: pane_grid::State<PaneGridState>,
|
||||
main_pane: pane_grid::Pane,
|
||||
split_value: f32,
|
||||
events: EventsCollection,
|
||||
calendars: std::vec::Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for CalendarApp {
|
||||
|
@ -69,7 +73,9 @@ impl Default for CalendarApp {
|
|||
controls: Controls::default(),
|
||||
grid_state,
|
||||
main_pane,
|
||||
split_value: 0.20,
|
||||
events: EventsCollection::default(),
|
||||
calendars: std::vec::Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,9 +83,13 @@ impl Default for CalendarApp {
|
|||
impl CalendarApp {
|
||||
pub fn with_files(calendar_paths: std::vec::Vec<path::PathBuf>) -> Self {
|
||||
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 {
|
||||
view_date,
|
||||
events: EventsCollection::new(),
|
||||
calendars,
|
||||
..CalendarApp::default()
|
||||
};
|
||||
for calendar_path in calendar_paths {
|
||||
|
@ -115,6 +125,7 @@ impl CalendarApp {
|
|||
self.toggle_sidebar();
|
||||
},
|
||||
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
||||
self.split_value = 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
|
||||
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);
|
||||
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> {
|
||||
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> {
|
||||
|
|
Loading…
Reference in New Issue