feat: render interactive manuscript from Endor through generic graphics

This commit is contained in:
2026-11-12 10:52:28 +08:00
parent d29a1be329
commit 2715c1ce2c
71 changed files with 3000 additions and 78 deletions
+67 -1
View File
@@ -63,6 +63,8 @@ pub struct TesseraApp {
activity: Activity,
event_client: crate::events::Client,
guest_pressed: Option<crate::events::Input>,
pointer_hover: Option<crate::events::Input>,
pointer_capture: Option<crate::events::Input>,
guest_focus: Option<crate::events::Input>,
guest_key: Option<(NamedKey, crate::events::Input)>,
guest_keyboard: bool,
@@ -76,7 +78,8 @@ impl TesseraApp {
proxy: EventLoopProxy<AppEvent>,
control: crate::api::RuntimeControl,
) -> anyhow::Result<Self> {
let event_client = crate::events::Client::new(proxy.clone(), namespace.clone())?;
let event_client =
crate::events::Client::new(proxy.clone(), namespace.clone(), control.clone())?;
Ok(Self::with_event_client(
namespace,
activity,
@@ -120,6 +123,8 @@ impl TesseraApp {
activity,
event_client,
guest_pressed: None,
pointer_hover: None,
pointer_capture: None,
guest_focus: None,
guest_key: None,
guest_keyboard: true,
@@ -558,6 +563,54 @@ impl TesseraApp {
})
}
/// Pointer subscriptions explicitly opt a Mount into continuous input.
/// Capture retains window/session/Mount; the worker validates it again.
fn pointer_target(&self) -> Option<crate::events::Input> {
let mut input = self.guest_hit()?;
let current = self.namespace.read().ok()?;
let frame = &current.document.frame;
let mut mount = frame.mounts.iter().find(|m| m.id == input.mount)?;
while !mount.pointer_events {
mount = frame.mounts.iter().find(|m| Some(m.id) == mount.parent)?;
}
input.mount = mount.id;
input.press_point = None;
Some(input)
}
fn emit_pointer(&self, mut input: crate::events::Input, kind: &str) {
input.kind = kind.into();
input.press_point = None;
if let Some(p) = self.guest_point() {
input.point = Some([p.x, p.y]);
}
self.event_client.send(input);
}
fn cancel_pointer(&mut self) {
if let Some(input) = self.pointer_capture.take() {
self.emit_pointer(input, "pointercancel");
}
if let Some(input) = self.pointer_hover.take() {
self.emit_pointer(input, "pointerleave");
}
}
fn move_pointer(&mut self) {
if let Some(input) = self.pointer_capture.clone() {
self.emit_pointer(input, "pointermove");
return;
}
let next = self.pointer_target();
if self.pointer_hover.as_ref().map(|i| (i.session, i.mount))
!= next.as_ref().map(|i| (i.session, i.mount))
&& let Some(old) = self.pointer_hover.take()
{
self.emit_pointer(old, "pointerleave");
}
if let Some(input) = next.clone() {
self.emit_pointer(input, "pointermove");
}
self.pointer_hover = next;
}
/// 将标签快捷键转换为当前窗口/帧中的明确页面动作。
fn send_tab_shortcut(&mut self, close: bool) -> bool {
let input = self.namespace.read().ok().and_then(|namespace| {
@@ -1152,6 +1205,7 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
window.request_redraw();
return;
}
self.move_pointer();
self.developer_tools.move_pointer(
next,
delta,
@@ -1175,6 +1229,7 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
window.request_redraw();
}
WindowEvent::CursorLeft { .. } => {
self.cancel_pointer();
self.guest_pressed = None;
self.panning = false;
self.sidebar.interaction.pointer_left();
@@ -1197,6 +1252,16 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
button: MouseButton::Left,
..
} => {
if state == ElementState::Pressed {
if let Some(input) = self.pointer_target() {
self.pointer_capture = Some(input.clone());
self.emit_pointer(input, "pointerdown");
return;
}
} else if let Some(input) = self.pointer_capture.take() {
self.emit_pointer(input, "pointerup");
return;
}
if state == ElementState::Pressed {
if self.sidebar.covers(self.pointer) {
self.sidebar_keyboard = true;
@@ -1354,6 +1419,7 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
window.request_redraw();
}
WindowEvent::Focused(false) => {
self.cancel_pointer();
self.guest_pressed = None;
self.guest_key = None;
self.developer_tools.blur();