feat: retain managed visual objects and dispatch native input through Endor
Verify Tessera GUI / verify (push) Successful in 9m28s

This commit is contained in:
2026-10-21 01:49:35 +08:00
parent 757fa22d9b
commit 0d5e4b318d
21 changed files with 3295 additions and 892 deletions
+112 -6
View File
@@ -89,7 +89,36 @@ impl RenderDocument {
for command in &self.frame.commands {
command.validate()?;
}
if self.frame.mounts.len() > 10_000 {
bail!("frame exceeds the 10000 mount limit");
}
let mut mount_ids = HashSet::new();
for mount in &self.frame.mounts {
if mount.id == 0 || mount.block_id.is_empty() || !mount_ids.insert(mount.id) {
bail!("invalid or duplicate mount identity");
}
validate_rect(mount.x, mount.y, mount.width, mount.height, 0.0)?;
}
for mount in &self.frame.mounts {
for linked in [mount.parent, mount.first_child, mount.next_sibling]
.into_iter()
.flatten()
{
if !mount_ids.contains(&linked) {
bail!("mount links outside this frame");
}
}
}
if let Some(root) = &self.ui_root
&& self
.frame
.mounts
.first()
.is_none_or(|mount| mount.block_id != root.block_id)
{
bail!("frame root does not match its visual projection");
}
let mut ids = HashSet::new();
if let Some(root) = &self.root {
root.validate(0, &mut ids)?;
@@ -98,17 +127,52 @@ impl RenderDocument {
}
pub fn display_list(&self, scale: f32) -> Result<DisplayList> {
let relayout = self
.ui_root
.as_deref()
.map(crate::layout::frame)
.transpose()?;
let frame = relayout.as_ref().unwrap_or(&self.frame);
let frame = &self.frame;
let mut list = DisplayList::default();
list.push(DrawCommand::Clear(parse_color(&frame.background)?));
for command in &frame.commands {
list.push(command.to_draw_command(scale)?);
}
if let Some(focus) = frame
.focus
.and_then(|id| frame.mounts.iter().find(|m| m.id == id))
{
list.push(
RenderCommand::StrokeRoundedRect {
x: focus.x,
y: focus.y,
width: focus.width,
height: focus.height,
radius: 7.0,
stroke_width: 2.0,
color: "#4F6FDB".into(),
}
.to_draw_command(scale)?,
);
}
if let Some(error) = &frame.fault {
list.push(
RenderCommand::RoundedRect {
x: 0.0,
y: 0.0,
width: 10000.0,
height: 36.0,
radius: 0.0,
color: "#FFF1EF".into(),
}
.to_draw_command(scale)?,
);
list.push(
RenderCommand::Text {
x: 12.0,
y: 8.0,
value: format!("运行已停止:{error}"),
size: 1,
color: "#A32D25".into(),
}
.to_draw_command(scale)?,
);
}
Ok(list)
}
@@ -164,6 +228,16 @@ pub struct Frame {
pub background: String,
#[serde(default)]
pub commands: Vec<RenderCommand>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub mounts: Vec<MountGeometry>,
#[serde(default)]
pub layout_version: u64,
#[serde(default)]
pub session: u64,
#[serde(default)]
pub focus: Option<u64>,
#[serde(default)]
pub fault: Option<String>,
}
impl Default for Frame {
@@ -171,10 +245,42 @@ impl Default for Frame {
Self {
background: default_background(),
commands: Vec::new(),
mounts: Vec::new(),
layout_version: 0,
session: 0,
focus: None,
fault: None,
}
}
}
/// A position in a published frame. Identifiers are opaque data, never VM handles.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct MountGeometry {
pub id: u64,
pub block_id: String,
pub parent: Option<u64>,
pub first_child: Option<u64>,
pub next_sibling: Option<u64>,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub interactive: bool,
}
impl Frame {
pub fn hit_test(&self, point: Point) -> Option<&MountGeometry> {
if self.fault.is_some() {
return None;
}
self.mounts.iter().rev().find(|mount| {
mount.interactive
&& Rect::new(mount.x, mount.y, mount.width, mount.height).contains(point)
})
}
}
fn default_background() -> String {
"#F7F7F5".to_owned()
}