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:
co-authored by
Antonio Scandurra
parent
0c59937a65
commit
f5df3681f8
+8
-3
@@ -3,8 +3,9 @@ use crate::{
|
||||
executor::{self, ForegroundTask},
|
||||
keymap::{self, Keystroke},
|
||||
platform::{self, App as _, WindowOptions},
|
||||
presenter::Presenter,
|
||||
util::post_inc,
|
||||
AssetCache, AssetSource, FontCache, Presenter,
|
||||
AssetCache, AssetSource, FontCache,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use keymap::MatchResult;
|
||||
@@ -1440,8 +1441,8 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
||||
self.app
|
||||
}
|
||||
|
||||
pub fn background_executor(&self) -> Arc<executor::Background> {
|
||||
self.app.background.clone()
|
||||
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||
&self.app.background
|
||||
}
|
||||
|
||||
pub fn halt_stream(&mut self) {
|
||||
@@ -1633,6 +1634,10 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||
self.app
|
||||
}
|
||||
|
||||
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||
&self.app.background
|
||||
}
|
||||
|
||||
pub fn focus<S>(&mut self, handle: S)
|
||||
where
|
||||
S: Into<AnyViewHandle>,
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
+4
-1
@@ -18,4 +18,7 @@ pub mod platform;
|
||||
pub use pathfinder_color as color;
|
||||
pub use pathfinder_geometry as geometry;
|
||||
pub use platform::Event;
|
||||
pub use presenter::*;
|
||||
pub use presenter::{
|
||||
AfterLayoutContext, Axis, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
||||
Vector2FExt,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user