81 lines
3.8 KiB
Plaintext
81 lines
3.8 KiB
Plaintext
// Tessera's start page is an ordinary Endor Page, including its layout and actions.
|
||
// This module has its own globals; creating tabs does not replace user bindings.
|
||
class StartPage: Page {
|
||
function measure(self: StartPage, mount: Mount, constraints: Constraints): MeasureResult {
|
||
return MeasureResult(constraints.maxWidth, constraints.maxHeight)
|
||
}
|
||
}
|
||
class StartRow: Row {
|
||
function measure(self: StartRow, mount: Mount, constraints: Constraints): MeasureResult {
|
||
measured = Row.measure(self, mount, constraints)
|
||
return MeasureResult(constraints.maxWidth, measured.height)
|
||
}
|
||
}
|
||
// Quiet action rows retain native hit targets and keyboard focus without card chrome.
|
||
class StartButton: Button {
|
||
function measure(self: StartButton, mount: Mount, constraints: Constraints): MeasureResult {
|
||
return MeasureResult(360, 40)
|
||
}
|
||
function paint(self: StartButton, mount: Mount, geometry: Bounds): DisplayList {
|
||
return DisplayList(ObjectList())
|
||
}
|
||
}
|
||
class StartLine: Row {
|
||
function measure(self: StartLine, mount: Mount, constraints: Constraints): MeasureResult {
|
||
measured = Row.measure(self, mount, constraints)
|
||
return MeasureResult(360, measured.height)
|
||
}
|
||
}
|
||
class StartActions {
|
||
home: Page
|
||
function blank(self: StartActions, event: Event): Unit {
|
||
page = Page()
|
||
page.title = "未命名页面"
|
||
back = Button("返回开始页")
|
||
back.onClick(self.home.activate)
|
||
page.render(Column(32, 16, TextBlock("未命名页面", 2), TextBlock("一个新的 Page 对象,已加入当前窗口。"), TextBlock("用 Endor 的 page.render(...) 组织内容。"), back))
|
||
}
|
||
function counter(self: StartActions, event: Event): Unit {
|
||
count = ui.state(0)
|
||
add = Button("增加计数")
|
||
add.onClick(count.increment)
|
||
page = Page()
|
||
page.title = "共享对象"
|
||
page.render(Column(32, 16, TextBlock("一个对象,两个视图", 2), TextBlock("点击一次,两处展示同时更新。切换标签后,状态仍然保留。"), Row(0, 32, ui.textOf(count, "value", 3), ui.textOf(count, "value", 3)), add))
|
||
}
|
||
function compose(self: StartActions, event: Event): Unit {
|
||
label = TextBlock("对象可以被多处引用")
|
||
page = Page()
|
||
page.title = "组合页面"
|
||
page.render(Column(32, 20, TextBlock("把对象组合成界面", 2), TextBlock("Column 组织纵向内容,Row 组织横向内容。"), Row(0, 16, RectBlock(100, 64, 12, "#DCE8FF"), RectBlock(100, 64, 12, "#E3ECDC"), RectBlock(100, 64, 12, "#F3E4DB")), label, Row(0, 24, label, label)))
|
||
}
|
||
}
|
||
function newTab(): Page {
|
||
page = StartPage()
|
||
page.title = "新标签页"
|
||
actions = StartActions(page)
|
||
blank = StartButton("+ 创建页面")
|
||
counter = StartButton("↗ 共享对象示例")
|
||
compose = StartButton("◇ 界面组合示例")
|
||
blank.on("click", actions.blank)
|
||
counter.on("click", actions.counter)
|
||
compose.on("click", actions.compose)
|
||
heading = StartLine(0, 0, TextBlock("Endor", 2, "#30343B"))
|
||
heading.mainAlign = "center"
|
||
subtitle = StartLine(0, 0, TextBlock("创建页面,或从一个示例开始。", 1, "#80858D"))
|
||
subtitle.mainAlign = "center"
|
||
newHint = StartLine(0, 0, TextBlock("新建标签页", 1, "#8A8F97"), TextBlock("⌘ T / Ctrl + T", 1, "#747B85"))
|
||
newHint.mainAlign = "space-between"
|
||
closeHint = StartLine(0, 0, TextBlock("关闭标签页", 1, "#8A8F97"), TextBlock("⌘ W / Ctrl + W", 1, "#747B85"))
|
||
closeHint.mainAlign = "space-between"
|
||
content = Column(0, 8,
|
||
heading, subtitle, Spacer(20),
|
||
blank, counter, compose, Spacer(20),
|
||
newHint, closeHint)
|
||
row = StartRow(24, 0, content)
|
||
row.mainAlign = "center"
|
||
page.mainAlign = "center"
|
||
page.render(row)
|
||
return page
|
||
}
|