feat: add page surfaces and collapsible sidebar
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
//! Camera mutations run on the owning VM worker, just like other page input.
|
||||
use super::*;
|
||||
|
||||
impl UiBridge {
|
||||
pub(super) fn dispatch_page_view(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
input: &crate::events::Input,
|
||||
) -> Result<()> {
|
||||
let (page, mut surface, viewport) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
anyhow::ensure!(
|
||||
state.published_version == input.layout_version,
|
||||
"obsolete page view"
|
||||
);
|
||||
(
|
||||
state
|
||||
.active
|
||||
.ok_or_else(|| anyhow::anyhow!("no active Page"))?,
|
||||
state.surface.clone(),
|
||||
state.layout.viewport,
|
||||
)
|
||||
};
|
||||
let delta = input
|
||||
.delta
|
||||
.ok_or_else(|| anyhow::anyhow!("page view requires delta"))?;
|
||||
if input.kind == "page-zoom" {
|
||||
anyhow::ensure!(
|
||||
surface.mode == crate::page::Mode::Canvas,
|
||||
"zoom requires canvas mode"
|
||||
);
|
||||
let pointer = input
|
||||
.point
|
||||
.ok_or_else(|| anyhow::anyhow!("zoom requires anchor"))?;
|
||||
let pointer = crate::geometry::Point::new(pointer[0], pointer[1]);
|
||||
anyhow::ensure!(
|
||||
pointer.x >= 0.0
|
||||
&& pointer.y >= 0.0
|
||||
&& viewport.is_none_or(|v| pointer.x < v.width && pointer.y < v.height),
|
||||
"zoom anchor is outside viewport"
|
||||
);
|
||||
let world = surface.to_world(pointer);
|
||||
surface.zoom = (surface.zoom * delta[0]).clamp(0.1, 4.0);
|
||||
surface.pan = crate::geometry::Point::new(
|
||||
world.x - pointer.x / surface.zoom,
|
||||
world.y - pointer.y / surface.zoom,
|
||||
);
|
||||
} else {
|
||||
surface.pan.x += delta[0] / surface.zoom;
|
||||
surface.pan.y += delta[1] / surface.zoom;
|
||||
}
|
||||
if let Some(viewport) = viewport {
|
||||
surface.clamp(viewport);
|
||||
}
|
||||
let limit = MAX_DIMENSION as f32;
|
||||
surface.pan.x = surface.pan.x.clamp(-limit, limit);
|
||||
surface.pan.y = surface.pan.y.clamp(-limit, limit);
|
||||
vm.set_attr(page, "panX", crate::native_visual::value(surface.pan.x))?;
|
||||
vm.set_attr(page, "panY", crate::native_visual::value(surface.pan.y))?;
|
||||
vm.set_attr(page, "zoom", crate::native_visual::value(surface.zoom))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user