mocking out cursor event interop
This commit is contained in:
@@ -17,3 +17,15 @@ pub(self) use history::*;
|
||||
pub use layout::*;
|
||||
pub use state::*;
|
||||
pub use storage::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn make_element(app: &mut gpui::App) -> impl gpui::IntoElement {
|
||||
use gpui::AppContext;
|
||||
let state = app.new(|cx| InputState::new(cx));
|
||||
let cursor = app.new(|cx| {
|
||||
let mut cursor = Cursor::new(None);
|
||||
cursor.subscribe_to(&state, cx);
|
||||
cursor
|
||||
});
|
||||
input(&state, app).cursor(cursor)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
use gpui::{Bounds, Context, Element, Hsla, IntoElement, Pixels, Point, Render};
|
||||
use gpui::{
|
||||
Bounds, Context, Element, Entity, EventEmitter, Hsla, IntoElement, Pixels, Point, Render,
|
||||
Subscription,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::input::CursorTrigger;
|
||||
|
||||
/// Default interval for cursor blinking.
|
||||
pub const DEFAULT_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||
|
||||
@@ -17,6 +23,8 @@ pub struct Cursor {
|
||||
was_focused: bool,
|
||||
point: Point<Pixels>,
|
||||
height: Pixels,
|
||||
#[allow(dead_code)]
|
||||
subscriptions: SmallVec<[Subscription; 2]>,
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
@@ -33,6 +41,7 @@ impl Cursor {
|
||||
was_focused: false,
|
||||
point: Point::default(),
|
||||
height: Pixels::ZERO,
|
||||
subscriptions: SmallVec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +50,19 @@ impl Cursor {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn subscribe_to<E>(&mut self, emitter: &Entity<E>, cx: &mut Context<Self>)
|
||||
where
|
||||
E: EventEmitter<CursorTrigger>,
|
||||
{
|
||||
let handle = cx.subscribe(emitter, |cursor, _emitter, event, cx| match event {
|
||||
CursorTrigger::PauseBlinkingForUserAction => {
|
||||
cursor.pause_blinking(cx);
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
self.subscriptions.push(handle);
|
||||
}
|
||||
|
||||
/// Returns whether the cursor should currently be rendered.
|
||||
pub fn visible(&self) -> bool {
|
||||
self.visible
|
||||
|
||||
Reference in New Issue
Block a user