Start work on expanding and collapsing directories in project panel

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-09-24 15:12:49 -07:00
co-authored by Nathan Sobo
parent 7eda614c4a
commit 443a7826bb
7 changed files with 559 additions and 160 deletions
+6 -6
View File
@@ -5,7 +5,7 @@ use crate::{
vector::{vec2f, Vector2F},
},
json::{self, json},
ElementBox, MutableAppContext,
ElementBox,
};
use json::ToJson;
use parking_lot::Mutex;
@@ -38,7 +38,7 @@ pub struct LayoutState {
pub struct UniformList<F>
where
F: Fn(Range<usize>, &mut Vec<ElementBox>, &mut MutableAppContext),
F: Fn(Range<usize>, &mut Vec<ElementBox>, &mut LayoutContext),
{
state: UniformListState,
item_count: usize,
@@ -47,7 +47,7 @@ where
impl<F> UniformList<F>
where
F: Fn(Range<usize>, &mut Vec<ElementBox>, &mut MutableAppContext),
F: Fn(Range<usize>, &mut Vec<ElementBox>, &mut LayoutContext),
{
pub fn new(state: UniformListState, item_count: usize, append_items: F) -> Self {
Self {
@@ -102,7 +102,7 @@ where
impl<F> Element for UniformList<F>
where
F: Fn(Range<usize>, &mut Vec<ElementBox>, &mut MutableAppContext),
F: Fn(Range<usize>, &mut Vec<ElementBox>, &mut LayoutContext),
{
type LayoutState = LayoutState;
type PaintState = ();
@@ -124,7 +124,7 @@ where
let mut scroll_max = 0.;
let mut items = Vec::new();
(self.append_items)(0..1, &mut items, cx.app);
(self.append_items)(0..1, &mut items, cx);
if let Some(first_item) = items.first_mut() {
let mut item_size = first_item.layout(item_constraint, cx);
item_size.set_x(size.x());
@@ -146,7 +146,7 @@ where
self.item_count,
start + (size.y() / item_height).ceil() as usize + 1,
);
(self.append_items)(start..end, &mut items, cx.app);
(self.append_items)(start..end, &mut items, cx);
for item in &mut items {
item.layout(item_constraint, cx);
}
+11 -1
View File
@@ -7,7 +7,7 @@ use crate::{
platform::Event,
text_layout::TextLayoutCache,
Action, AnyAction, AssetCache, ElementBox, Entity, FontSystem, ModelHandle, ReadModel,
ReadView, Scene, View, ViewHandle,
ReadView, Scene, UpdateView, View, ViewHandle,
};
use pathfinder_geometry::vector::{vec2f, Vector2F};
use serde_json::json;
@@ -264,6 +264,16 @@ impl<'a> ReadView for LayoutContext<'a> {
}
}
impl<'a> UpdateView for LayoutContext<'a> {
fn update_view<T, F, S>(&mut self, handle: &ViewHandle<T>, update: F) -> S
where
T: View,
F: FnOnce(&mut T, &mut crate::ViewContext<T>) -> S,
{
self.app.update_view(handle, update)
}
}
impl<'a> ReadModel for LayoutContext<'a> {
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
self.app.read_model(handle)
+3 -3
View File
@@ -126,7 +126,7 @@ impl View for Select {
UniformList::new(
self.list_state.clone(),
self.item_count,
move |mut range, items, mut cx| {
move |mut range, items, cx| {
let handle = handle.upgrade(cx).unwrap();
let this = handle.read(cx);
let selected_item_ix = this.selected_item_ix;
@@ -134,9 +134,9 @@ impl View for Select {
items.extend(range.map(|ix| {
MouseEventHandler::new::<Item, _, _, _>(
(handle.id(), ix),
&mut cx,
cx,
|mouse_state, cx| {
(handle.read(*cx).render_item)(
(handle.read(cx).render_item)(
ix,
if ix == selected_item_ix {
ItemType::Selected