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
|
@ -324,20 +324,24 @@ impl Element for Flex {
|
||||||
// overall flex element and each child. We then align these points. So 0 would center
|
// overall flex element and each child. We then align these points. So 0 would center
|
||||||
// each child relative to the overall height/width of the flex. -1 puts children at
|
// each child relative to the overall height/width of the flex. -1 puts children at
|
||||||
// the start. 1 puts children at the end.
|
// the start. 1 puts children at the end.
|
||||||
let cross_axis = self.axis.invert();
|
let aligned_child_origin = {
|
||||||
let my_center = bounds.size().along(cross_axis) / 2.;
|
let cross_axis = self.axis.invert();
|
||||||
let my_target = my_center + my_center * self.child_alignment;
|
let my_center = bounds.size().along(cross_axis) / 2.;
|
||||||
|
let my_target = my_center + my_center * self.child_alignment;
|
||||||
|
|
||||||
let child_center = child.size().along(cross_axis) / 2.;
|
let child_center = child.size().along(cross_axis) / 2.;
|
||||||
let child_target = child_center + child_center * self.child_alignment;
|
let child_target = child_center + child_center * self.child_alignment;
|
||||||
|
|
||||||
let mut aligned_child_origin = child_origin;
|
let mut aligned_child_origin = child_origin;
|
||||||
match self.axis {
|
match self.axis {
|
||||||
Axis::Horizontal => aligned_child_origin
|
Axis::Horizontal => aligned_child_origin
|
||||||
.set_y(aligned_child_origin.y() - (child_target - my_target)),
|
.set_y(aligned_child_origin.y() - (child_target - my_target)),
|
||||||
Axis::Vertical => aligned_child_origin
|
Axis::Vertical => aligned_child_origin
|
||||||
.set_x(aligned_child_origin.x() - (child_target - my_target)),
|
.set_x(aligned_child_origin.x() - (child_target - my_target)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aligned_child_origin
|
||||||
|
};
|
||||||
|
|
||||||
child.paint(aligned_child_origin, visible_bounds, cx);
|
child.paint(aligned_child_origin, visible_bounds, cx);
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::{Canvas, Empty, Flex, Image, Label, MouseEventHandler, ParentElement, Stack, Svg},
|
elements::{Empty, Flex, Image, Label, MouseEventHandler, ParentElement, Svg},
|
||||||
geometry::rect::RectF,
|
Action, Element, ElementBox, Entity, MouseButton, MutableAppContext, RenderContext,
|
||||||
Action, Element, ElementBox, Entity, MouseButton, MouseRegion, MutableAppContext,
|
Subscription, View, ViewContext,
|
||||||
RenderContext, Subscription, View, ViewContext,
|
|
||||||
};
|
};
|
||||||
use settings::{settings_file::SettingsFile, Settings, SettingsFileContent};
|
use settings::{settings_file::SettingsFile, Settings, SettingsFileContent};
|
||||||
use theme::CheckboxStyle;
|
use theme::CheckboxStyle;
|
||||||
use workspace::{item::Item, Welcome, Workspace};
|
use workspace::{item::Item, PaneBackdrop, Welcome, Workspace, WorkspaceId};
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(|workspace: &mut Workspace, _: &Welcome, cx| {
|
cx.add_action(|workspace: &mut Workspace, _: &Welcome, cx| {
|
||||||
|
@ -43,89 +42,67 @@ impl View for WelcomePage {
|
||||||
enum Metrics {}
|
enum Metrics {}
|
||||||
enum Diagnostics {}
|
enum Diagnostics {}
|
||||||
|
|
||||||
let background = theme.editor.background;
|
PaneBackdrop::new(
|
||||||
|
self_handle.id(),
|
||||||
Stack::new()
|
Flex::column()
|
||||||
.with_child(
|
.with_children([
|
||||||
// TODO: Can this be moved into the pane?
|
Flex::row()
|
||||||
Canvas::new(move |bounds, visible_bounds, cx| {
|
.with_children([
|
||||||
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
|
Image::new("images/zed-logo-90x90.png")
|
||||||
|
.constrained()
|
||||||
cx.paint_layer(Some(visible_bounds), |cx| {
|
.with_width(90.)
|
||||||
cx.scene.push_quad(gpui::Quad {
|
.with_height(90.)
|
||||||
bounds: RectF::new(bounds.origin(), bounds.size()),
|
.aligned()
|
||||||
background: Some(background),
|
.contained()
|
||||||
..Default::default()
|
.boxed(),
|
||||||
})
|
// Label::new("Zed", theme.editor.hover_popover.prose.clone()).boxed(),
|
||||||
});
|
])
|
||||||
|
|
||||||
cx.scene.push_mouse_region(
|
|
||||||
MouseRegion::new::<Self>(self_handle.id(), 0, visible_bounds)
|
|
||||||
.on_down(gpui::MouseButton::Left, |_, cx| cx.focus_parent_view()),
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Flex::column()
|
|
||||||
.with_children([
|
|
||||||
Flex::row()
|
|
||||||
.with_children([
|
|
||||||
Image::new("images/zed-logo-90x90.png")
|
|
||||||
.constrained()
|
|
||||||
.with_width(90.)
|
|
||||||
.with_height(90.)
|
|
||||||
.aligned()
|
|
||||||
.contained()
|
|
||||||
.boxed(),
|
|
||||||
// Label::new("Zed", theme.editor.hover_popover.prose.clone()).boxed(),
|
|
||||||
])
|
|
||||||
.boxed(),
|
|
||||||
Label::new(
|
|
||||||
"Code at the speed of thought",
|
|
||||||
theme.editor.hover_popover.prose.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
.boxed(),
|
||||||
self.render_cta_button(2, "Choose a theme", theme_selector::Toggle, cx),
|
Label::new(
|
||||||
self.render_cta_button(3, "Choose a keymap", theme_selector::Toggle, cx),
|
"Code at the speed of thought",
|
||||||
Flex::row()
|
theme.editor.hover_popover.prose.clone(),
|
||||||
.with_children([
|
)
|
||||||
self.render_settings_checkbox::<Metrics>(
|
|
||||||
&theme.welcome.checkbox,
|
|
||||||
metrics,
|
|
||||||
cx,
|
|
||||||
|content, checked| {
|
|
||||||
content.telemetry.set_metrics(checked);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Label::new(
|
|
||||||
"Do you want to send telemetry?",
|
|
||||||
theme.editor.hover_popover.prose.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
])
|
|
||||||
.align_children_center()
|
|
||||||
.boxed(),
|
|
||||||
Flex::row()
|
|
||||||
.with_children([
|
|
||||||
self.render_settings_checkbox::<Diagnostics>(
|
|
||||||
&theme.welcome.checkbox,
|
|
||||||
diagnostics,
|
|
||||||
cx,
|
|
||||||
|content, checked| content.telemetry.set_diagnostics(checked),
|
|
||||||
),
|
|
||||||
Label::new(
|
|
||||||
"Send crash reports",
|
|
||||||
theme.editor.hover_popover.prose.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
])
|
|
||||||
.align_children_center()
|
|
||||||
.boxed(),
|
|
||||||
])
|
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
self.render_cta_button(2, "Choose a theme", theme_selector::Toggle, cx),
|
||||||
.boxed()
|
self.render_cta_button(3, "Choose a keymap", theme_selector::Toggle, cx),
|
||||||
|
Flex::row()
|
||||||
|
.with_children([
|
||||||
|
self.render_settings_checkbox::<Metrics>(
|
||||||
|
&theme.welcome.checkbox,
|
||||||
|
metrics,
|
||||||
|
cx,
|
||||||
|
|content, checked| {
|
||||||
|
content.telemetry.set_metrics(checked);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Label::new(
|
||||||
|
"Do you want to send telemetry?",
|
||||||
|
theme.editor.hover_popover.prose.clone(),
|
||||||
|
)
|
||||||
|
.boxed(),
|
||||||
|
])
|
||||||
|
.align_children_center()
|
||||||
|
.boxed(),
|
||||||
|
Flex::row()
|
||||||
|
.with_children([
|
||||||
|
self.render_settings_checkbox::<Diagnostics>(
|
||||||
|
&theme.welcome.checkbox,
|
||||||
|
diagnostics,
|
||||||
|
cx,
|
||||||
|
|content, checked| content.telemetry.set_diagnostics(checked),
|
||||||
|
),
|
||||||
|
Label::new(
|
||||||
|
"Send crash reports",
|
||||||
|
theme.editor.hover_popover.prose.clone(),
|
||||||
|
)
|
||||||
|
.boxed(),
|
||||||
|
])
|
||||||
|
.align_children_center()
|
||||||
|
.boxed(),
|
||||||
|
])
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,4 +209,11 @@ impl Item for WelcomePage {
|
||||||
fn show_toolbar(&self) -> bool {
|
fn show_toolbar(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
fn clone_on_split(
|
||||||
|
&self,
|
||||||
|
_workspace_id: WorkspaceId,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> Option<Self> {
|
||||||
|
Some(WelcomePage::new(cx))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ use gpui::{
|
||||||
keymap_matcher::KeymapContext,
|
keymap_matcher::KeymapContext,
|
||||||
platform::{CursorStyle, NavigationDirection},
|
platform::{CursorStyle, NavigationDirection},
|
||||||
Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
|
Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
|
||||||
ModelHandle, MouseButton, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View,
|
ModelHandle, MouseButton, MouseRegion, MutableAppContext, PromptLevel, Quad, RenderContext,
|
||||||
ViewContext, ViewHandle, WeakViewHandle,
|
Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||||
};
|
};
|
||||||
use project::{Project, ProjectEntryId, ProjectPath};
|
use project::{Project, ProjectEntryId, ProjectPath};
|
||||||
use serde::Deserialize;
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue