Add per-Mount scrolling with shared paint and input clipping
Verify Tessera GUI / verify (push) Failing after 7m33s
Verify Tessera GUI / verify (push) Failing after 7m33s
This commit is contained in:
+57
-5
@@ -136,6 +136,14 @@ impl RenderDocument {
|
||||
bail!("invalid window identity");
|
||||
}
|
||||
parse_color(&self.frame.background)?;
|
||||
if !self.frame.command_clips.is_empty()
|
||||
&& self.frame.command_clips.len() != self.frame.commands.len()
|
||||
{
|
||||
bail!("invalid command clip table");
|
||||
}
|
||||
for clip in self.frame.command_clips.iter().flatten() {
|
||||
validate_rect(clip[0], clip[1], clip[2], clip[3], 0.0)?;
|
||||
}
|
||||
for command in &self.frame.commands {
|
||||
command.validate()?;
|
||||
}
|
||||
@@ -159,6 +167,17 @@ impl RenderDocument {
|
||||
bail!("invalid or duplicate mount identity");
|
||||
}
|
||||
validate_rect(mount.x, mount.y, mount.width, mount.height, 0.0)?;
|
||||
if let Some(clip) = mount.clip {
|
||||
validate_rect(clip[0], clip[1], clip[2], clip[3], 0.0)?;
|
||||
}
|
||||
if let Some(scroll) = mount.scroll
|
||||
&& (!scroll.iter().all(|n| {
|
||||
n.is_finite() && (0.0..=crate::ui_bridge::MAX_DIMENSION as f32).contains(n)
|
||||
}) || scroll[0] > scroll[2]
|
||||
|| scroll[1] > scroll[3])
|
||||
{
|
||||
bail!("invalid scroll projection");
|
||||
}
|
||||
}
|
||||
for mount in &self.frame.mounts {
|
||||
for linked in [mount.parent, mount.first_child, mount.next_sibling]
|
||||
@@ -191,13 +210,27 @@ impl RenderDocument {
|
||||
let frame = &self.frame;
|
||||
let mut list = DisplayList::default();
|
||||
list.push(DrawCommand::Clear(parse_color(&frame.background)?));
|
||||
for command in &frame.commands {
|
||||
for (index, command) in frame.commands.iter().enumerate() {
|
||||
let clip = frame.command_clips.get(index).copied().flatten();
|
||||
if let Some(clip) = clip {
|
||||
list.push(DrawCommand::PushClip(scaled_rect(
|
||||
clip[0], clip[1], clip[2], clip[3], scale,
|
||||
)));
|
||||
}
|
||||
list.push(command.to_draw_command(scale)?);
|
||||
if clip.is_some() {
|
||||
list.push(DrawCommand::PopClip);
|
||||
}
|
||||
}
|
||||
if let Some(focus) = frame
|
||||
.focus
|
||||
.and_then(|id| frame.mounts.iter().find(|m| m.id == id))
|
||||
{
|
||||
if let Some(c) = focus.clip {
|
||||
list.push(DrawCommand::PushClip(scaled_rect(
|
||||
c[0], c[1], c[2], c[3], scale,
|
||||
)));
|
||||
}
|
||||
list.push(
|
||||
RenderCommand::StrokeRoundedRect {
|
||||
x: focus.x,
|
||||
@@ -210,6 +243,9 @@ impl RenderDocument {
|
||||
}
|
||||
.to_draw_command(scale)?,
|
||||
);
|
||||
if focus.clip.is_some() {
|
||||
list.push(DrawCommand::PopClip);
|
||||
}
|
||||
}
|
||||
if let Some(error) = &frame.fault {
|
||||
list.push(
|
||||
@@ -292,6 +328,8 @@ pub struct Frame {
|
||||
#[serde(default)]
|
||||
pub commands: Vec<RenderCommand>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub command_clips: Vec<Option<[f32; 4]>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub mounts: Vec<MountGeometry>,
|
||||
#[serde(default)]
|
||||
pub layout_version: u64,
|
||||
@@ -311,6 +349,7 @@ impl Default for Frame {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
background: default_background(),
|
||||
commands: Vec::new(),
|
||||
command_clips: Vec::new(),
|
||||
mounts: Vec::new(),
|
||||
layout_version: 0,
|
||||
session: 0,
|
||||
@@ -324,6 +363,10 @@ impl Default for Frame {
|
||||
/// A position in a published frame. Identifiers are opaque data, never VM handles.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct MountGeometry {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub clip: Option<[f32; 4]>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub scroll: Option<[f32; 4]>,
|
||||
pub id: u64,
|
||||
pub block_id: String,
|
||||
pub parent: Option<u64>,
|
||||
@@ -336,15 +379,24 @@ pub struct MountGeometry {
|
||||
pub interactive: bool,
|
||||
}
|
||||
|
||||
impl MountGeometry {
|
||||
pub fn contains(&self, point: Point) -> bool {
|
||||
Rect::new(self.x, self.y, self.width, self.height).contains(point)
|
||||
&& self.clip.is_none_or(|c| {
|
||||
c[2] > 0.0 && c[3] > 0.0 && Rect::new(c[0], c[1], c[2], c[3]).contains(point)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
self.mounts
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|mount| mount.interactive && mount.contains(point))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user