feat: add page surfaces and collapsible sidebar

This commit is contained in:
2026-11-10 16:18:47 +08:00
parent e0eff7755f
commit 82f9256a84
35 changed files with 1480 additions and 1751 deletions
+29 -19
View File
@@ -2,6 +2,7 @@
mod bootstrap;
mod calls;
mod developer_pages;
mod page_input;
mod signatures;
mod tree;
@@ -658,6 +659,7 @@ pub enum LayoutProgress {
}
struct LayoutContext {
surface: crate::page::Surface,
root: Arc<UiNode>,
tabs: Vec<crate::tabs::Tab>,
full_viewport: Option<crate::layout::Size>,
@@ -1189,13 +1191,16 @@ impl UiBridge {
vm.release_value(page)?;
return Ok(());
}
if matches!(input.kind.as_str(), "page-pan" | "page-zoom") {
return self.dispatch_page_view(vm, input);
}
if matches!(
input.kind.as_str(),
"tab-activate" | "tab-close" | "tab-detach" | "tab-drop"
) {
return self.dispatch_tab(vm, input);
}
let (weak, desktop, candidates, viewport) = {
let (weak, desktop, candidates, viewport, surface) = {
let state = self
.session
.lock()
@@ -1211,13 +1216,8 @@ impl UiBridge {
.ok_or_else(|| anyhow::anyhow!("Mount is no longer active"))?,
state.desktop,
state.mounts.ordered(),
state.layout.viewport.map(|size| crate::layout::Size {
width: (size.width - crate::tabs::RAIL - crate::tabs::INSET).max(0.0),
height: (size.height
- crate::tabs::INSET
- crate::tabs::height(&state.last_tabs))
.max(0.0),
}),
state.layout.viewport,
state.surface.clone(),
)
};
if input.kind == "scroll" {
@@ -1231,8 +1231,7 @@ impl UiBridge {
.ok_or_else(|| anyhow::anyhow!("scroll has no pointer"))?;
if !data.mounted
|| data.version != input.layout_version
|| viewport
.is_some_and(|size| point[0] >= size.width || point[1] >= size.height)
|| !surface.contains(point, viewport)
|| !data
.geometry
.contains(crate::geometry::Point::new(point[0], point[1]))
@@ -1265,11 +1264,10 @@ impl UiBridge {
return result;
}
let mount = if let (Some(press), Some(release)) = (input.press_point, input.point) {
if viewport.is_some_and(|size| {
[press, release]
.iter()
.any(|point| point[0] >= size.width || point[1] >= size.height)
}) {
if [press, release]
.iter()
.any(|point| !surface.contains(*point, viewport))
{
return Ok(());
}
let Some(mount) = crate::source_hit::resolve(vm, desktop, candidates, press, release)?
@@ -1477,6 +1475,7 @@ impl UiBridge {
state.force_frame = false;
state.last_snapshot = snapshot;
state.last_tabs = frame.tabs.clone();
state.surface = frame.surface.clone();
state.published_version = frame.layout_version;
// Hooks may call Page/container APIs; never hold the session mutex
// across user code. Publish only after the refresh loop settles.
@@ -1649,10 +1648,8 @@ impl UiBridge {
project_tabs(vm, &mut state)?
};
let full_viewport = layout.viewport;
if let Some(size) = &mut layout.viewport {
size.width = (size.width - crate::tabs::RAIL - crate::tabs::INSET).max(0.0);
size.height = (size.height - crate::tabs::height(&tabs) - crate::tabs::INSET).max(0.0);
}
let surface = root.surface.clone().unwrap_or_default();
layout.page_mode = root.surface.as_ref().map(|surface| surface.mode);
{
let state = self
.session
@@ -1688,6 +1685,7 @@ impl UiBridge {
(hooks, state.mounts.ordered(), checkpoint)
};
let context = LayoutContext {
surface,
root: root.clone(),
tabs,
full_viewport,
@@ -1736,6 +1734,7 @@ impl UiBridge {
fn discard_layout_context(&self, vm: &mut Vm, context: LayoutContext) -> Result<()> {
let LayoutContext {
surface: _,
desktop,
window,
hooks,
@@ -1824,6 +1823,7 @@ impl UiBridge {
draft: crate::source_layout::Draft,
) -> Result<crate::document::Frame> {
let LayoutContext {
mut surface,
root,
tabs,
full_viewport,
@@ -1851,6 +1851,16 @@ impl UiBridge {
// after either layout path has produced the final page geometry.
frame.tabs = tabs;
frame.window = window;
if let Some(root) = frame.mounts.first() {
surface.extent = crate::layout::Size {
width: root.width,
height: root.height,
};
}
if let Some(viewport) = full_viewport {
surface.clamp(viewport);
}
frame.surface = surface;
// Capture versions before lifecycle hooks can change a dependency.
let desktops = self
.session