docs: clarify example inheritance and type contract calls
This commit is contained in:
@@ -6,6 +6,7 @@ class Sized: MeasureResult {}
|
||||
class BaseRect: RectBlock {
|
||||
// 原生方法按给定出现位置与约束测量,不把几何存进共享对象。
|
||||
function measure(self: BaseRect, mount: Mount, constraints: Constraints): MeasureResult {
|
||||
// 由 WideRect.measure 显式调用此实现,再委托 RectBlock 原生测量;传递的仍是当前出现与当前约束。
|
||||
return RectBlock.measure(self, mount, constraints)
|
||||
}
|
||||
}
|
||||
@@ -13,7 +14,9 @@ class BaseRect: RectBlock {
|
||||
class WideRect: BaseRect {
|
||||
// 调用基类后复制测量数值到新的 Sized;新结果仍满足 MeasureResult 协议。
|
||||
function measure(self: WideRect, mount: Object, constraints: Object): Sized {
|
||||
// 宿主布局驱动仍传入 Mount/Constraints;Object 注解只放宽覆盖签名,不改变实际输入对象。
|
||||
measured = BaseRect.measure(self, mount, constraints)
|
||||
// 拷贝的是本轮测量结果的两个数值,不复制业务矩形或 Mount;返回新结果供宿主校验。
|
||||
return Sized(measured.width, measured.height)
|
||||
}
|
||||
}
|
||||
@@ -23,6 +26,7 @@ class Actions {
|
||||
count: Object
|
||||
// 先改 width 再递增计数,新的布局刷新会使用上述动态测量覆盖。
|
||||
function widen(self: Actions): Unit {
|
||||
// Button.onClick 调用零参绑定方法;width 写入令依赖该原生尺寸的测量失效,count 驱动另一文字绑定。
|
||||
self.rect.width = 260
|
||||
self.count.increment()
|
||||
}
|
||||
@@ -31,6 +35,7 @@ class Actions {
|
||||
rect = WideRect(180, 60, 8, "#ED6A5A")
|
||||
count = ui.state(0)
|
||||
actions = Actions(rect, count)
|
||||
// 所有点击都操作同一个 rect/count;重复设 width=260 不继续增加宽度,但 increment 每次都会增加计数。
|
||||
button = Button("扩大矩形")
|
||||
button.onClick(actions.widen)
|
||||
root = Column(24, 16, TextBlock("参数可以更宽,返回类型可以更具体", 2), rect, button, ui.textOf(count, "value"))
|
||||
|
||||
Reference in New Issue
Block a user