Merge pull request #1764 from zed-industries/gpui-events
Eliminate dispatch_event on Element trait
This commit is contained in:
commit
f8e5a08324
56 changed files with 861 additions and 1245 deletions
|
@ -397,7 +397,7 @@ impl View for ChatPanel {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if matches!(
|
if matches!(
|
||||||
*self.rpc.status().borrow(),
|
*self.rpc.status().borrow(),
|
||||||
client::Status::Connected { .. }
|
client::Status::Connected { .. }
|
||||||
|
|
|
@ -526,18 +526,6 @@ impl Element for AvatarRibbon {
|
||||||
cx.scene.push_path(path.build(self.color, None));
|
cx.scene.push_path(path.build(self.color, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &gpui::Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut gpui::EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl View for ContactFinder {
|
||||||
ChildView::new(self.picker.clone(), cx).boxed()
|
ChildView::new(self.picker.clone(), cx).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.picker);
|
cx.focus(&self.picker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1121,13 +1121,13 @@ impl View for ContactList {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if !self.filter_editor.is_focused(cx) {
|
if !self.filter_editor.is_focused(cx) {
|
||||||
cx.focus(&self.filter_editor);
|
cx.focus(&self.filter_editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if !self.filter_editor.is_focused(cx) {
|
if !self.filter_editor.is_focused(cx) {
|
||||||
cx.emit(Event::Dismissed);
|
cx.emit(Event::Dismissed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ impl View for ContactsPopover {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
match &self.child {
|
match &self.child {
|
||||||
Child::ContactList(child) => cx.focus(child),
|
Child::ContactList(child) => cx.focus(child),
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl View for CommandPalette {
|
||||||
ChildView::new(self.picker.clone(), cx).boxed()
|
ChildView::new(self.picker.clone(), cx).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.picker);
|
cx.focus(&self.picker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl View for ContextMenu {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
self.reset(cx);
|
self.reset(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl View for ProjectDiagnosticsEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if !self.path_states.is_empty() {
|
if !self.path_states.is_empty() {
|
||||||
cx.focus(&self.editor);
|
cx.focus(&self.editor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use collections::HashSet;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::{MouseEventHandler, Overlay},
|
elements::{MouseEventHandler, Overlay},
|
||||||
geometry::vector::Vector2F,
|
geometry::vector::Vector2F,
|
||||||
scene::DragRegionEvent,
|
scene::MouseDrag,
|
||||||
CursorStyle, Element, ElementBox, EventContext, MouseButton, MutableAppContext, RenderContext,
|
CursorStyle, Element, ElementBox, EventContext, MouseButton, MutableAppContext, RenderContext,
|
||||||
View, WeakViewHandle,
|
View, WeakViewHandle,
|
||||||
};
|
};
|
||||||
|
@ -70,7 +70,7 @@ impl<V: View> DragAndDrop<V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dragging<T: Any>(
|
pub fn dragging<T: Any>(
|
||||||
event: DragRegionEvent,
|
event: MouseDrag,
|
||||||
payload: Rc<T>,
|
payload: Rc<T>,
|
||||||
cx: &mut EventContext,
|
cx: &mut EventContext,
|
||||||
render: Rc<impl 'static + Fn(&T, &mut RenderContext<V>) -> ElementBox>,
|
render: Rc<impl 'static + Fn(&T, &mut RenderContext<V>) -> ElementBox>,
|
||||||
|
|
|
@ -48,7 +48,9 @@ use language::{
|
||||||
Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16,
|
Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16,
|
||||||
Point, Selection, SelectionGoal, TransactionId,
|
Point, Selection, SelectionGoal, TransactionId,
|
||||||
};
|
};
|
||||||
use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState};
|
use link_go_to_definition::{
|
||||||
|
hide_link_definition, show_link_definition, LinkDefinitionKind, LinkGoToDefinitionState,
|
||||||
|
};
|
||||||
pub use multi_buffer::{
|
pub use multi_buffer::{
|
||||||
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
|
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
|
||||||
ToPoint,
|
ToPoint,
|
||||||
|
@ -6425,7 +6427,7 @@ impl View for Editor {
|
||||||
"Editor"
|
"Editor"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
let focused_event = EditorFocused(cx.handle());
|
let focused_event = EditorFocused(cx.handle());
|
||||||
cx.emit_global(focused_event);
|
cx.emit_global(focused_event);
|
||||||
if let Some(rename) = self.pending_rename.as_ref() {
|
if let Some(rename) = self.pending_rename.as_ref() {
|
||||||
|
@ -6447,7 +6449,7 @@ impl View for Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
let blurred_event = EditorBlurred(cx.handle());
|
let blurred_event = EditorBlurred(cx.handle());
|
||||||
cx.emit_global(blurred_event);
|
cx.emit_global(blurred_event);
|
||||||
self.focused = false;
|
self.focused = false;
|
||||||
|
@ -6460,6 +6462,44 @@ impl View for Editor {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn modifiers_changed(
|
||||||
|
&mut self,
|
||||||
|
event: &gpui::ModifiersChangedEvent,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> bool {
|
||||||
|
let pending_selection = self.has_pending_selection();
|
||||||
|
|
||||||
|
if let Some(point) = self.link_go_to_definition_state.last_mouse_location.clone() {
|
||||||
|
if event.cmd && !pending_selection {
|
||||||
|
let snapshot = self.snapshot(cx);
|
||||||
|
let kind = if event.shift {
|
||||||
|
LinkDefinitionKind::Type
|
||||||
|
} else {
|
||||||
|
LinkDefinitionKind::Symbol
|
||||||
|
};
|
||||||
|
|
||||||
|
show_link_definition(kind, self, point, snapshot, cx);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
if self.link_go_to_definition_state.symbol_range.is_some()
|
||||||
|
|| !self.link_go_to_definition_state.definitions.is_empty()
|
||||||
|
{
|
||||||
|
self.link_go_to_definition_state.symbol_range.take();
|
||||||
|
self.link_go_to_definition_state.definitions.clear();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.link_go_to_definition_state.task = None;
|
||||||
|
|
||||||
|
self.clear_text_highlights::<LinkGoToDefinitionState>(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn keymap_context(&self, _: &AppContext) -> gpui::keymap::Context {
|
fn keymap_context(&self, _: &AppContext) -> gpui::keymap::Context {
|
||||||
let mut context = Self::default_keymap_context();
|
let mut context = Self::default_keymap_context();
|
||||||
let mode = match self.mode {
|
let mode = match self.mode {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
HoverAt, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
|
HoverAt, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
|
||||||
},
|
},
|
||||||
link_go_to_definition::{
|
link_go_to_definition::{
|
||||||
CmdShiftChanged, GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink,
|
GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink,
|
||||||
},
|
},
|
||||||
mouse_context_menu::DeployMouseContextMenu,
|
mouse_context_menu::DeployMouseContextMenu,
|
||||||
AnchorRangeExt, EditorStyle,
|
AnchorRangeExt, EditorStyle,
|
||||||
|
@ -29,10 +29,9 @@ use gpui::{
|
||||||
json::{self, ToJson},
|
json::{self, ToJson},
|
||||||
platform::CursorStyle,
|
platform::CursorStyle,
|
||||||
text_layout::{self, Line, RunStyle, TextLayoutCache},
|
text_layout::{self, Line, RunStyle, TextLayoutCache},
|
||||||
AppContext, Axis, Border, CursorRegion, Element, ElementBox, Event, EventContext,
|
AppContext, Axis, Border, CursorRegion, Element, ElementBox, EventContext, LayoutContext,
|
||||||
LayoutContext, ModifiersChangedEvent, MouseButton, MouseButtonEvent, MouseMovedEvent,
|
MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion, MutableAppContext, PaintContext,
|
||||||
MouseRegion, MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext,
|
Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
|
||||||
WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use json::json;
|
use json::json;
|
||||||
use language::{Bias, CursorShape, DiagnosticSeverity, OffsetUtf16, Point, Selection};
|
use language::{Bias, CursorShape, DiagnosticSeverity, OffsetUtf16, Point, Selection};
|
||||||
|
@ -412,14 +411,6 @@ impl EditorElement {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modifiers_changed(&self, event: ModifiersChangedEvent, cx: &mut EventContext) -> bool {
|
|
||||||
cx.dispatch_action(CmdShiftChanged {
|
|
||||||
cmd_down: event.cmd,
|
|
||||||
shift_down: event.shift,
|
|
||||||
});
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn scroll(
|
fn scroll(
|
||||||
position: Vector2F,
|
position: Vector2F,
|
||||||
mut delta: Vector2F,
|
mut delta: Vector2F,
|
||||||
|
@ -1930,22 +1921,6 @@ impl Element for EditorElement {
|
||||||
cx.scene.pop_layer();
|
cx.scene.pop_layer();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut LayoutState,
|
|
||||||
_: &mut (),
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
if let Event::ModifiersChanged(event) = event {
|
|
||||||
self.modifiers_changed(*event, cx);
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -19,12 +19,6 @@ pub struct UpdateGoToDefinitionLink {
|
||||||
pub shift_held: bool,
|
pub shift_held: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
|
||||||
pub struct CmdShiftChanged {
|
|
||||||
pub cmd_down: bool,
|
|
||||||
pub shift_down: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct GoToFetchedDefinition {
|
pub struct GoToFetchedDefinition {
|
||||||
pub point: DisplayPoint,
|
pub point: DisplayPoint,
|
||||||
|
@ -39,7 +33,6 @@ impl_internal_actions!(
|
||||||
editor,
|
editor,
|
||||||
[
|
[
|
||||||
UpdateGoToDefinitionLink,
|
UpdateGoToDefinitionLink,
|
||||||
CmdShiftChanged,
|
|
||||||
GoToFetchedDefinition,
|
GoToFetchedDefinition,
|
||||||
GoToFetchedTypeDefinition
|
GoToFetchedTypeDefinition
|
||||||
]
|
]
|
||||||
|
@ -47,7 +40,6 @@ impl_internal_actions!(
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(update_go_to_definition_link);
|
cx.add_action(update_go_to_definition_link);
|
||||||
cx.add_action(cmd_shift_changed);
|
|
||||||
cx.add_action(go_to_fetched_definition);
|
cx.add_action(go_to_fetched_definition);
|
||||||
cx.add_action(go_to_fetched_type_definition);
|
cx.add_action(go_to_fetched_type_definition);
|
||||||
}
|
}
|
||||||
|
@ -113,37 +105,6 @@ pub fn update_go_to_definition_link(
|
||||||
hide_link_definition(editor, cx);
|
hide_link_definition(editor, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_shift_changed(
|
|
||||||
editor: &mut Editor,
|
|
||||||
&CmdShiftChanged {
|
|
||||||
cmd_down,
|
|
||||||
shift_down,
|
|
||||||
}: &CmdShiftChanged,
|
|
||||||
cx: &mut ViewContext<Editor>,
|
|
||||||
) {
|
|
||||||
let pending_selection = editor.has_pending_selection();
|
|
||||||
|
|
||||||
if let Some(point) = editor
|
|
||||||
.link_go_to_definition_state
|
|
||||||
.last_mouse_location
|
|
||||||
.clone()
|
|
||||||
{
|
|
||||||
if cmd_down && !pending_selection {
|
|
||||||
let snapshot = editor.snapshot(cx);
|
|
||||||
let kind = if shift_down {
|
|
||||||
LinkDefinitionKind::Type
|
|
||||||
} else {
|
|
||||||
LinkDefinitionKind::Symbol
|
|
||||||
};
|
|
||||||
|
|
||||||
show_link_definition(kind, editor, point, snapshot, cx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hide_link_definition(editor, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum LinkDefinitionKind {
|
pub enum LinkDefinitionKind {
|
||||||
Symbol,
|
Symbol,
|
||||||
|
@ -397,6 +358,7 @@ fn go_to_fetched_definition_of_kind(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use gpui::{ModifiersChangedEvent, View};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use lsp::request::{GotoDefinition, GotoTypeDefinition};
|
use lsp::request::{GotoDefinition, GotoTypeDefinition};
|
||||||
|
|
||||||
|
@ -467,11 +429,10 @@ mod tests {
|
||||||
|
|
||||||
// Unpress shift causes highlight to go away (normal goto-definition is not valid here)
|
// Unpress shift causes highlight to go away (normal goto-definition is not valid here)
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
cmd_shift_changed(
|
editor.modifiers_changed(
|
||||||
editor,
|
&gpui::ModifiersChangedEvent {
|
||||||
&CmdShiftChanged {
|
cmd: true,
|
||||||
cmd_down: true,
|
..Default::default()
|
||||||
shift_down: false,
|
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
@ -581,14 +542,7 @@ mod tests {
|
||||||
|
|
||||||
// Unpress cmd causes highlight to go away
|
// Unpress cmd causes highlight to go away
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
cmd_shift_changed(
|
editor.modifiers_changed(&Default::default(), cx);
|
||||||
editor,
|
|
||||||
&CmdShiftChanged {
|
|
||||||
cmd_down: false,
|
|
||||||
shift_down: false,
|
|
||||||
},
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assert no link highlights
|
// Assert no link highlights
|
||||||
|
@ -704,11 +658,10 @@ mod tests {
|
||||||
])))
|
])))
|
||||||
});
|
});
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
cmd_shift_changed(
|
editor.modifiers_changed(
|
||||||
editor,
|
&ModifiersChangedEvent {
|
||||||
&CmdShiftChanged {
|
cmd: true,
|
||||||
cmd_down: true,
|
..Default::default()
|
||||||
shift_down: false,
|
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl View for FileFinder {
|
||||||
ChildView::new(self.picker.clone(), cx).boxed()
|
ChildView::new(self.picker.clone(), cx).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.picker);
|
cx.focus(&self.picker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl View for GoToLine {
|
||||||
.named("go to line")
|
.named("go to line")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
cx.focus(&self.line_editor);
|
cx.focus(&self.line_editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,18 +101,6 @@ impl gpui::Element for TextElement {
|
||||||
line.paint(bounds.origin(), visible_bounds, bounds.height(), cx);
|
line.paint(bounds.origin(), visible_bounds, bounds.height(), cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &gpui::Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut gpui::EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -41,8 +41,8 @@ use crate::{
|
||||||
platform::{self, KeyDownEvent, Platform, PromptLevel, WindowOptions},
|
platform::{self, KeyDownEvent, Platform, PromptLevel, WindowOptions},
|
||||||
presenter::Presenter,
|
presenter::Presenter,
|
||||||
util::post_inc,
|
util::post_inc,
|
||||||
Appearance, AssetCache, AssetSource, ClipboardItem, FontCache, InputHandler, MouseButton,
|
Appearance, AssetCache, AssetSource, ClipboardItem, FontCache, InputHandler, KeyUpEvent,
|
||||||
MouseRegionId, PathPromptOptions, TextLayoutCache,
|
ModifiersChangedEvent, MouseButton, MouseRegionId, PathPromptOptions, TextLayoutCache,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait Entity: 'static {
|
pub trait Entity: 'static {
|
||||||
|
@ -60,8 +60,18 @@ pub trait Entity: 'static {
|
||||||
pub trait View: Entity + Sized {
|
pub trait View: Entity + Sized {
|
||||||
fn ui_name() -> &'static str;
|
fn ui_name() -> &'static str;
|
||||||
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox;
|
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox;
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
|
fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
|
||||||
fn on_focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
|
fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
|
||||||
|
fn key_down(&mut self, _: &KeyDownEvent, _: &mut ViewContext<Self>) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
fn key_up(&mut self, _: &KeyUpEvent, _: &mut ViewContext<Self>) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
fn modifiers_changed(&mut self, _: &ModifiersChangedEvent, _: &mut ViewContext<Self>) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn keymap_context(&self, _: &AppContext) -> keymap::Context {
|
fn keymap_context(&self, _: &AppContext) -> keymap::Context {
|
||||||
Self::default_keymap_context()
|
Self::default_keymap_context()
|
||||||
}
|
}
|
||||||
|
@ -1297,7 +1307,7 @@ impl MutableAppContext {
|
||||||
) -> impl Iterator<Item = (&'static str, Box<dyn Action>, SmallVec<[&Binding; 1]>)> {
|
) -> impl Iterator<Item = (&'static str, Box<dyn Action>, SmallVec<[&Binding; 1]>)> {
|
||||||
let mut action_types: HashSet<_> = self.global_actions.keys().copied().collect();
|
let mut action_types: HashSet<_> = self.global_actions.keys().copied().collect();
|
||||||
|
|
||||||
for view_id in self.parents(window_id, view_id) {
|
for view_id in self.ancestors(window_id, view_id) {
|
||||||
if let Some(view) = self.views.get(&(window_id, view_id)) {
|
if let Some(view) = self.views.get(&(window_id, view_id)) {
|
||||||
let view_type = view.as_any().type_id();
|
let view_type = view.as_any().type_id();
|
||||||
if let Some(actions) = self.actions.get(&view_type) {
|
if let Some(actions) = self.actions.get(&view_type) {
|
||||||
|
@ -1327,7 +1337,7 @@ impl MutableAppContext {
|
||||||
let action_type = action.as_any().type_id();
|
let action_type = action.as_any().type_id();
|
||||||
if let Some(window_id) = self.cx.platform.key_window_id() {
|
if let Some(window_id) = self.cx.platform.key_window_id() {
|
||||||
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
||||||
for view_id in self.parents(window_id, focused_view_id) {
|
for view_id in self.ancestors(window_id, focused_view_id) {
|
||||||
if let Some(view) = self.views.get(&(window_id, view_id)) {
|
if let Some(view) = self.views.get(&(window_id, view_id)) {
|
||||||
let view_type = view.as_any().type_id();
|
let view_type = view.as_any().type_id();
|
||||||
if let Some(actions) = self.actions.get(&view_type) {
|
if let Some(actions) = self.actions.get(&view_type) {
|
||||||
|
@ -1376,7 +1386,7 @@ impl MutableAppContext {
|
||||||
mut visit: impl FnMut(usize, bool, &mut MutableAppContext) -> bool,
|
mut visit: impl FnMut(usize, bool, &mut MutableAppContext) -> bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// List of view ids from the leaf to the root of the window
|
// List of view ids from the leaf to the root of the window
|
||||||
let path = self.parents(window_id, view_id).collect::<Vec<_>>();
|
let path = self.ancestors(window_id, view_id).collect::<Vec<_>>();
|
||||||
|
|
||||||
// Walk down from the root to the leaf calling visit with capture_phase = true
|
// Walk down from the root to the leaf calling visit with capture_phase = true
|
||||||
for view_id in path.iter().rev() {
|
for view_id in path.iter().rev() {
|
||||||
|
@ -1397,7 +1407,7 @@ impl MutableAppContext {
|
||||||
|
|
||||||
// Returns an iterator over all of the view ids from the passed view up to the root of the window
|
// Returns an iterator over all of the view ids from the passed view up to the root of the window
|
||||||
// Includes the passed view itself
|
// Includes the passed view itself
|
||||||
fn parents(&self, window_id: usize, mut view_id: usize) -> impl Iterator<Item = usize> + '_ {
|
fn ancestors(&self, window_id: usize, mut view_id: usize) -> impl Iterator<Item = usize> + '_ {
|
||||||
std::iter::once(view_id)
|
std::iter::once(view_id)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(std::iter::from_fn(move || {
|
.chain(std::iter::from_fn(move || {
|
||||||
|
@ -1445,11 +1455,81 @@ impl MutableAppContext {
|
||||||
self.keystroke_matcher.clear_bindings();
|
self.keystroke_matcher.clear_bindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dispatch_key_down(&mut self, window_id: usize, event: &KeyDownEvent) -> bool {
|
||||||
|
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
||||||
|
for view_id in self
|
||||||
|
.ancestors(window_id, focused_view_id)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
{
|
||||||
|
if let Some(mut view) = self.cx.views.remove(&(window_id, view_id)) {
|
||||||
|
let handled = view.key_down(event, self, window_id, view_id);
|
||||||
|
self.cx.views.insert((window_id, view_id), view);
|
||||||
|
if handled {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("view {} does not exist", view_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dispatch_key_up(&mut self, window_id: usize, event: &KeyUpEvent) -> bool {
|
||||||
|
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
||||||
|
for view_id in self
|
||||||
|
.ancestors(window_id, focused_view_id)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
{
|
||||||
|
if let Some(mut view) = self.cx.views.remove(&(window_id, view_id)) {
|
||||||
|
let handled = view.key_up(event, self, window_id, view_id);
|
||||||
|
self.cx.views.insert((window_id, view_id), view);
|
||||||
|
if handled {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("view {} does not exist", view_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dispatch_modifiers_changed(
|
||||||
|
&mut self,
|
||||||
|
window_id: usize,
|
||||||
|
event: &ModifiersChangedEvent,
|
||||||
|
) -> bool {
|
||||||
|
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
||||||
|
for view_id in self
|
||||||
|
.ancestors(window_id, focused_view_id)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
{
|
||||||
|
if let Some(mut view) = self.cx.views.remove(&(window_id, view_id)) {
|
||||||
|
let handled = view.modifiers_changed(event, self, window_id, view_id);
|
||||||
|
self.cx.views.insert((window_id, view_id), view);
|
||||||
|
if handled {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("view {} does not exist", view_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dispatch_keystroke(&mut self, window_id: usize, keystroke: &Keystroke) -> bool {
|
pub fn dispatch_keystroke(&mut self, window_id: usize, keystroke: &Keystroke) -> bool {
|
||||||
let mut pending = false;
|
let mut pending = false;
|
||||||
|
|
||||||
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
if let Some(focused_view_id) = self.focused_view_id(window_id) {
|
||||||
for view_id in self.parents(window_id, focused_view_id).collect::<Vec<_>>() {
|
for view_id in self
|
||||||
|
.ancestors(window_id, focused_view_id)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
{
|
||||||
let keymap_context = self
|
let keymap_context = self
|
||||||
.cx
|
.cx
|
||||||
.views
|
.views
|
||||||
|
@ -1580,7 +1660,7 @@ impl MutableAppContext {
|
||||||
is_fullscreen: false,
|
is_fullscreen: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx));
|
root_view.update(this, |view, cx| view.focus_in(cx.handle().into(), cx));
|
||||||
|
|
||||||
let window =
|
let window =
|
||||||
this.cx
|
this.cx
|
||||||
|
@ -1612,7 +1692,7 @@ impl MutableAppContext {
|
||||||
is_fullscreen: false,
|
is_fullscreen: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx));
|
root_view.update(this, |view, cx| view.focus_in(cx.handle().into(), cx));
|
||||||
|
|
||||||
let status_item = this.cx.platform.add_status_item();
|
let status_item = this.cx.platform.add_status_item();
|
||||||
this.register_platform_window(window_id, status_item);
|
this.register_platform_window(window_id, status_item);
|
||||||
|
@ -2235,12 +2315,12 @@ impl MutableAppContext {
|
||||||
|
|
||||||
//Handle focus
|
//Handle focus
|
||||||
let focused_id = window.focused_view_id?;
|
let focused_id = window.focused_view_id?;
|
||||||
for view_id in this.parents(window_id, focused_id).collect::<Vec<_>>() {
|
for view_id in this.ancestors(window_id, focused_id).collect::<Vec<_>>() {
|
||||||
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
|
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
|
||||||
if active {
|
if active {
|
||||||
view.on_focus_in(this, window_id, view_id, focused_id);
|
view.focus_in(this, window_id, view_id, focused_id);
|
||||||
} else {
|
} else {
|
||||||
view.on_focus_out(this, window_id, view_id, focused_id);
|
view.focus_out(this, window_id, view_id, focused_id);
|
||||||
}
|
}
|
||||||
this.cx.views.insert((window_id, view_id), view);
|
this.cx.views.insert((window_id, view_id), view);
|
||||||
}
|
}
|
||||||
|
@ -2272,16 +2352,16 @@ impl MutableAppContext {
|
||||||
});
|
});
|
||||||
|
|
||||||
let blurred_parents = blurred_id
|
let blurred_parents = blurred_id
|
||||||
.map(|blurred_id| this.parents(window_id, blurred_id).collect::<Vec<_>>())
|
.map(|blurred_id| this.ancestors(window_id, blurred_id).collect::<Vec<_>>())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let focused_parents = focused_id
|
let focused_parents = focused_id
|
||||||
.map(|focused_id| this.parents(window_id, focused_id).collect::<Vec<_>>())
|
.map(|focused_id| this.ancestors(window_id, focused_id).collect::<Vec<_>>())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if let Some(blurred_id) = blurred_id {
|
if let Some(blurred_id) = blurred_id {
|
||||||
for view_id in blurred_parents.iter().copied() {
|
for view_id in blurred_parents.iter().copied() {
|
||||||
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
|
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
|
||||||
view.on_focus_out(this, window_id, view_id, blurred_id);
|
view.focus_out(this, window_id, view_id, blurred_id);
|
||||||
this.cx.views.insert((window_id, view_id), view);
|
this.cx.views.insert((window_id, view_id), view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2294,7 +2374,7 @@ impl MutableAppContext {
|
||||||
if let Some(focused_id) = focused_id {
|
if let Some(focused_id) = focused_id {
|
||||||
for view_id in focused_parents {
|
for view_id in focused_parents {
|
||||||
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
|
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
|
||||||
view.on_focus_in(this, window_id, view_id, focused_id);
|
view.focus_in(this, window_id, view_id, focused_id);
|
||||||
this.cx.views.insert((window_id, view_id), view);
|
this.cx.views.insert((window_id, view_id), view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2961,20 +3041,41 @@ pub trait AnyView {
|
||||||
) -> Option<Pin<Box<dyn 'static + Future<Output = ()>>>>;
|
) -> Option<Pin<Box<dyn 'static + Future<Output = ()>>>>;
|
||||||
fn ui_name(&self) -> &'static str;
|
fn ui_name(&self) -> &'static str;
|
||||||
fn render(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox;
|
fn render(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox;
|
||||||
fn on_focus_in(
|
fn focus_in(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
view_id: usize,
|
view_id: usize,
|
||||||
focused_id: usize,
|
focused_id: usize,
|
||||||
);
|
);
|
||||||
fn on_focus_out(
|
fn focus_out(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
view_id: usize,
|
view_id: usize,
|
||||||
focused_id: usize,
|
focused_id: usize,
|
||||||
);
|
);
|
||||||
|
fn key_down(
|
||||||
|
&mut self,
|
||||||
|
event: &KeyDownEvent,
|
||||||
|
cx: &mut MutableAppContext,
|
||||||
|
window_id: usize,
|
||||||
|
view_id: usize,
|
||||||
|
) -> bool;
|
||||||
|
fn key_up(
|
||||||
|
&mut self,
|
||||||
|
event: &KeyUpEvent,
|
||||||
|
cx: &mut MutableAppContext,
|
||||||
|
window_id: usize,
|
||||||
|
view_id: usize,
|
||||||
|
) -> bool;
|
||||||
|
fn modifiers_changed(
|
||||||
|
&mut self,
|
||||||
|
event: &ModifiersChangedEvent,
|
||||||
|
cx: &mut MutableAppContext,
|
||||||
|
window_id: usize,
|
||||||
|
view_id: usize,
|
||||||
|
) -> bool;
|
||||||
fn keymap_context(&self, cx: &AppContext) -> keymap::Context;
|
fn keymap_context(&self, cx: &AppContext) -> keymap::Context;
|
||||||
fn debug_json(&self, cx: &AppContext) -> serde_json::Value;
|
fn debug_json(&self, cx: &AppContext) -> serde_json::Value;
|
||||||
|
|
||||||
|
@ -3040,7 +3141,7 @@ where
|
||||||
View::render(self, &mut RenderContext::new(params, cx))
|
View::render(self, &mut RenderContext::new(params, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(
|
fn focus_in(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
|
@ -3059,10 +3160,10 @@ where
|
||||||
.type_id();
|
.type_id();
|
||||||
AnyViewHandle::new(window_id, focused_id, focused_type, cx.ref_counts.clone())
|
AnyViewHandle::new(window_id, focused_id, focused_type, cx.ref_counts.clone())
|
||||||
};
|
};
|
||||||
View::on_focus_in(self, focused_view_handle, &mut cx);
|
View::focus_in(self, focused_view_handle, &mut cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_out(
|
fn focus_out(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
|
@ -3081,7 +3182,40 @@ where
|
||||||
.type_id();
|
.type_id();
|
||||||
AnyViewHandle::new(window_id, blurred_id, blurred_type, cx.ref_counts.clone())
|
AnyViewHandle::new(window_id, blurred_id, blurred_type, cx.ref_counts.clone())
|
||||||
};
|
};
|
||||||
View::on_focus_out(self, blurred_view_handle, &mut cx);
|
View::focus_out(self, blurred_view_handle, &mut cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn key_down(
|
||||||
|
&mut self,
|
||||||
|
event: &KeyDownEvent,
|
||||||
|
cx: &mut MutableAppContext,
|
||||||
|
window_id: usize,
|
||||||
|
view_id: usize,
|
||||||
|
) -> bool {
|
||||||
|
let mut cx = ViewContext::new(cx, window_id, view_id);
|
||||||
|
View::key_down(self, event, &mut cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn key_up(
|
||||||
|
&mut self,
|
||||||
|
event: &KeyUpEvent,
|
||||||
|
cx: &mut MutableAppContext,
|
||||||
|
window_id: usize,
|
||||||
|
view_id: usize,
|
||||||
|
) -> bool {
|
||||||
|
let mut cx = ViewContext::new(cx, window_id, view_id);
|
||||||
|
View::key_up(self, event, &mut cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn modifiers_changed(
|
||||||
|
&mut self,
|
||||||
|
event: &ModifiersChangedEvent,
|
||||||
|
cx: &mut MutableAppContext,
|
||||||
|
window_id: usize,
|
||||||
|
view_id: usize,
|
||||||
|
) -> bool {
|
||||||
|
let mut cx = ViewContext::new(cx, window_id, view_id);
|
||||||
|
View::modifiers_changed(self, event, &mut cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keymap_context(&self, cx: &AppContext) -> keymap::Context {
|
fn keymap_context(&self, cx: &AppContext) -> keymap::Context {
|
||||||
|
@ -3463,7 +3597,7 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||||
if self.window_id != view.window_id {
|
if self.window_id != view.window_id {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
self.parents(view.window_id, view.view_id)
|
self.ancestors(view.window_id, view.view_id)
|
||||||
.any(|parent| parent == self.view_id)
|
.any(|parent| parent == self.view_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6354,13 +6488,13 @@ mod tests {
|
||||||
"View"
|
"View"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.handle().id() == focused.id() {
|
if cx.handle().id() == focused.id() {
|
||||||
self.events.lock().push(format!("{} focused", &self.name));
|
self.events.lock().push(format!("{} focused", &self.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_out(&mut self, blurred: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_out(&mut self, blurred: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.handle().id() == blurred.id() {
|
if cx.handle().id() == blurred.id() {
|
||||||
self.events.lock().push(format!("{} blurred", &self.name));
|
self.events.lock().push(format!("{} blurred", &self.name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ use crate::{
|
||||||
},
|
},
|
||||||
json,
|
json,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
Action, DebugContext, Event, EventContext, LayoutContext, PaintContext, RenderContext,
|
Action, DebugContext, EventContext, LayoutContext, PaintContext, RenderContext, SizeConstraint,
|
||||||
SizeConstraint, View,
|
View,
|
||||||
};
|
};
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use json::ToJson;
|
use json::ToJson;
|
||||||
|
@ -50,7 +50,6 @@ use std::{
|
||||||
trait AnyElement {
|
trait AnyElement {
|
||||||
fn layout(&mut self, constraint: SizeConstraint, cx: &mut LayoutContext) -> Vector2F;
|
fn layout(&mut self, constraint: SizeConstraint, cx: &mut LayoutContext) -> Vector2F;
|
||||||
fn paint(&mut self, origin: Vector2F, visible_bounds: RectF, cx: &mut PaintContext);
|
fn paint(&mut self, origin: Vector2F, visible_bounds: RectF, cx: &mut PaintContext);
|
||||||
fn dispatch_event(&mut self, event: &Event, cx: &mut EventContext) -> bool;
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
@ -80,16 +79,6 @@ pub trait Element {
|
||||||
cx: &mut PaintContext,
|
cx: &mut PaintContext,
|
||||||
) -> Self::PaintState;
|
) -> Self::PaintState;
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
bounds: RectF,
|
|
||||||
visible_bounds: RectF,
|
|
||||||
layout: &mut Self::LayoutState,
|
|
||||||
paint: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool;
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
@ -303,22 +292,6 @@ impl<T: Element> AnyElement for Lifecycle<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(&mut self, event: &Event, cx: &mut EventContext) -> bool {
|
|
||||||
if let Lifecycle::PostPaint {
|
|
||||||
element,
|
|
||||||
bounds,
|
|
||||||
visible_bounds,
|
|
||||||
layout,
|
|
||||||
paint,
|
|
||||||
..
|
|
||||||
} = self
|
|
||||||
{
|
|
||||||
element.dispatch_event(event, *bounds, *visible_bounds, layout, paint, cx)
|
|
||||||
} else {
|
|
||||||
panic!("invalid element lifecycle state");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
@ -433,10 +406,6 @@ impl ElementRc {
|
||||||
self.element.borrow_mut().paint(origin, visible_bounds, cx);
|
self.element.borrow_mut().paint(origin, visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch_event(&mut self, event: &Event, cx: &mut EventContext) -> bool {
|
|
||||||
self.element.borrow_mut().dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rect_for_text_range(
|
pub fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -2,8 +2,7 @@ use crate::{
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
json,
|
json,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
|
DebugContext, Element, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
SizeConstraint,
|
|
||||||
};
|
};
|
||||||
use json::ToJson;
|
use json::ToJson;
|
||||||
|
|
||||||
|
@ -84,18 +83,6 @@ impl Element for Align {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: std::ops::Range<usize>,
|
range_utf16: std::ops::Range<usize>,
|
||||||
|
|
|
@ -56,18 +56,6 @@ where
|
||||||
self.0(bounds, visible_bounds, cx)
|
self.0(bounds, visible_bounds, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &crate::Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut crate::EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: std::ops::Range<usize>,
|
_: std::ops::Range<usize>,
|
||||||
|
|
|
@ -7,8 +7,7 @@ use crate::{
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
json,
|
json,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
|
DebugContext, Element, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
SizeConstraint,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ConstrainedBox {
|
pub struct ConstrainedBox {
|
||||||
|
@ -157,18 +156,6 @@ impl Element for ConstrainedBox {
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
platform::CursorStyle,
|
platform::CursorStyle,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
scene::{self, Border, CursorRegion, Quad},
|
scene::{self, Border, CursorRegion, Quad},
|
||||||
Element, ElementBox, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
Element, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -285,18 +285,6 @@ impl Element for Container {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext,
|
DebugContext,
|
||||||
};
|
};
|
||||||
use crate::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
|
use crate::{Element, LayoutContext, PaintContext, SizeConstraint};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Empty {
|
pub struct Empty {
|
||||||
|
@ -59,18 +59,6 @@ impl Element for Empty {
|
||||||
) -> Self::PaintState {
|
) -> Self::PaintState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -4,8 +4,7 @@ use crate::{
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
json,
|
json,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
|
DebugContext, Element, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
SizeConstraint,
|
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -66,18 +65,6 @@ impl Element for Expanded {
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -3,8 +3,8 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
|
||||||
use crate::{
|
use crate::{
|
||||||
json::{self, ToJson, Value},
|
json::{self, ToJson, Value},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
Axis, DebugContext, Element, ElementBox, ElementStateHandle, Event, EventContext,
|
Axis, DebugContext, Element, ElementBox, ElementStateHandle, LayoutContext, PaintContext,
|
||||||
LayoutContext, PaintContext, RenderContext, SizeConstraint, Vector2FExt, View,
|
RenderContext, SizeConstraint, Vector2FExt, View,
|
||||||
};
|
};
|
||||||
use pathfinder_geometry::{
|
use pathfinder_geometry::{
|
||||||
rect::RectF,
|
rect::RectF,
|
||||||
|
@ -318,23 +318,6 @@ impl Element for Flex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
let mut handled = false;
|
|
||||||
for child in &mut self.children {
|
|
||||||
handled = child.dispatch_event(event, cx) || handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
handled
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
@ -420,18 +403,6 @@ impl Element for FlexItem {
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx)
|
self.child.paint(bounds.origin(), visible_bounds, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -4,8 +4,7 @@ use crate::{
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
json::json,
|
json::json,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
|
DebugContext, Element, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
SizeConstraint,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Hook {
|
pub struct Hook {
|
||||||
|
@ -56,18 +55,6 @@ impl Element for Hook {
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -6,8 +6,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
json::{json, ToJson},
|
json::{json, ToJson},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
scene, Border, DebugContext, Element, Event, EventContext, ImageData, LayoutContext,
|
scene, Border, DebugContext, Element, ImageData, LayoutContext, PaintContext, SizeConstraint,
|
||||||
PaintContext, SizeConstraint,
|
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{ops::Range, sync::Arc};
|
use std::{ops::Range, sync::Arc};
|
||||||
|
@ -81,18 +80,6 @@ impl Element for Image {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
elements::*,
|
elements::*,
|
||||||
fonts::TextStyle,
|
fonts::TextStyle,
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
Action, ElementBox, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
Action, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -64,18 +64,6 @@ impl Element for KeystrokeLabel {
|
||||||
element.paint(bounds.origin(), visible_bounds, cx);
|
element.paint(bounds.origin(), visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
element: &mut ElementBox,
|
|
||||||
_: &mut (),
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
element.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
json::{ToJson, Value},
|
json::{ToJson, Value},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
text_layout::{Line, RunStyle},
|
text_layout::{Line, RunStyle},
|
||||||
DebugContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
DebugContext, Element, LayoutContext, PaintContext, SizeConstraint,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -165,18 +165,6 @@ impl Element for Label {
|
||||||
line.paint(bounds.origin(), visible_bounds, bounds.size().y(), cx)
|
line.paint(bounds.origin(), visible_bounds, bounds.size().y(), cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
json::json,
|
json::json,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext, Element, ElementBox, ElementRc, Event, EventContext, LayoutContext, MouseRegion,
|
DebugContext, Element, ElementBox, ElementRc, EventContext, LayoutContext, MouseRegion,
|
||||||
PaintContext, RenderContext, SizeConstraint, View, ViewContext,
|
PaintContext, RenderContext, SizeConstraint, View, ViewContext,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, collections::VecDeque, ops::Range, rc::Rc};
|
use std::{cell::RefCell, collections::VecDeque, ops::Range, rc::Rc};
|
||||||
|
@ -13,7 +13,6 @@ use sum_tree::{Bias, SumTree};
|
||||||
|
|
||||||
pub struct List {
|
pub struct List {
|
||||||
state: ListState,
|
state: ListState,
|
||||||
invalidated_elements: Vec<ElementRc>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -82,10 +81,7 @@ struct Height(f32);
|
||||||
|
|
||||||
impl List {
|
impl List {
|
||||||
pub fn new(state: ListState) -> Self {
|
pub fn new(state: ListState) -> Self {
|
||||||
Self {
|
Self { state }
|
||||||
state,
|
|
||||||
invalidated_elements: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,50 +285,6 @@ impl Element for List {
|
||||||
cx.scene.pop_layer();
|
cx.scene.pop_layer();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
bounds: RectF,
|
|
||||||
_: RectF,
|
|
||||||
scroll_top: &mut ListOffset,
|
|
||||||
_: &mut (),
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
let mut handled = false;
|
|
||||||
|
|
||||||
let mut state = self.state.0.borrow_mut();
|
|
||||||
let mut item_origin = bounds.origin() - vec2f(0., scroll_top.offset_in_item);
|
|
||||||
let mut cursor = state.items.cursor::<Count>();
|
|
||||||
let mut new_items = cursor.slice(&Count(scroll_top.item_ix), Bias::Right, &());
|
|
||||||
while let Some(item) = cursor.item() {
|
|
||||||
if item_origin.y() > bounds.max_y() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let ListItem::Rendered(element) = item {
|
|
||||||
let prev_notify_count = cx.notify_count();
|
|
||||||
let mut element = element.clone();
|
|
||||||
handled = element.dispatch_event(event, cx) || handled;
|
|
||||||
item_origin.set_y(item_origin.y() + element.size().y());
|
|
||||||
if cx.notify_count() > prev_notify_count {
|
|
||||||
new_items.push(ListItem::Unrendered, &());
|
|
||||||
self.invalidated_elements.push(element);
|
|
||||||
} else {
|
|
||||||
new_items.push(item.clone(), &());
|
|
||||||
}
|
|
||||||
cursor.next(&());
|
|
||||||
} else {
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_items.push_tree(cursor.suffix(&()), &());
|
|
||||||
drop(cursor);
|
|
||||||
state.items = new_items;
|
|
||||||
|
|
||||||
handled
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
@ -964,18 +916,6 @@ mod tests {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut (),
|
|
||||||
_: &mut (),
|
|
||||||
_: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -6,11 +6,10 @@ use crate::{
|
||||||
},
|
},
|
||||||
platform::CursorStyle,
|
platform::CursorStyle,
|
||||||
scene::{
|
scene::{
|
||||||
ClickRegionEvent, CursorRegion, DownOutRegionEvent, DownRegionEvent, DragRegionEvent,
|
CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover,
|
||||||
HandlerSet, HoverRegionEvent, MoveRegionEvent, ScrollWheelRegionEvent, UpOutRegionEvent,
|
MouseMove, MouseScrollWheel, MouseUp, MouseUpOut,
|
||||||
UpRegionEvent,
|
|
||||||
},
|
},
|
||||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, MeasurementContext,
|
DebugContext, Element, ElementBox, EventContext, LayoutContext, MeasurementContext,
|
||||||
MouseButton, MouseRegion, MouseState, PaintContext, RenderContext, SizeConstraint, View,
|
MouseButton, MouseRegion, MouseState, PaintContext, RenderContext, SizeConstraint, View,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -61,10 +60,7 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_move(
|
pub fn on_move(mut self, handler: impl Fn(MouseMove, &mut EventContext) + 'static) -> Self {
|
||||||
mut self,
|
|
||||||
handler: impl Fn(MoveRegionEvent, &mut EventContext) + 'static,
|
|
||||||
) -> Self {
|
|
||||||
self.handlers = self.handlers.on_move(handler);
|
self.handlers = self.handlers.on_move(handler);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -72,7 +68,7 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
pub fn on_down(
|
pub fn on_down(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DownRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDown, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_down(button, handler);
|
self.handlers = self.handlers.on_down(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -81,7 +77,7 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
pub fn on_up(
|
pub fn on_up(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(UpRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseUp, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_up(button, handler);
|
self.handlers = self.handlers.on_up(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -90,7 +86,7 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
pub fn on_click(
|
pub fn on_click(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(ClickRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseClick, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_click(button, handler);
|
self.handlers = self.handlers.on_click(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -99,7 +95,7 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
pub fn on_down_out(
|
pub fn on_down_out(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DownOutRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDownOut, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_down_out(button, handler);
|
self.handlers = self.handlers.on_down_out(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -108,7 +104,7 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
pub fn on_up_out(
|
pub fn on_up_out(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(UpOutRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseUpOut, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_up_out(button, handler);
|
self.handlers = self.handlers.on_up_out(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -117,23 +113,20 @@ impl<Tag> MouseEventHandler<Tag> {
|
||||||
pub fn on_drag(
|
pub fn on_drag(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DragRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDrag, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_drag(button, handler);
|
self.handlers = self.handlers.on_drag(button, handler);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_hover(
|
pub fn on_hover(mut self, handler: impl Fn(MouseHover, &mut EventContext) + 'static) -> Self {
|
||||||
mut self,
|
|
||||||
handler: impl Fn(HoverRegionEvent, &mut EventContext) + 'static,
|
|
||||||
) -> Self {
|
|
||||||
self.handlers = self.handlers.on_hover(handler);
|
self.handlers = self.handlers.on_hover(handler);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_scroll(
|
pub fn on_scroll(
|
||||||
mut self,
|
mut self,
|
||||||
handler: impl Fn(ScrollWheelRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseScrollWheel, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_scroll(handler);
|
self.handlers = self.handlers.on_scroll(handler);
|
||||||
self
|
self
|
||||||
|
@ -201,18 +194,6 @@ impl<Tag> Element for MouseEventHandler<Tag> {
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -4,8 +4,8 @@ use crate::{
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
json::ToJson,
|
json::ToJson,
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
Axis, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, MouseRegion,
|
Axis, DebugContext, Element, ElementBox, LayoutContext, MouseRegion, PaintContext,
|
||||||
PaintContext, SizeConstraint,
|
SizeConstraint,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -225,18 +225,6 @@ impl Element for Overlay {
|
||||||
cx.scene.pop_stacking_context();
|
cx.scene.pop_stacking_context();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use pathfinder_geometry::vector::{vec2f, Vector2F};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::rect::RectF, scene::DragRegionEvent, Axis, CursorStyle, Element, ElementBox,
|
geometry::rect::RectF, scene::MouseDrag, Axis, CursorStyle, Element, ElementBox,
|
||||||
ElementStateHandle, MouseButton, MouseRegion, RenderContext, View,
|
ElementStateHandle, MouseButton, MouseRegion, RenderContext, View,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ impl Side {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_delta(&self, e: DragRegionEvent) -> f32 {
|
fn compute_delta(&self, e: MouseDrag) -> f32 {
|
||||||
if self.before_content() {
|
if self.before_content() {
|
||||||
self.relevant_component(e.prev_mouse_position) - self.relevant_component(e.position)
|
self.relevant_component(e.prev_mouse_position) - self.relevant_component(e.position)
|
||||||
} else {
|
} else {
|
||||||
|
@ -187,18 +187,6 @@ impl Element for Resizable {
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &crate::Event,
|
|
||||||
_bounds: pathfinder_geometry::rect::RectF,
|
|
||||||
_visible_bounds: pathfinder_geometry::rect::RectF,
|
|
||||||
_layout: &mut Self::LayoutState,
|
|
||||||
_paint: &mut Self::PaintState,
|
|
||||||
cx: &mut crate::EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: std::ops::Range<usize>,
|
range_utf16: std::ops::Range<usize>,
|
||||||
|
|
|
@ -4,8 +4,7 @@ use crate::{
|
||||||
geometry::{rect::RectF, vector::Vector2F},
|
geometry::{rect::RectF, vector::Vector2F},
|
||||||
json::{self, json, ToJson},
|
json::{self, json, ToJson},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
|
DebugContext, Element, ElementBox, LayoutContext, PaintContext, SizeConstraint,
|
||||||
SizeConstraint,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -49,23 +48,6 @@ impl Element for Stack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
for child in self.children.iter_mut().rev() {
|
|
||||||
if child.dispatch_event(event, cx) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
vector::{vec2f, Vector2F},
|
vector::{vec2f, Vector2F},
|
||||||
},
|
},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
scene, DebugContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
scene, DebugContext, Element, LayoutContext, PaintContext, SizeConstraint,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Svg {
|
pub struct Svg {
|
||||||
|
@ -73,18 +73,6 @@ impl Element for Svg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -8,8 +8,7 @@ use crate::{
|
||||||
json::{ToJson, Value},
|
json::{ToJson, Value},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
text_layout::{Line, RunStyle, ShapedBoundary},
|
text_layout::{Line, RunStyle, ShapedBoundary},
|
||||||
DebugContext, Element, Event, EventContext, FontCache, LayoutContext, PaintContext,
|
DebugContext, Element, FontCache, LayoutContext, PaintContext, SizeConstraint, TextLayoutCache,
|
||||||
SizeConstraint, TextLayoutCache,
|
|
||||||
};
|
};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -178,18 +177,6 @@ impl Element for Text {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
_: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
_: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
|
|
@ -186,18 +186,6 @@ impl Element for Tooltip {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &crate::Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut crate::EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
|
use super::{Element, EventContext, LayoutContext, PaintContext, SizeConstraint};
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{
|
geometry::{
|
||||||
rect::RectF,
|
rect::RectF,
|
||||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
json::{self, json},
|
json::{self, json},
|
||||||
presenter::MeasurementContext,
|
presenter::MeasurementContext,
|
||||||
scene::ScrollWheelRegionEvent,
|
scene::MouseScrollWheel,
|
||||||
ElementBox, MouseRegion, RenderContext, ScrollWheelEvent, View,
|
ElementBox, MouseRegion, RenderContext, ScrollWheelEvent, View,
|
||||||
};
|
};
|
||||||
use json::ToJson;
|
use json::ToJson;
|
||||||
|
@ -292,7 +292,7 @@ impl Element for UniformList {
|
||||||
MouseRegion::new::<Self>(self.view_id, 0, visible_bounds).on_scroll({
|
MouseRegion::new::<Self>(self.view_id, 0, visible_bounds).on_scroll({
|
||||||
let scroll_max = layout.scroll_max;
|
let scroll_max = layout.scroll_max;
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
move |ScrollWheelRegionEvent {
|
move |MouseScrollWheel {
|
||||||
platform_event:
|
platform_event:
|
||||||
ScrollWheelEvent {
|
ScrollWheelEvent {
|
||||||
position,
|
position,
|
||||||
|
@ -324,23 +324,6 @@ impl Element for UniformList {
|
||||||
cx.scene.pop_layer();
|
cx.scene.pop_layer();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
layout: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
let mut handled = false;
|
|
||||||
for item in &mut layout.items {
|
|
||||||
handled = item.dispatch_event(event, cx) || handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
handled
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct KeyUpEvent {
|
||||||
pub keystroke: Keystroke,
|
pub keystroke: Keystroke,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct ModifiersChangedEvent {
|
pub struct ModifiersChangedEvent {
|
||||||
pub ctrl: bool,
|
pub ctrl: bool,
|
||||||
pub alt: bool,
|
pub alt: bool,
|
||||||
|
|
|
@ -7,9 +7,8 @@ use crate::{
|
||||||
keymap::Keystroke,
|
keymap::Keystroke,
|
||||||
platform::{CursorStyle, Event},
|
platform::{CursorStyle, Event},
|
||||||
scene::{
|
scene::{
|
||||||
ClickRegionEvent, CursorRegion, DownOutRegionEvent, DownRegionEvent, DragRegionEvent,
|
CursorRegion, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseEvent, MouseHover,
|
||||||
HoverRegionEvent, MouseRegionEvent, MoveRegionEvent, ScrollWheelRegionEvent,
|
MouseMove, MouseScrollWheel, MouseUp, MouseUpOut,
|
||||||
UpOutRegionEvent, UpRegionEvent,
|
|
||||||
},
|
},
|
||||||
text_layout::TextLayoutCache,
|
text_layout::TextLayoutCache,
|
||||||
Action, AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, Appearance,
|
Action, AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, Appearance,
|
||||||
|
@ -229,293 +228,283 @@ impl Presenter {
|
||||||
event_reused: bool,
|
event_reused: bool,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
let mut mouse_events = SmallVec::<[_; 2]>::new();
|
||||||
let mut events_to_send = Vec::new();
|
let mut notified_views: HashSet<usize> = Default::default();
|
||||||
let mut notified_views: HashSet<usize> = Default::default();
|
|
||||||
|
|
||||||
// 1. Allocate the correct set of GPUI events generated from the platform events
|
// 1. Handle platform event. Keyboard events get dispatched immediately, while mouse events
|
||||||
// -> These are usually small: [Mouse Down] or [Mouse up, Click] or [Mouse Moved, Mouse Dragged?]
|
// get mapped into the mouse-specific MouseEvent type.
|
||||||
// -> Also moves around mouse related state
|
// -> These are usually small: [Mouse Down] or [Mouse up, Click] or [Mouse Moved, Mouse Dragged?]
|
||||||
match &event {
|
// -> Also updates mouse-related state
|
||||||
Event::MouseDown(e) => {
|
match &event {
|
||||||
// Click events are weird because they can be fired after a drag event.
|
Event::KeyDown(e) => return cx.dispatch_key_down(self.window_id, e),
|
||||||
// MDN says that browsers handle this by starting from 'the most
|
Event::KeyUp(e) => return cx.dispatch_key_up(self.window_id, e),
|
||||||
// specific ancestor element that contained both [positions]'
|
Event::ModifiersChanged(e) => return cx.dispatch_modifiers_changed(self.window_id, e),
|
||||||
// So we need to store the overlapping regions on mouse down.
|
Event::MouseDown(e) => {
|
||||||
|
// Click events are weird because they can be fired after a drag event.
|
||||||
|
// MDN says that browsers handle this by starting from 'the most
|
||||||
|
// specific ancestor element that contained both [positions]'
|
||||||
|
// So we need to store the overlapping regions on mouse down.
|
||||||
|
|
||||||
// If there is already clicked_button stored, don't replace it.
|
// If there is already clicked_button stored, don't replace it.
|
||||||
if self.clicked_button.is_none() {
|
if self.clicked_button.is_none() {
|
||||||
self.clicked_region_ids = self
|
self.clicked_region_ids = self
|
||||||
.mouse_regions
|
.mouse_regions
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(region, _)| {
|
.filter_map(|(region, _)| {
|
||||||
if region.bounds.contains_point(e.position) {
|
if region.bounds.contains_point(e.position) {
|
||||||
Some(region.id())
|
Some(region.id())
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
self.clicked_button = Some(e.button);
|
|
||||||
}
|
|
||||||
|
|
||||||
events_to_send.push(MouseRegionEvent::Down(DownRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
events_to_send.push(MouseRegionEvent::DownOut(DownOutRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
Event::MouseUp(e) => {
|
|
||||||
// NOTE: The order of event pushes is important! MouseUp events MUST be fired
|
|
||||||
// before click events, and so the UpRegionEvent events need to be pushed before
|
|
||||||
// ClickRegionEvents
|
|
||||||
events_to_send.push(MouseRegionEvent::Up(UpRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
events_to_send.push(MouseRegionEvent::UpOut(UpOutRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
events_to_send.push(MouseRegionEvent::Click(ClickRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
Event::MouseMoved(
|
|
||||||
e @ MouseMovedEvent {
|
|
||||||
position,
|
|
||||||
pressed_button,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
) => {
|
|
||||||
let mut style_to_assign = CursorStyle::Arrow;
|
|
||||||
for region in self.cursor_regions.iter().rev() {
|
|
||||||
if region.bounds.contains_point(*position) {
|
|
||||||
style_to_assign = region.style;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cx.platform().set_cursor_style(style_to_assign);
|
|
||||||
|
|
||||||
if !event_reused {
|
|
||||||
if pressed_button.is_some() {
|
|
||||||
events_to_send.push(MouseRegionEvent::Drag(DragRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
prev_mouse_position: self.mouse_position,
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
} else if let Some(clicked_button) = self.clicked_button {
|
|
||||||
// Mouse up event happened outside the current window. Simulate mouse up button event
|
|
||||||
let button_event = e.to_button_event(clicked_button);
|
|
||||||
events_to_send.push(MouseRegionEvent::Up(UpRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: button_event.clone(),
|
|
||||||
}));
|
|
||||||
events_to_send.push(MouseRegionEvent::UpOut(UpOutRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: button_event.clone(),
|
|
||||||
}));
|
|
||||||
events_to_send.push(MouseRegionEvent::Click(ClickRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: button_event.clone(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
events_to_send.push(MouseRegionEvent::Move(MoveRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
events_to_send.push(MouseRegionEvent::Hover(HoverRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
started: false,
|
|
||||||
}));
|
|
||||||
|
|
||||||
self.last_mouse_moved_event = Some(event.clone());
|
|
||||||
}
|
|
||||||
Event::ScrollWheel(e) => {
|
|
||||||
events_to_send.push(MouseRegionEvent::ScrollWheel(ScrollWheelRegionEvent {
|
|
||||||
region: Default::default(),
|
|
||||||
platform_event: e.clone(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(position) = event.position() {
|
|
||||||
self.mouse_position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut any_event_handled = false;
|
|
||||||
// 2. Process the raw mouse events into region events
|
|
||||||
for mut region_event in events_to_send {
|
|
||||||
let mut valid_regions = Vec::new();
|
|
||||||
|
|
||||||
// GPUI elements are arranged by depth but sibling elements can register overlapping
|
|
||||||
// mouse regions. As such, hover events are only fired on overlapping elements which
|
|
||||||
// are at the same depth as the topmost element which overlaps with the mouse.
|
|
||||||
|
|
||||||
match ®ion_event {
|
|
||||||
MouseRegionEvent::Hover(_) => {
|
|
||||||
let mut top_most_depth = None;
|
|
||||||
let mouse_position = self.mouse_position.clone();
|
|
||||||
for (region, depth) in self.mouse_regions.iter().rev() {
|
|
||||||
// Allow mouse regions to appear transparent to hovers
|
|
||||||
if !region.hoverable {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let contains_mouse = region.bounds.contains_point(mouse_position);
|
|
||||||
|
|
||||||
if contains_mouse && top_most_depth.is_none() {
|
|
||||||
top_most_depth = Some(depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This unwrap relies on short circuiting boolean expressions
|
|
||||||
// The right side of the && is only executed when contains_mouse
|
|
||||||
// is true, and we know above that when contains_mouse is true
|
|
||||||
// top_most_depth is set
|
|
||||||
if contains_mouse && depth == top_most_depth.unwrap() {
|
|
||||||
//Ensure that hover entrance events aren't sent twice
|
|
||||||
if self.hovered_region_ids.insert(region.id()) {
|
|
||||||
valid_regions.push(region.clone());
|
|
||||||
if region.notify_on_hover {
|
|
||||||
notified_views.insert(region.id().view_id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Ensure that hover exit events aren't sent twice
|
None
|
||||||
if self.hovered_region_ids.remove(®ion.id()) {
|
|
||||||
valid_regions.push(region.clone());
|
|
||||||
if region.notify_on_hover {
|
|
||||||
notified_views.insert(region.id().view_id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
.collect();
|
||||||
MouseRegionEvent::Down(_) | MouseRegionEvent::Up(_) => {
|
|
||||||
for (region, _) in self.mouse_regions.iter().rev() {
|
|
||||||
if region.bounds.contains_point(self.mouse_position) {
|
|
||||||
if region.notify_on_click {
|
|
||||||
notified_views.insert(region.id().view_id());
|
|
||||||
}
|
|
||||||
valid_regions.push(region.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MouseRegionEvent::Click(e) => {
|
|
||||||
// Only raise click events if the released button is the same as the one stored
|
|
||||||
if self
|
|
||||||
.clicked_button
|
|
||||||
.map(|clicked_button| clicked_button == e.button)
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
// Clear clicked regions and clicked button
|
|
||||||
let clicked_region_ids =
|
|
||||||
std::mem::replace(&mut self.clicked_region_ids, Default::default());
|
|
||||||
self.clicked_button = None;
|
|
||||||
|
|
||||||
// Find regions which still overlap with the mouse since the last MouseDown happened
|
self.clicked_button = Some(e.button);
|
||||||
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
|
||||||
if clicked_region_ids.contains(&mouse_region.id()) {
|
|
||||||
if mouse_region.bounds.contains_point(self.mouse_position) {
|
|
||||||
valid_regions.push(mouse_region.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MouseRegionEvent::Drag(_) => {
|
|
||||||
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
|
||||||
if self.clicked_region_ids.contains(&mouse_region.id()) {
|
|
||||||
valid_regions.push(mouse_region.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseRegionEvent::UpOut(_) | MouseRegionEvent::DownOut(_) => {
|
|
||||||
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
|
||||||
// NOT contains
|
|
||||||
if !mouse_region.bounds.contains_point(self.mouse_position) {
|
|
||||||
valid_regions.push(mouse_region.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
|
||||||
// Contains
|
|
||||||
if mouse_region.bounds.contains_point(self.mouse_position) {
|
|
||||||
valid_regions.push(mouse_region.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//3. Fire region events
|
mouse_events.push(MouseEvent::Down(MouseDown {
|
||||||
let hovered_region_ids = self.hovered_region_ids.clone();
|
region: Default::default(),
|
||||||
for valid_region in valid_regions.into_iter() {
|
platform_event: e.clone(),
|
||||||
let mut event_cx = self.build_event_context(&mut notified_views, cx);
|
}));
|
||||||
|
mouse_events.push(MouseEvent::DownOut(MouseDownOut {
|
||||||
region_event.set_region(valid_region.bounds);
|
region: Default::default(),
|
||||||
if let MouseRegionEvent::Hover(e) = &mut region_event {
|
platform_event: e.clone(),
|
||||||
e.started = hovered_region_ids.contains(&valid_region.id())
|
}));
|
||||||
}
|
}
|
||||||
// Handle Down events if the MouseRegion has a Click or Drag handler. This makes the api more intuitive as you would
|
Event::MouseUp(e) => {
|
||||||
// not expect a MouseRegion to be transparent to Down events if it also has a Click handler.
|
// NOTE: The order of event pushes is important! MouseUp events MUST be fired
|
||||||
// This behavior can be overridden by adding a Down handler that calls cx.propogate_event
|
// before click events, and so the MouseUp events need to be pushed before
|
||||||
if let MouseRegionEvent::Down(e) = ®ion_event {
|
// MouseClick events.
|
||||||
if valid_region
|
mouse_events.push(MouseEvent::Up(MouseUp {
|
||||||
.handlers
|
region: Default::default(),
|
||||||
.contains_handler(MouseRegionEvent::click_disc(), Some(e.button))
|
platform_event: e.clone(),
|
||||||
|| valid_region
|
}));
|
||||||
.handlers
|
mouse_events.push(MouseEvent::UpOut(MouseUpOut {
|
||||||
.contains_handler(MouseRegionEvent::drag_disc(), Some(e.button))
|
region: Default::default(),
|
||||||
{
|
platform_event: e.clone(),
|
||||||
event_cx.handled = true;
|
}));
|
||||||
}
|
mouse_events.push(MouseEvent::Click(MouseClick {
|
||||||
}
|
region: Default::default(),
|
||||||
|
platform_event: e.clone(),
|
||||||
if let Some(callback) = valid_region.handlers.get(®ion_event.handler_key()) {
|
}));
|
||||||
event_cx.handled = true;
|
}
|
||||||
event_cx.with_current_view(valid_region.id().view_id(), {
|
Event::MouseMoved(
|
||||||
let region_event = region_event.clone();
|
e @ MouseMovedEvent {
|
||||||
|cx| {
|
position,
|
||||||
callback(region_event, cx);
|
pressed_button,
|
||||||
}
|
..
|
||||||
});
|
},
|
||||||
}
|
) => {
|
||||||
|
let mut style_to_assign = CursorStyle::Arrow;
|
||||||
any_event_handled = any_event_handled || event_cx.handled;
|
for region in self.cursor_regions.iter().rev() {
|
||||||
// For bubbling events, if the event was handled, don't continue dispatching
|
if region.bounds.contains_point(*position) {
|
||||||
// This only makes sense for local events.
|
style_to_assign = region.style;
|
||||||
if event_cx.handled && region_event.is_capturable() {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
cx.platform().set_cursor_style(style_to_assign);
|
||||||
|
|
||||||
if !any_event_handled && !event_reused {
|
if !event_reused {
|
||||||
let mut event_cx = self.build_event_context(&mut notified_views, cx);
|
if pressed_button.is_some() {
|
||||||
any_event_handled = event_cx.dispatch_event(root_view_id, &event);
|
mouse_events.push(MouseEvent::Drag(MouseDrag {
|
||||||
}
|
region: Default::default(),
|
||||||
|
prev_mouse_position: self.mouse_position,
|
||||||
|
platform_event: e.clone(),
|
||||||
|
}));
|
||||||
|
} else if let Some(clicked_button) = self.clicked_button {
|
||||||
|
// Mouse up event happened outside the current window. Simulate mouse up button event
|
||||||
|
let button_event = e.to_button_event(clicked_button);
|
||||||
|
mouse_events.push(MouseEvent::Up(MouseUp {
|
||||||
|
region: Default::default(),
|
||||||
|
platform_event: button_event.clone(),
|
||||||
|
}));
|
||||||
|
mouse_events.push(MouseEvent::UpOut(MouseUpOut {
|
||||||
|
region: Default::default(),
|
||||||
|
platform_event: button_event.clone(),
|
||||||
|
}));
|
||||||
|
mouse_events.push(MouseEvent::Click(MouseClick {
|
||||||
|
region: Default::default(),
|
||||||
|
platform_event: button_event.clone(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
for view_id in notified_views {
|
mouse_events.push(MouseEvent::Move(MouseMove {
|
||||||
cx.notify_view(self.window_id, view_id);
|
region: Default::default(),
|
||||||
}
|
platform_event: e.clone(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
any_event_handled
|
mouse_events.push(MouseEvent::Hover(MouseHover {
|
||||||
} else {
|
region: Default::default(),
|
||||||
false
|
platform_event: e.clone(),
|
||||||
|
started: false,
|
||||||
|
}));
|
||||||
|
|
||||||
|
self.last_mouse_moved_event = Some(event.clone());
|
||||||
|
}
|
||||||
|
Event::ScrollWheel(e) => mouse_events.push(MouseEvent::ScrollWheel(MouseScrollWheel {
|
||||||
|
region: Default::default(),
|
||||||
|
platform_event: e.clone(),
|
||||||
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(position) = event.position() {
|
||||||
|
self.mouse_position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Dispatch mouse events on regions
|
||||||
|
let mut any_event_handled = false;
|
||||||
|
for mut mouse_event in mouse_events {
|
||||||
|
let mut valid_regions = Vec::new();
|
||||||
|
|
||||||
|
// GPUI elements are arranged by depth but sibling elements can register overlapping
|
||||||
|
// mouse regions. As such, hover events are only fired on overlapping elements which
|
||||||
|
// are at the same depth as the topmost element which overlaps with the mouse.
|
||||||
|
match &mouse_event {
|
||||||
|
MouseEvent::Hover(_) => {
|
||||||
|
let mut top_most_depth = None;
|
||||||
|
let mouse_position = self.mouse_position.clone();
|
||||||
|
for (region, depth) in self.mouse_regions.iter().rev() {
|
||||||
|
// Allow mouse regions to appear transparent to hovers
|
||||||
|
if !region.hoverable {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let contains_mouse = region.bounds.contains_point(mouse_position);
|
||||||
|
|
||||||
|
if contains_mouse && top_most_depth.is_none() {
|
||||||
|
top_most_depth = Some(depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This unwrap relies on short circuiting boolean expressions
|
||||||
|
// The right side of the && is only executed when contains_mouse
|
||||||
|
// is true, and we know above that when contains_mouse is true
|
||||||
|
// top_most_depth is set
|
||||||
|
if contains_mouse && depth == top_most_depth.unwrap() {
|
||||||
|
//Ensure that hover entrance events aren't sent twice
|
||||||
|
if self.hovered_region_ids.insert(region.id()) {
|
||||||
|
valid_regions.push(region.clone());
|
||||||
|
if region.notify_on_hover {
|
||||||
|
notified_views.insert(region.id().view_id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Ensure that hover exit events aren't sent twice
|
||||||
|
if self.hovered_region_ids.remove(®ion.id()) {
|
||||||
|
valid_regions.push(region.clone());
|
||||||
|
if region.notify_on_hover {
|
||||||
|
notified_views.insert(region.id().view_id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MouseEvent::Down(_) | MouseEvent::Up(_) => {
|
||||||
|
for (region, _) in self.mouse_regions.iter().rev() {
|
||||||
|
if region.bounds.contains_point(self.mouse_position) {
|
||||||
|
if region.notify_on_click {
|
||||||
|
notified_views.insert(region.id().view_id());
|
||||||
|
}
|
||||||
|
valid_regions.push(region.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MouseEvent::Click(e) => {
|
||||||
|
// Only raise click events if the released button is the same as the one stored
|
||||||
|
if self
|
||||||
|
.clicked_button
|
||||||
|
.map(|clicked_button| clicked_button == e.button)
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
// Clear clicked regions and clicked button
|
||||||
|
let clicked_region_ids =
|
||||||
|
std::mem::replace(&mut self.clicked_region_ids, Default::default());
|
||||||
|
self.clicked_button = None;
|
||||||
|
|
||||||
|
// Find regions which still overlap with the mouse since the last MouseDown happened
|
||||||
|
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
||||||
|
if clicked_region_ids.contains(&mouse_region.id()) {
|
||||||
|
if mouse_region.bounds.contains_point(self.mouse_position) {
|
||||||
|
valid_regions.push(mouse_region.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MouseEvent::Drag(_) => {
|
||||||
|
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
||||||
|
if self.clicked_region_ids.contains(&mouse_region.id()) {
|
||||||
|
valid_regions.push(mouse_region.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseEvent::UpOut(_) | MouseEvent::DownOut(_) => {
|
||||||
|
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
||||||
|
// NOT contains
|
||||||
|
if !mouse_region.bounds.contains_point(self.mouse_position) {
|
||||||
|
valid_regions.push(mouse_region.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
for (mouse_region, _) in self.mouse_regions.iter().rev() {
|
||||||
|
// Contains
|
||||||
|
if mouse_region.bounds.contains_point(self.mouse_position) {
|
||||||
|
valid_regions.push(mouse_region.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//3. Fire region events
|
||||||
|
let hovered_region_ids = self.hovered_region_ids.clone();
|
||||||
|
for valid_region in valid_regions.into_iter() {
|
||||||
|
let mut event_cx = self.build_event_context(&mut notified_views, cx);
|
||||||
|
|
||||||
|
mouse_event.set_region(valid_region.bounds);
|
||||||
|
if let MouseEvent::Hover(e) = &mut mouse_event {
|
||||||
|
e.started = hovered_region_ids.contains(&valid_region.id())
|
||||||
|
}
|
||||||
|
// Handle Down events if the MouseRegion has a Click or Drag handler. This makes the api more intuitive as you would
|
||||||
|
// not expect a MouseRegion to be transparent to Down events if it also has a Click handler.
|
||||||
|
// This behavior can be overridden by adding a Down handler that calls cx.propogate_event
|
||||||
|
if let MouseEvent::Down(e) = &mouse_event {
|
||||||
|
if valid_region
|
||||||
|
.handlers
|
||||||
|
.contains_handler(MouseEvent::click_disc(), Some(e.button))
|
||||||
|
|| valid_region
|
||||||
|
.handlers
|
||||||
|
.contains_handler(MouseEvent::drag_disc(), Some(e.button))
|
||||||
|
{
|
||||||
|
event_cx.handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(callback) = valid_region.handlers.get(&mouse_event.handler_key()) {
|
||||||
|
event_cx.handled = true;
|
||||||
|
event_cx.with_current_view(valid_region.id().view_id(), {
|
||||||
|
let region_event = mouse_event.clone();
|
||||||
|
|cx| {
|
||||||
|
callback(region_event, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
any_event_handled = any_event_handled || event_cx.handled;
|
||||||
|
// For bubbling events, if the event was handled, don't continue dispatching
|
||||||
|
// This only makes sense for local events.
|
||||||
|
if event_cx.handled && mouse_event.is_capturable() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for view_id in notified_views {
|
||||||
|
cx.notify_view(self.window_id, view_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
any_event_handled
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_event_context<'a>(
|
pub fn build_event_context<'a>(
|
||||||
|
@ -524,7 +513,6 @@ impl Presenter {
|
||||||
cx: &'a mut MutableAppContext,
|
cx: &'a mut MutableAppContext,
|
||||||
) -> EventContext<'a> {
|
) -> EventContext<'a> {
|
||||||
EventContext {
|
EventContext {
|
||||||
rendered_views: &mut self.rendered_views,
|
|
||||||
font_cache: &self.font_cache,
|
font_cache: &self.font_cache,
|
||||||
text_layout_cache: &self.text_layout_cache,
|
text_layout_cache: &self.text_layout_cache,
|
||||||
view_stack: Default::default(),
|
view_stack: Default::default(),
|
||||||
|
@ -743,7 +731,6 @@ impl<'a> Deref for PaintContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventContext<'a> {
|
pub struct EventContext<'a> {
|
||||||
rendered_views: &'a mut HashMap<usize, ElementBox>,
|
|
||||||
pub font_cache: &'a FontCache,
|
pub font_cache: &'a FontCache,
|
||||||
pub text_layout_cache: &'a TextLayoutCache,
|
pub text_layout_cache: &'a TextLayoutCache,
|
||||||
pub app: &'a mut MutableAppContext,
|
pub app: &'a mut MutableAppContext,
|
||||||
|
@ -755,17 +742,6 @@ pub struct EventContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EventContext<'a> {
|
impl<'a> EventContext<'a> {
|
||||||
fn dispatch_event(&mut self, view_id: usize, event: &Event) -> bool {
|
|
||||||
if let Some(mut element) = self.rendered_views.remove(&view_id) {
|
|
||||||
let result =
|
|
||||||
self.with_current_view(view_id, |this| element.dispatch_event(event, this));
|
|
||||||
self.rendered_views.insert(view_id, element);
|
|
||||||
result
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn with_current_view<F, T>(&mut self, view_id: usize, f: F) -> T
|
fn with_current_view<F, T>(&mut self, view_id: usize, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> T,
|
F: FnOnce(&mut Self) -> T,
|
||||||
|
@ -1028,27 +1004,6 @@ impl Element for ChildView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: RectF,
|
|
||||||
view_is_valid: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
if *view_is_valid {
|
|
||||||
cx.dispatch_event(self.view.id(), event)
|
|
||||||
} else {
|
|
||||||
log::error!(
|
|
||||||
"dispatch_event called on a ChildView element whose underlying view was dropped (view_id: {}, name: {:?})",
|
|
||||||
self.view.id(),
|
|
||||||
self.view_name
|
|
||||||
);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
mod mouse_event;
|
||||||
mod mouse_region;
|
mod mouse_region;
|
||||||
mod mouse_region_event;
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
|
@ -15,8 +15,8 @@ use crate::{
|
||||||
platform::{current::Surface, CursorStyle},
|
platform::{current::Surface, CursorStyle},
|
||||||
ImageData,
|
ImageData,
|
||||||
};
|
};
|
||||||
|
pub use mouse_event::*;
|
||||||
pub use mouse_region::*;
|
pub use mouse_region::*;
|
||||||
pub use mouse_region_event::*;
|
|
||||||
|
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
|
|
233
crates/gpui/src/scene/mouse_event.rs
Normal file
233
crates/gpui/src/scene/mouse_event.rs
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
use std::{
|
||||||
|
mem::{discriminant, Discriminant},
|
||||||
|
ops::Deref,
|
||||||
|
};
|
||||||
|
|
||||||
|
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
||||||
|
|
||||||
|
use crate::{MouseButton, MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent};
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseMove {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: MouseMovedEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseMove {
|
||||||
|
type Target = MouseMovedEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseDrag {
|
||||||
|
pub region: RectF,
|
||||||
|
pub prev_mouse_position: Vector2F,
|
||||||
|
pub platform_event: MouseMovedEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseDrag {
|
||||||
|
type Target = MouseMovedEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseHover {
|
||||||
|
pub region: RectF,
|
||||||
|
pub started: bool,
|
||||||
|
pub platform_event: MouseMovedEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseHover {
|
||||||
|
type Target = MouseMovedEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseDown {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: MouseButtonEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseDown {
|
||||||
|
type Target = MouseButtonEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseUp {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: MouseButtonEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseUp {
|
||||||
|
type Target = MouseButtonEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseClick {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: MouseButtonEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseClick {
|
||||||
|
type Target = MouseButtonEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseDownOut {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: MouseButtonEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseDownOut {
|
||||||
|
type Target = MouseButtonEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseUpOut {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: MouseButtonEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseUpOut {
|
||||||
|
type Target = MouseButtonEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct MouseScrollWheel {
|
||||||
|
pub region: RectF,
|
||||||
|
pub platform_event: ScrollWheelEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for MouseScrollWheel {
|
||||||
|
type Target = ScrollWheelEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.platform_event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum MouseEvent {
|
||||||
|
Move(MouseMove),
|
||||||
|
Drag(MouseDrag),
|
||||||
|
Hover(MouseHover),
|
||||||
|
Down(MouseDown),
|
||||||
|
Up(MouseUp),
|
||||||
|
Click(MouseClick),
|
||||||
|
DownOut(MouseDownOut),
|
||||||
|
UpOut(MouseUpOut),
|
||||||
|
ScrollWheel(MouseScrollWheel),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MouseEvent {
|
||||||
|
pub fn set_region(&mut self, region: RectF) {
|
||||||
|
match self {
|
||||||
|
MouseEvent::Move(r) => r.region = region,
|
||||||
|
MouseEvent::Drag(r) => r.region = region,
|
||||||
|
MouseEvent::Hover(r) => r.region = region,
|
||||||
|
MouseEvent::Down(r) => r.region = region,
|
||||||
|
MouseEvent::Up(r) => r.region = region,
|
||||||
|
MouseEvent::Click(r) => r.region = region,
|
||||||
|
MouseEvent::DownOut(r) => r.region = region,
|
||||||
|
MouseEvent::UpOut(r) => r.region = region,
|
||||||
|
MouseEvent::ScrollWheel(r) => r.region = region,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When true, mouse event handlers must call cx.propagate_event() to bubble
|
||||||
|
/// the event to handlers they are painted on top of.
|
||||||
|
pub fn is_capturable(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
MouseEvent::Move(_) => true,
|
||||||
|
MouseEvent::Drag(_) => true,
|
||||||
|
MouseEvent::Hover(_) => false,
|
||||||
|
MouseEvent::Down(_) => true,
|
||||||
|
MouseEvent::Up(_) => true,
|
||||||
|
MouseEvent::Click(_) => true,
|
||||||
|
MouseEvent::DownOut(_) => false,
|
||||||
|
MouseEvent::UpOut(_) => false,
|
||||||
|
MouseEvent::ScrollWheel(_) => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MouseEvent {
|
||||||
|
pub fn move_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::Move(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn drag_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::Drag(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hover_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::Hover(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn down_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::Down(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn up_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::Up(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn up_out_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::UpOut(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn click_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::Click(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn down_out_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::DownOut(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scroll_wheel_disc() -> Discriminant<MouseEvent> {
|
||||||
|
discriminant(&MouseEvent::ScrollWheel(Default::default()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handler_key(&self) -> (Discriminant<MouseEvent>, Option<MouseButton>) {
|
||||||
|
match self {
|
||||||
|
MouseEvent::Move(_) => (Self::move_disc(), None),
|
||||||
|
MouseEvent::Drag(e) => (Self::drag_disc(), e.pressed_button),
|
||||||
|
MouseEvent::Hover(_) => (Self::hover_disc(), None),
|
||||||
|
MouseEvent::Down(e) => (Self::down_disc(), Some(e.button)),
|
||||||
|
MouseEvent::Up(e) => (Self::up_disc(), Some(e.button)),
|
||||||
|
MouseEvent::Click(e) => (Self::click_disc(), Some(e.button)),
|
||||||
|
MouseEvent::UpOut(e) => (Self::up_out_disc(), Some(e.button)),
|
||||||
|
MouseEvent::DownOut(e) => (Self::down_out_disc(), Some(e.button)),
|
||||||
|
MouseEvent::ScrollWheel(_) => (Self::scroll_wheel_disc(), None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,11 +7,11 @@ use pathfinder_geometry::rect::RectF;
|
||||||
use crate::{EventContext, MouseButton};
|
use crate::{EventContext, MouseButton};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
mouse_region_event::{
|
mouse_event::{
|
||||||
ClickRegionEvent, DownOutRegionEvent, DownRegionEvent, DragRegionEvent, HoverRegionEvent,
|
MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseEvent, MouseHover, MouseMove, MouseUp,
|
||||||
MouseRegionEvent, MoveRegionEvent, UpOutRegionEvent, UpRegionEvent,
|
MouseUpOut,
|
||||||
},
|
},
|
||||||
ScrollWheelRegionEvent,
|
MouseScrollWheel,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -62,7 +62,7 @@ impl MouseRegion {
|
||||||
pub fn on_down(
|
pub fn on_down(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DownRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDown, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_down(button, handler);
|
self.handlers = self.handlers.on_down(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -71,7 +71,7 @@ impl MouseRegion {
|
||||||
pub fn on_up(
|
pub fn on_up(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(UpRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseUp, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_up(button, handler);
|
self.handlers = self.handlers.on_up(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -80,7 +80,7 @@ impl MouseRegion {
|
||||||
pub fn on_click(
|
pub fn on_click(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(ClickRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseClick, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_click(button, handler);
|
self.handlers = self.handlers.on_click(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -89,7 +89,7 @@ impl MouseRegion {
|
||||||
pub fn on_down_out(
|
pub fn on_down_out(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DownOutRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDownOut, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_down_out(button, handler);
|
self.handlers = self.handlers.on_down_out(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -98,7 +98,7 @@ impl MouseRegion {
|
||||||
pub fn on_up_out(
|
pub fn on_up_out(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(UpOutRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseUpOut, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_up_out(button, handler);
|
self.handlers = self.handlers.on_up_out(button, handler);
|
||||||
self
|
self
|
||||||
|
@ -107,31 +107,25 @@ impl MouseRegion {
|
||||||
pub fn on_drag(
|
pub fn on_drag(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DragRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDrag, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_drag(button, handler);
|
self.handlers = self.handlers.on_drag(button, handler);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_hover(
|
pub fn on_hover(mut self, handler: impl Fn(MouseHover, &mut EventContext) + 'static) -> Self {
|
||||||
mut self,
|
|
||||||
handler: impl Fn(HoverRegionEvent, &mut EventContext) + 'static,
|
|
||||||
) -> Self {
|
|
||||||
self.handlers = self.handlers.on_hover(handler);
|
self.handlers = self.handlers.on_hover(handler);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_move(
|
pub fn on_move(mut self, handler: impl Fn(MouseMove, &mut EventContext) + 'static) -> Self {
|
||||||
mut self,
|
|
||||||
handler: impl Fn(MoveRegionEvent, &mut EventContext) + 'static,
|
|
||||||
) -> Self {
|
|
||||||
self.handlers = self.handlers.on_move(handler);
|
self.handlers = self.handlers.on_move(handler);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_scroll(
|
pub fn on_scroll(
|
||||||
mut self,
|
mut self,
|
||||||
handler: impl Fn(ScrollWheelRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseScrollWheel, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.handlers = self.handlers.on_scroll(handler);
|
self.handlers = self.handlers.on_scroll(handler);
|
||||||
self
|
self
|
||||||
|
@ -187,8 +181,8 @@ impl MouseRegionId {
|
||||||
pub struct HandlerSet {
|
pub struct HandlerSet {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub set: HashMap<
|
pub set: HashMap<
|
||||||
(Discriminant<MouseRegionEvent>, Option<MouseButton>),
|
(Discriminant<MouseEvent>, Option<MouseButton>),
|
||||||
Rc<dyn Fn(MouseRegionEvent, &mut EventContext)>,
|
Rc<dyn Fn(MouseEvent, &mut EventContext)>,
|
||||||
>,
|
>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,68 +190,50 @@ impl HandlerSet {
|
||||||
pub fn capture_all() -> Self {
|
pub fn capture_all() -> Self {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
let mut set: HashMap<
|
let mut set: HashMap<
|
||||||
(Discriminant<MouseRegionEvent>, Option<MouseButton>),
|
(Discriminant<MouseEvent>, Option<MouseButton>),
|
||||||
Rc<dyn Fn(MouseRegionEvent, &mut EventContext)>,
|
Rc<dyn Fn(MouseEvent, &mut EventContext)>,
|
||||||
> = Default::default();
|
> = Default::default();
|
||||||
|
|
||||||
set.insert((MouseRegionEvent::move_disc(), None), Rc::new(|_, _| {}));
|
set.insert((MouseEvent::move_disc(), None), Rc::new(|_, _| {}));
|
||||||
set.insert((MouseRegionEvent::hover_disc(), None), Rc::new(|_, _| {}));
|
set.insert((MouseEvent::hover_disc(), None), Rc::new(|_, _| {}));
|
||||||
for button in MouseButton::all() {
|
for button in MouseButton::all() {
|
||||||
|
set.insert((MouseEvent::drag_disc(), Some(button)), Rc::new(|_, _| {}));
|
||||||
|
set.insert((MouseEvent::down_disc(), Some(button)), Rc::new(|_, _| {}));
|
||||||
|
set.insert((MouseEvent::up_disc(), Some(button)), Rc::new(|_, _| {}));
|
||||||
|
set.insert((MouseEvent::click_disc(), Some(button)), Rc::new(|_, _| {}));
|
||||||
set.insert(
|
set.insert(
|
||||||
(MouseRegionEvent::drag_disc(), Some(button)),
|
(MouseEvent::down_out_disc(), Some(button)),
|
||||||
Rc::new(|_, _| {}),
|
Rc::new(|_, _| {}),
|
||||||
);
|
);
|
||||||
set.insert(
|
set.insert(
|
||||||
(MouseRegionEvent::down_disc(), Some(button)),
|
(MouseEvent::up_out_disc(), Some(button)),
|
||||||
Rc::new(|_, _| {}),
|
|
||||||
);
|
|
||||||
set.insert(
|
|
||||||
(MouseRegionEvent::up_disc(), Some(button)),
|
|
||||||
Rc::new(|_, _| {}),
|
|
||||||
);
|
|
||||||
set.insert(
|
|
||||||
(MouseRegionEvent::click_disc(), Some(button)),
|
|
||||||
Rc::new(|_, _| {}),
|
|
||||||
);
|
|
||||||
set.insert(
|
|
||||||
(MouseRegionEvent::down_out_disc(), Some(button)),
|
|
||||||
Rc::new(|_, _| {}),
|
|
||||||
);
|
|
||||||
set.insert(
|
|
||||||
(MouseRegionEvent::up_out_disc(), Some(button)),
|
|
||||||
Rc::new(|_, _| {}),
|
Rc::new(|_, _| {}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
set.insert(
|
set.insert((MouseEvent::scroll_wheel_disc(), None), Rc::new(|_, _| {}));
|
||||||
(MouseRegionEvent::scroll_wheel_disc(), None),
|
|
||||||
Rc::new(|_, _| {}),
|
|
||||||
);
|
|
||||||
|
|
||||||
HandlerSet { set }
|
HandlerSet { set }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(
|
pub fn get(
|
||||||
&self,
|
&self,
|
||||||
key: &(Discriminant<MouseRegionEvent>, Option<MouseButton>),
|
key: &(Discriminant<MouseEvent>, Option<MouseButton>),
|
||||||
) -> Option<Rc<dyn Fn(MouseRegionEvent, &mut EventContext)>> {
|
) -> Option<Rc<dyn Fn(MouseEvent, &mut EventContext)>> {
|
||||||
self.set.get(key).cloned()
|
self.set.get(key).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_handler(
|
pub fn contains_handler(
|
||||||
&self,
|
&self,
|
||||||
event: Discriminant<MouseRegionEvent>,
|
event: Discriminant<MouseEvent>,
|
||||||
button: Option<MouseButton>,
|
button: Option<MouseButton>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
self.set.contains_key(&(event, button))
|
self.set.contains_key(&(event, button))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_move(
|
pub fn on_move(mut self, handler: impl Fn(MouseMove, &mut EventContext) + 'static) -> Self {
|
||||||
mut self,
|
self.set.insert((MouseEvent::move_disc(), None),
|
||||||
handler: impl Fn(MoveRegionEvent, &mut EventContext) + 'static,
|
|
||||||
) -> Self {
|
|
||||||
self.set.insert((MouseRegionEvent::move_disc(), None),
|
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::Move(e) = region_event {
|
if let MouseEvent::Move(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -271,11 +247,11 @@ impl HandlerSet {
|
||||||
pub fn on_down(
|
pub fn on_down(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DownRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDown, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::down_disc(), Some(button)),
|
self.set.insert((MouseEvent::down_disc(), Some(button)),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::Down(e) = region_event {
|
if let MouseEvent::Down(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -289,11 +265,11 @@ impl HandlerSet {
|
||||||
pub fn on_up(
|
pub fn on_up(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(UpRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseUp, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::up_disc(), Some(button)),
|
self.set.insert((MouseEvent::up_disc(), Some(button)),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::Up(e) = region_event {
|
if let MouseEvent::Up(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -307,11 +283,11 @@ impl HandlerSet {
|
||||||
pub fn on_click(
|
pub fn on_click(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(ClickRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseClick, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::click_disc(), Some(button)),
|
self.set.insert((MouseEvent::click_disc(), Some(button)),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::Click(e) = region_event {
|
if let MouseEvent::Click(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -325,11 +301,11 @@ impl HandlerSet {
|
||||||
pub fn on_down_out(
|
pub fn on_down_out(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DownOutRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDownOut, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::down_out_disc(), Some(button)),
|
self.set.insert((MouseEvent::down_out_disc(), Some(button)),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::DownOut(e) = region_event {
|
if let MouseEvent::DownOut(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -343,11 +319,11 @@ impl HandlerSet {
|
||||||
pub fn on_up_out(
|
pub fn on_up_out(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(UpOutRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseUpOut, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::up_out_disc(), Some(button)),
|
self.set.insert((MouseEvent::up_out_disc(), Some(button)),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::UpOut(e) = region_event {
|
if let MouseEvent::UpOut(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -361,11 +337,11 @@ impl HandlerSet {
|
||||||
pub fn on_drag(
|
pub fn on_drag(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
handler: impl Fn(DragRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseDrag, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::drag_disc(), Some(button)),
|
self.set.insert((MouseEvent::drag_disc(), Some(button)),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::Drag(e) = region_event {
|
if let MouseEvent::Drag(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -376,13 +352,10 @@ impl HandlerSet {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_hover(
|
pub fn on_hover(mut self, handler: impl Fn(MouseHover, &mut EventContext) + 'static) -> Self {
|
||||||
mut self,
|
self.set.insert((MouseEvent::hover_disc(), None),
|
||||||
handler: impl Fn(HoverRegionEvent, &mut EventContext) + 'static,
|
|
||||||
) -> Self {
|
|
||||||
self.set.insert((MouseRegionEvent::hover_disc(), None),
|
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::Hover(e) = region_event {
|
if let MouseEvent::Hover(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -395,11 +368,11 @@ impl HandlerSet {
|
||||||
|
|
||||||
pub fn on_scroll(
|
pub fn on_scroll(
|
||||||
mut self,
|
mut self,
|
||||||
handler: impl Fn(ScrollWheelRegionEvent, &mut EventContext) + 'static,
|
handler: impl Fn(MouseScrollWheel, &mut EventContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.set.insert((MouseRegionEvent::scroll_wheel_disc(), None),
|
self.set.insert((MouseEvent::scroll_wheel_disc(), None),
|
||||||
Rc::new(move |region_event, cx| {
|
Rc::new(move |region_event, cx| {
|
||||||
if let MouseRegionEvent::ScrollWheel(e) = region_event {
|
if let MouseEvent::ScrollWheel(e) = region_event {
|
||||||
handler(e, cx);
|
handler(e, cx);
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!(
|
||||||
|
|
|
@ -1,233 +0,0 @@
|
||||||
use std::{
|
|
||||||
mem::{discriminant, Discriminant},
|
|
||||||
ops::Deref,
|
|
||||||
};
|
|
||||||
|
|
||||||
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
|
||||||
|
|
||||||
use crate::{MouseButton, MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct MoveRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: MouseMovedEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for MoveRegionEvent {
|
|
||||||
type Target = MouseMovedEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct DragRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub prev_mouse_position: Vector2F,
|
|
||||||
pub platform_event: MouseMovedEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for DragRegionEvent {
|
|
||||||
type Target = MouseMovedEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct HoverRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub started: bool,
|
|
||||||
pub platform_event: MouseMovedEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for HoverRegionEvent {
|
|
||||||
type Target = MouseMovedEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct DownRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: MouseButtonEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for DownRegionEvent {
|
|
||||||
type Target = MouseButtonEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct UpRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: MouseButtonEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for UpRegionEvent {
|
|
||||||
type Target = MouseButtonEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct ClickRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: MouseButtonEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for ClickRegionEvent {
|
|
||||||
type Target = MouseButtonEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct DownOutRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: MouseButtonEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for DownOutRegionEvent {
|
|
||||||
type Target = MouseButtonEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct UpOutRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: MouseButtonEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for UpOutRegionEvent {
|
|
||||||
type Target = MouseButtonEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
|
||||||
pub struct ScrollWheelRegionEvent {
|
|
||||||
pub region: RectF,
|
|
||||||
pub platform_event: ScrollWheelEvent,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for ScrollWheelRegionEvent {
|
|
||||||
type Target = ScrollWheelEvent;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.platform_event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum MouseRegionEvent {
|
|
||||||
Move(MoveRegionEvent),
|
|
||||||
Drag(DragRegionEvent),
|
|
||||||
Hover(HoverRegionEvent),
|
|
||||||
Down(DownRegionEvent),
|
|
||||||
Up(UpRegionEvent),
|
|
||||||
Click(ClickRegionEvent),
|
|
||||||
DownOut(DownOutRegionEvent),
|
|
||||||
UpOut(UpOutRegionEvent),
|
|
||||||
ScrollWheel(ScrollWheelRegionEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MouseRegionEvent {
|
|
||||||
pub fn set_region(&mut self, region: RectF) {
|
|
||||||
match self {
|
|
||||||
MouseRegionEvent::Move(r) => r.region = region,
|
|
||||||
MouseRegionEvent::Drag(r) => r.region = region,
|
|
||||||
MouseRegionEvent::Hover(r) => r.region = region,
|
|
||||||
MouseRegionEvent::Down(r) => r.region = region,
|
|
||||||
MouseRegionEvent::Up(r) => r.region = region,
|
|
||||||
MouseRegionEvent::Click(r) => r.region = region,
|
|
||||||
MouseRegionEvent::DownOut(r) => r.region = region,
|
|
||||||
MouseRegionEvent::UpOut(r) => r.region = region,
|
|
||||||
MouseRegionEvent::ScrollWheel(r) => r.region = region,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When true, mouse event handlers must call cx.propagate_event() to bubble
|
|
||||||
/// the event to handlers they are painted on top of.
|
|
||||||
pub fn is_capturable(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
MouseRegionEvent::Move(_) => true,
|
|
||||||
MouseRegionEvent::Drag(_) => true,
|
|
||||||
MouseRegionEvent::Hover(_) => false,
|
|
||||||
MouseRegionEvent::Down(_) => true,
|
|
||||||
MouseRegionEvent::Up(_) => true,
|
|
||||||
MouseRegionEvent::Click(_) => true,
|
|
||||||
MouseRegionEvent::DownOut(_) => false,
|
|
||||||
MouseRegionEvent::UpOut(_) => false,
|
|
||||||
MouseRegionEvent::ScrollWheel(_) => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MouseRegionEvent {
|
|
||||||
pub fn move_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::Move(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn drag_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::Drag(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn hover_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::Hover(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn down_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::Down(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn up_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::Up(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn up_out_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::UpOut(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn click_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::Click(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn down_out_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::DownOut(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scroll_wheel_disc() -> Discriminant<MouseRegionEvent> {
|
|
||||||
discriminant(&MouseRegionEvent::ScrollWheel(Default::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler_key(&self) -> (Discriminant<MouseRegionEvent>, Option<MouseButton>) {
|
|
||||||
match self {
|
|
||||||
MouseRegionEvent::Move(_) => (Self::move_disc(), None),
|
|
||||||
MouseRegionEvent::Drag(e) => (Self::drag_disc(), e.pressed_button),
|
|
||||||
MouseRegionEvent::Hover(_) => (Self::hover_disc(), None),
|
|
||||||
MouseRegionEvent::Down(e) => (Self::down_disc(), Some(e.button)),
|
|
||||||
MouseRegionEvent::Up(e) => (Self::up_disc(), Some(e.button)),
|
|
||||||
MouseRegionEvent::Click(e) => (Self::click_disc(), Some(e.button)),
|
|
||||||
MouseRegionEvent::UpOut(e) => (Self::up_out_disc(), Some(e.button)),
|
|
||||||
MouseRegionEvent::DownOut(e) => (Self::down_out_disc(), Some(e.button)),
|
|
||||||
MouseRegionEvent::ScrollWheel(_) => (Self::scroll_wheel_disc(), None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -52,7 +52,7 @@ impl View for OutlineView {
|
||||||
ChildView::new(self.picker.clone(), cx).boxed()
|
ChildView::new(self.picker.clone(), cx).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.picker);
|
cx.focus(&self.picker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ impl<D: PickerDelegate> View for Picker<D> {
|
||||||
cx
|
cx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.query_editor);
|
cx.focus(&self.query_editor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl View for ProjectSymbolsView {
|
||||||
ChildView::new(self.picker.clone(), cx).boxed()
|
ChildView::new(self.picker.clone(), cx).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.picker);
|
cx.focus(&self.picker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl View for BufferSearchBar {
|
||||||
"BufferSearchBar"
|
"BufferSearchBar"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.query_editor);
|
cx.focus(&self.query_editor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ impl View for ProjectSearchView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
let handle = cx.weak_handle();
|
let handle = cx.weak_handle();
|
||||||
cx.update_global(|state: &mut ActiveSearches, cx| {
|
cx.update_global(|state: &mut ActiveSearches, cx| {
|
||||||
state
|
state
|
||||||
|
|
|
@ -6,7 +6,7 @@ use alacritty_terminal::grid::Dimensions;
|
||||||
/// with modifications for our circumstances
|
/// with modifications for our circumstances
|
||||||
use alacritty_terminal::index::{Column as GridCol, Line as GridLine, Point, Side};
|
use alacritty_terminal::index::{Column as GridCol, Line as GridLine, Point, Side};
|
||||||
use alacritty_terminal::term::TermMode;
|
use alacritty_terminal::term::TermMode;
|
||||||
use gpui::scene::ScrollWheelRegionEvent;
|
use gpui::scene::MouseScrollWheel;
|
||||||
use gpui::{geometry::vector::Vector2F, MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent};
|
use gpui::{geometry::vector::Vector2F, MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent};
|
||||||
|
|
||||||
use crate::TerminalSize;
|
use crate::TerminalSize;
|
||||||
|
@ -115,7 +115,7 @@ impl MouseButton {
|
||||||
pub fn scroll_report(
|
pub fn scroll_report(
|
||||||
point: Point,
|
point: Point,
|
||||||
scroll_lines: i32,
|
scroll_lines: i32,
|
||||||
e: &ScrollWheelRegionEvent,
|
e: &MouseScrollWheel,
|
||||||
mode: TermMode,
|
mode: TermMode,
|
||||||
) -> Option<impl Iterator<Item = Vec<u8>>> {
|
) -> Option<impl Iterator<Item = Vec<u8>>> {
|
||||||
if mode.intersects(TermMode::MOUSE_MODE) {
|
if mode.intersects(TermMode::MOUSE_MODE) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ use thiserror::Error;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
geometry::vector::{vec2f, Vector2F},
|
geometry::vector::{vec2f, Vector2F},
|
||||||
keymap::Keystroke,
|
keymap::Keystroke,
|
||||||
scene::{DownRegionEvent, DragRegionEvent, ScrollWheelRegionEvent, UpRegionEvent},
|
scene::{MouseDown, MouseDrag, MouseScrollWheel, MouseUp},
|
||||||
ClipboardItem, Entity, ModelContext, MouseButton, MouseMovedEvent, MutableAppContext, Task,
|
ClipboardItem, Entity, ModelContext, MouseButton, MouseMovedEvent, MutableAppContext, Task,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -971,7 +971,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mouse_drag(&mut self, e: DragRegionEvent, origin: Vector2F) {
|
pub fn mouse_drag(&mut self, e: MouseDrag, origin: Vector2F) {
|
||||||
let position = e.position.sub(origin);
|
let position = e.position.sub(origin);
|
||||||
self.last_mouse_position = Some(position);
|
self.last_mouse_position = Some(position);
|
||||||
|
|
||||||
|
@ -997,7 +997,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drag_line_delta(&mut self, e: DragRegionEvent) -> Option<f32> {
|
fn drag_line_delta(&mut self, e: MouseDrag) -> Option<f32> {
|
||||||
//TODO: Why do these need to be doubled? Probably the same problem that the IME has
|
//TODO: Why do these need to be doubled? Probably the same problem that the IME has
|
||||||
let top = e.region.origin_y() + (self.last_content.size.line_height * 2.);
|
let top = e.region.origin_y() + (self.last_content.size.line_height * 2.);
|
||||||
let bottom = e.region.lower_left().y() - (self.last_content.size.line_height * 2.);
|
let bottom = e.region.lower_left().y() - (self.last_content.size.line_height * 2.);
|
||||||
|
@ -1011,7 +1011,7 @@ impl Terminal {
|
||||||
Some(scroll_delta)
|
Some(scroll_delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mouse_down(&mut self, e: &DownRegionEvent, origin: Vector2F) {
|
pub fn mouse_down(&mut self, e: &MouseDown, origin: Vector2F) {
|
||||||
let position = e.position.sub(origin);
|
let position = e.position.sub(origin);
|
||||||
let point = grid_point(
|
let point = grid_point(
|
||||||
position,
|
position,
|
||||||
|
@ -1050,7 +1050,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mouse_up(&mut self, e: &UpRegionEvent, origin: Vector2F, cx: &mut ModelContext<Self>) {
|
pub fn mouse_up(&mut self, e: &MouseUp, origin: Vector2F, cx: &mut ModelContext<Self>) {
|
||||||
let settings = cx.global::<Settings>();
|
let settings = cx.global::<Settings>();
|
||||||
let copy_on_select = settings
|
let copy_on_select = settings
|
||||||
.terminal_overrides
|
.terminal_overrides
|
||||||
|
@ -1095,7 +1095,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
|
|
||||||
///Scroll the terminal
|
///Scroll the terminal
|
||||||
pub fn scroll_wheel(&mut self, e: ScrollWheelRegionEvent, origin: Vector2F) {
|
pub fn scroll_wheel(&mut self, e: MouseScrollWheel, origin: Vector2F) {
|
||||||
let mouse_mode = self.mouse_mode(e.shift);
|
let mouse_mode = self.mouse_mode(e.shift);
|
||||||
|
|
||||||
if let Some(scroll_lines) = self.determine_scroll_lines(&e, mouse_mode) {
|
if let Some(scroll_lines) = self.determine_scroll_lines(&e, mouse_mode) {
|
||||||
|
@ -1134,11 +1134,7 @@ impl Terminal {
|
||||||
self.hyperlink_from_position(self.last_mouse_position);
|
self.hyperlink_from_position(self.last_mouse_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn determine_scroll_lines(
|
fn determine_scroll_lines(&mut self, e: &MouseScrollWheel, mouse_mode: bool) -> Option<i32> {
|
||||||
&mut self,
|
|
||||||
e: &ScrollWheelRegionEvent,
|
|
||||||
mouse_mode: bool,
|
|
||||||
) -> Option<i32> {
|
|
||||||
let scroll_multiplier = if mouse_mode { 1. } else { SCROLL_MULTIPLIER };
|
let scroll_multiplier = if mouse_mode { 1. } else { SCROLL_MULTIPLIER };
|
||||||
|
|
||||||
match e.phase {
|
match e.phase {
|
||||||
|
|
|
@ -174,7 +174,7 @@ impl View for TerminalContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(self.content.handle());
|
cx.focus(self.content.handle());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,8 @@ use gpui::{
|
||||||
},
|
},
|
||||||
serde_json::json,
|
serde_json::json,
|
||||||
text_layout::{Line, RunStyle},
|
text_layout::{Line, RunStyle},
|
||||||
Element, ElementBox, Event, EventContext, FontCache, KeyDownEvent, ModelContext, MouseButton,
|
Element, ElementBox, EventContext, FontCache, ModelContext, MouseButton, MouseRegion,
|
||||||
MouseRegion, PaintContext, Quad, SizeConstraint, TextLayoutCache, WeakModelHandle,
|
PaintContext, Quad, SizeConstraint, TextLayoutCache, WeakModelHandle, WeakViewHandle,
|
||||||
WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::CursorShape;
|
use language::CursorShape;
|
||||||
|
@ -800,46 +799,6 @@ impl Element for TerminalElement {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &gpui::Event,
|
|
||||||
_bounds: gpui::geometry::rect::RectF,
|
|
||||||
_visible_bounds: gpui::geometry::rect::RectF,
|
|
||||||
_layout: &mut Self::LayoutState,
|
|
||||||
_paint: &mut Self::PaintState,
|
|
||||||
cx: &mut gpui::EventContext,
|
|
||||||
) -> bool {
|
|
||||||
if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = event {
|
|
||||||
if !cx.is_parent_view_focused() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(view) = self.view.upgrade(cx.app) {
|
|
||||||
view.update(cx.app, |view, cx| {
|
|
||||||
view.clear_bel(cx);
|
|
||||||
view.pause_cursor_blinking(cx);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
self.terminal
|
|
||||||
.upgrade(cx.app)
|
|
||||||
.map(|model_handle| {
|
|
||||||
model_handle.update(cx.app, |term, cx| {
|
|
||||||
term.try_keystroke(
|
|
||||||
keystroke,
|
|
||||||
cx.global::<Settings>()
|
|
||||||
.terminal_overrides
|
|
||||||
.option_as_meta
|
|
||||||
.unwrap_or(false),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.unwrap_or(false)
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn metadata(&self) -> Option<&dyn std::any::Any> {
|
fn metadata(&self) -> Option<&dyn std::any::Any> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,20 +332,35 @@ impl View for TerminalView {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
self.has_new_content = false;
|
self.has_new_content = false;
|
||||||
self.terminal.read(cx).focus_in();
|
self.terminal.read(cx).focus_in();
|
||||||
self.blink_cursors(self.blink_epoch, cx);
|
self.blink_cursors(self.blink_epoch, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
self.terminal.update(cx, |terminal, _| {
|
self.terminal.update(cx, |terminal, _| {
|
||||||
terminal.focus_out();
|
terminal.focus_out();
|
||||||
});
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn key_down(&mut self, event: &gpui::KeyDownEvent, cx: &mut ViewContext<Self>) -> bool {
|
||||||
|
self.clear_bel(cx);
|
||||||
|
self.pause_cursor_blinking(cx);
|
||||||
|
|
||||||
|
self.terminal.update(cx, |term, cx| {
|
||||||
|
term.try_keystroke(
|
||||||
|
&event.keystroke,
|
||||||
|
cx.global::<Settings>()
|
||||||
|
.terminal_overrides
|
||||||
|
.option_as_meta
|
||||||
|
.unwrap_or(false),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//IME stuff
|
//IME stuff
|
||||||
fn selected_text_range(&self, cx: &AppContext) -> Option<std::ops::Range<usize>> {
|
fn selected_text_range(&self, cx: &AppContext) -> Option<std::ops::Range<usize>> {
|
||||||
if self
|
if self
|
||||||
|
|
|
@ -266,7 +266,7 @@ impl View for ThemeSelector {
|
||||||
ChildView::new(self.picker.clone(), cx).boxed()
|
ChildView::new(self.picker.clone(), cx).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.picker);
|
cx.focus(&self.picker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1485,7 +1485,7 @@ impl View for Pane {
|
||||||
.named("pane")
|
.named("pane")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(active_item) = self.active_item() {
|
if let Some(active_item) = self.active_item() {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
// Pane was focused directly. We need to either focus a view inside the active item,
|
// Pane was focused directly. We need to either focus a view inside the active item,
|
||||||
|
|
|
@ -2659,7 +2659,7 @@ impl View for Workspace {
|
||||||
.named("workspace")
|
.named("workspace")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
if cx.is_self_focused() {
|
if cx.is_self_focused() {
|
||||||
cx.focus(&self.active_pane);
|
cx.focus(&self.active_pane);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue