26 lines
1.5 KiB
Plaintext
26 lines
1.5 KiB
Plaintext
// 两个原生窗口共用一个 Aster VM 和 count 业务对象,各自拥有独立 Page 与 Mount。
|
|
// 任一窗口点击都修改同一计数,两个 textOf 显示随之更新。关闭窗口解除 Page 归属,持有的业务对象仍可重开。
|
|
// 跨窗共享的是业务对象,不是某个窗口中的具体 Mount。
|
|
// 唯一计数来源;两个按钮直接使用同一零参数原生 increment 方法。
|
|
count = ui.state(0)
|
|
leftButton = Button("共享计数 +1")
|
|
leftConnection = leftButton.on("click",count.increment)
|
|
// 先在主窗口建立页面,render 默认选择该页并挂载它的内容。
|
|
left = Page()
|
|
left.title = "主窗口页面"
|
|
left.render(Column(24,16,TextBlock("两个窗口操作同一个计数对象"),ui.textOf(count,"value"),leftButton))
|
|
|
|
// Window() 分配同 VM 中的独立窗口资源,不创建第二个运行时。
|
|
other = Window()
|
|
rightButton = Button("另一个窗口 +1")
|
|
rightConnection = rightButton.on("click",count.increment)
|
|
right = Page()
|
|
right.title = "独立窗口页面"
|
|
right.render(Column(24,16,TextBlock("关闭窗口会解除 Page 归属,保留的对象仍可重开"),ui.textOf(count,"value"),rightButton))
|
|
// 把页面放到 other,上下文更换将重建出现位置,业务 count 仍不变。
|
|
right.open(other)
|
|
// 窗口命令针对各自资源编号排队;成功输入后再交 GUI,另一窗口设置自己的尺寸。
|
|
ui.window().setTitle("Endor Main")
|
|
other.setTitle("Endor Shared")
|
|
other.resize(960,640)
|