Files
endorphin-tessera-gui/examples/tab-placement.endor
T

56 lines
2.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 页面位置与子项插入的代码示例:Page 方法覆盖计数,Container.insert 在指定位置创建稳定子槽。
// 当前侧栏提供选择/关闭,文案中的拖放场景也可经版本化事件 API 测试;不要把它理解成已实现的侧栏拖动手势。
// 继承 Page 后观察 moveToWindow/moveTab 的真实方法调用,保留原生迁移/重排行为。
class TrackedPage: Page {
calls: Object
// 先递增 calls,再显式调用基类执行跨窗迁移;Page 身份保留,旧 Mount 上下文会替换。
function moveToWindow(self: TrackedPage, window: Window): Page {
self.calls.increment()
return Page.moveToWindow(self, window)
}
// position 是所属窗口内最终零基位置,重排不等于创建新的业务 Page。
function moveTab(self: TrackedPage, position: Number): Page {
self.calls.increment()
return Page.moveTab(self, position)
}
}
// 保存容器业务对象,按钮插入只改变其子槽顺序,已有 child 的槽与 Mount 尽量保留。
class Actions {
list: Column
// 在索引 1 前插入新 TextBlock,返回的稳定槽可供 remove 等后续操作使用。
function insert(self: Actions, event: Event): Unit {
self.list.insert(1, TextBlock("插入的新对象"))
}
}
calls = ui.state(0)
list = Column(0, 8, TextBlock("第一个子项"), TextBlock("最后一个子项"))
actions = Actions(list)
button = Button("在位置 1 插入 Block")
connection = button.on("click", actions.insert)
// A/C/目标页共享同一根及 list;各页激活时使用独立展示上下文,业务插入结果共享。
shared = Column(24, 16, TextBlock("拖动 Tab 重排、移入另一个窗口,或拖出独立窗口"), TextBlock("Page 方法调用次数"), ui.textOf(calls,"value"), button, list)
first = TrackedPage(calls)
first.title = "A · 共享内容"
first.render(shared)
second = TrackedPage(calls)
second.title = "B · 单独内容"
second.render(Column(24, 16, TextBlock("这是 B,Page 身份随 Tab 移动保留")))
third = TrackedPage(calls)
third.title = "C · 同一对象"
third.render(shared)
// 建立目标窗口并指定桌面位置,MoveTo 使用物理桌面坐标且可能受窗口管理器调整。
other = Window()
other.resize(720,520)
other.setTitle("Tab Target")
other.moveTo(1700,80)
target = TrackedPage(calls)
target.title = "目标窗口"
target.render(shared)
target.open(other)
// 恢复源窗口首个页面,最后排出 resize/title/move/focus,便于手动或 API 验证。
first.activate()
ui.window().resize(800,600)
ui.window().setTitle("Tab Source")
ui.window().moveTo(50,80)
ui.window().focus()