Add an element to pane to take care of wiring initial mouse handlers
This commit is contained in:
parent
4a8527478d
commit
b74553455f
3 changed files with 175 additions and 100 deletions
|
@ -24,8 +24,8 @@ use gpui::{
|
|||
keymap_matcher::KeymapContext,
|
||||
platform::{CursorStyle, NavigationDirection},
|
||||
Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
|
||||
ModelHandle, MouseButton, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle,
|
||||
ModelHandle, MouseButton, MouseRegion, MutableAppContext, PromptLevel, Quad, RenderContext,
|
||||
Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
use serde::Deserialize;
|
||||
|
@ -1706,6 +1706,93 @@ impl NavHistory {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PaneBackdrop {
|
||||
child_view: usize,
|
||||
child: ElementBox,
|
||||
}
|
||||
impl PaneBackdrop {
|
||||
pub fn new(pane_item_view: usize, child: ElementBox) -> Self {
|
||||
PaneBackdrop {
|
||||
child,
|
||||
child_view: pane_item_view,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for PaneBackdrop {
|
||||
type LayoutState = ();
|
||||
|
||||
type PaintState = ();
|
||||
|
||||
fn layout(
|
||||
&mut self,
|
||||
constraint: gpui::SizeConstraint,
|
||||
cx: &mut gpui::LayoutContext,
|
||||
) -> (Vector2F, Self::LayoutState) {
|
||||
let size = self.child.layout(constraint, cx);
|
||||
(size, ())
|
||||
}
|
||||
|
||||
fn paint(
|
||||
&mut self,
|
||||
bounds: RectF,
|
||||
visible_bounds: RectF,
|
||||
_: &mut Self::LayoutState,
|
||||
cx: &mut gpui::PaintContext,
|
||||
) -> Self::PaintState {
|
||||
let background = cx.global::<Settings>().theme.editor.background;
|
||||
|
||||
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
|
||||
|
||||
cx.scene.push_quad(gpui::Quad {
|
||||
bounds: RectF::new(bounds.origin(), bounds.size()),
|
||||
background: Some(background),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let child_view_id = self.child_view;
|
||||
cx.scene.push_mouse_region(
|
||||
MouseRegion::new::<Self>(child_view_id, 0, visible_bounds).on_down(
|
||||
gpui::MouseButton::Left,
|
||||
move |_, cx| {
|
||||
let window_id = cx.window_id;
|
||||
cx.focus(window_id, Some(child_view_id))
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
cx.paint_layer(Some(bounds), |cx| {
|
||||
self.child.paint(bounds.origin(), visible_bounds, cx)
|
||||
})
|
||||
}
|
||||
|
||||
fn rect_for_text_range(
|
||||
&self,
|
||||
range_utf16: std::ops::Range<usize>,
|
||||
_bounds: RectF,
|
||||
_visible_bounds: RectF,
|
||||
_layout: &Self::LayoutState,
|
||||
_paint: &Self::PaintState,
|
||||
cx: &gpui::MeasurementContext,
|
||||
) -> Option<RectF> {
|
||||
self.child.rect_for_text_range(range_utf16, cx)
|
||||
}
|
||||
|
||||
fn debug(
|
||||
&self,
|
||||
_bounds: RectF,
|
||||
_layout: &Self::LayoutState,
|
||||
_paint: &Self::PaintState,
|
||||
cx: &gpui::DebugContext,
|
||||
) -> serde_json::Value {
|
||||
gpui::json::json!({
|
||||
"type": "Pane Back Drop",
|
||||
"view": self.child_view,
|
||||
"child": self.child.debug(cx),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue