feat: separate 2d scenes viewports and explicit cameras

This commit is contained in:
2026-11-10 22:42:56 +08:00
parent 32d7ada3ab
commit 040b779f5f
29 changed files with 1309 additions and 70 deletions
+1
View File
@@ -2,6 +2,7 @@
| File | Purpose |
| --- | --- |
| [scene-viewports.endor](scene-viewports.endor) | One Scene2D in two CanvasViewports with independent Camera2D, a nested viewport, shared state and fixed overlay UI. |
| [box-layout.endor](box-layout.endor) | Nested Row/Column/Overlay, shared text, finite border-box sizing, margins, borders, alignment and clipping. |
| [gc-lifecycle.endor](gc-lifecycle.endor) | A Page/Block/Task/await-frame cycle: hidden retained Blocks keep running, then releasing the last references permits collection despite rendering caches. |
| [scroll-axis.endor](scroll-axis.endor) | One shared TextBlock in vertical and horizontal viewports, live axis changes and independent offsets. |
+28
View File
@@ -0,0 +1,28 @@
// The scene has world positions; each finite viewport has its own camera.
count = ui.state(0)
increment = Button("共享计数 +1")
increment.onClick(count.increment)
card = Column(20, 12, TextBlock("世界里的 UI", 2), ui.textOf(count, "value", 3), increment)
card.boxWidth = 220
card.x = -60
card.y = 40
card.borderLeft = 2
card.borderColor = "#8CA5B8"
inner = CanvasViewport(200, 100, Scene2D(RectBlock(120, 60, 8, "#D4E6D9")))
inner.x = 260
inner.y = 40
world = Scene2D(card, inner)
left = CanvasViewport(460, 320, world)
left.camera.x = -100
right = CanvasViewport(320, 320, world)
right.camera.x = -80
right.camera.zoom = 0.65
// Set right.camera = left.camera to share a view explicitly.
views = Row(0, 20, left, right)
hud = Column(16, 8, TextBlock("一个世界,多个视角", 2), TextBlock("滚轮平移 · 空格/中键拖动 · 捏合或 Cmd/Ctrl+滚轮缩放"))
hud.alignSelf = "end"
page = Page()
page.title = "场景与视口"
page.render(Overlay(12, 0, views, hud))