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
+40
View File
@@ -121,6 +121,8 @@ pub struct Data {
pub flex_policy: crate::layout::FlexPolicy,
pub main_align: crate::layout::MainAlign,
pub scroll_axis: crate::scroll::Axis,
pub position: [f32; 2],
pub surface: crate::page::Surface,
pub next_slot: u64,
pub history: Vec<ObjectRef>,
pub history_index: usize,
@@ -150,6 +152,8 @@ impl Data {
flex_policy: crate::layout::FlexPolicy::default(),
main_align: crate::layout::MainAlign::Start,
scroll_axis: crate::scroll::Axis::Both,
position: [0.0, 0.0],
surface: crate::page::Surface::new(crate::page::Mode::Window),
next_slot,
history: vec![],
history_index: 0,
@@ -320,6 +324,8 @@ pub fn native_properties(data: &Data) -> Vec<(&'static str, Value)> {
Value::Number((value as f64).into())
}
let mut fields = vec![
("x", number(data.position[0])),
("y", number(data.position[1])),
("flex", number(data.flex)),
(
"flexBasis",
@@ -332,6 +338,12 @@ pub fn native_properties(data: &Data) -> Vec<(&'static str, Value)> {
("flexShrink", number(data.flex_policy.shrink)),
];
match &data.kind {
Kind::Page => fields.extend([
("mode", Value::Text(data.surface.mode.name().into())),
("panX", number(data.surface.pan.x)),
("panY", number(data.surface.pan.y)),
("zoom", number(data.surface.zoom)),
]),
Kind::Text { value, size, color } => fields.extend([
("text", Value::Text(value.clone())),
("size", Value::Number((*size as i64).into())),
@@ -393,6 +405,30 @@ pub fn apply_visual_property(data: &mut Data, name: &str, value: &Value) -> Resu
}
Ok(n)
};
if matches!(name, "x" | "y" | "panX" | "panY" | "zoom") {
let n = crate::scroll::coordinate(value)?;
match name {
"x" => data.position[0] = n,
"y" => data.position[1] = n,
"panX" if matches!(data.kind, Kind::Page) => data.surface.pan.x = n,
"panY" if matches!(data.kind, Kind::Page) => data.surface.pan.y = n,
"zoom" if matches!(data.kind, Kind::Page) => {
if !(0.1..=4.0).contains(&n) {
return Err(invalid_zoom());
}
data.surface.zoom = n;
}
_ => {}
}
return Ok(());
}
if matches!(data.kind, Kind::Page) && name == "mode" {
let Value::Text(name) = value else {
return Err(bad());
};
data.surface.mode = crate::page::Mode::parse(name)?;
return Ok(());
}
match name {
"flexBasis" => {
data.flex_policy.basis = if matches!(value, Value::Nil)
@@ -472,3 +508,7 @@ pub fn apply_visual_property(data: &mut Data, name: &str, value: &Value) -> Resu
}
Ok(())
}
fn invalid_zoom() -> VmError {
VmError::InvalidArgument("Page.zoom expects a number from 0.1 to 4")
}