Add file_finder module

Still need to wire up key bindings to make it toggle.

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo
2021-03-21 10:50:07 -06:00
co-authored by Antonio Scandurra
parent 0c59937a65
commit f5df3681f8
10 changed files with 508 additions and 25 deletions
+1
View File
@@ -10,6 +10,7 @@ mod stack;
mod svg;
mod uniform_list;
pub use crate::presenter::ChildView;
pub use align::*;
pub use constrained_box::*;
pub use container::*;
+12 -14
View File
@@ -30,30 +30,28 @@ impl UniformListState {
}
}
pub struct UniformList<F, G>
pub struct UniformList<F>
where
F: Fn(Range<usize>, &AppContext) -> G,
G: Iterator<Item = Box<dyn Element>>,
F: Fn(Range<usize>, &mut Vec<Box<dyn Element>>, &AppContext),
{
state: UniformListState,
item_count: usize,
build_items: F,
append_items: F,
scroll_max: Option<f32>,
items: Vec<Box<dyn Element>>,
origin: Option<Vector2F>,
size: Option<Vector2F>,
}
impl<F, G> UniformList<F, G>
impl<F> UniformList<F>
where
F: Fn(Range<usize>, &AppContext) -> G,
G: Iterator<Item = Box<dyn Element>>,
F: Fn(Range<usize>, &mut Vec<Box<dyn Element>>, &AppContext),
{
pub fn new(state: UniformListState, item_count: usize, build_items: F) -> Self {
Self {
state,
item_count,
build_items,
append_items: build_items,
scroll_max: None,
items: Default::default(),
origin: None,
@@ -115,10 +113,9 @@ where
}
}
impl<F, G> Element for UniformList<F, G>
impl<F> Element for UniformList<F>
where
F: Fn(Range<usize>, &AppContext) -> G,
G: Iterator<Item = Box<dyn Element>>,
F: Fn(Range<usize>, &mut Vec<Box<dyn Element>>, &AppContext),
{
fn layout(
&mut self,
@@ -135,8 +132,9 @@ where
let mut item_constraint =
SizeConstraint::new(vec2f(size.x(), 0.0), vec2f(size.x(), f32::INFINITY));
let first_item = (self.build_items)(0..1, app).next();
if let Some(mut first_item) = first_item {
self.items.clear();
(self.append_items)(0..1, &mut self.items, app);
if let Some(first_item) = self.items.first_mut() {
let mut item_size = first_item.layout(item_constraint, ctx, app);
item_size.set_x(size.x());
item_constraint.min = item_size;
@@ -158,7 +156,7 @@ where
start + (size.y() / item_size.y()).ceil() as usize + 1,
);
self.items.clear();
self.items.extend((self.build_items)(start..end, app));
(self.append_items)(start..end, &mut self.items, app);
self.scroll_max = Some(item_size.y() * self.item_count as f32 - size.y());