30 lines
963 B
Plaintext
30 lines
963 B
Plaintext
class Sized: MeasureResult {}
|
|
class BaseRect: RectBlock {
|
|
function measure(self: BaseRect, mount: Mount, constraints: Constraints): MeasureResult {
|
|
return RectBlock.measure(self, mount, constraints)
|
|
}
|
|
}
|
|
class WideRect: BaseRect {
|
|
function measure(self: WideRect, mount: Object, constraints: Object): Sized {
|
|
measured = BaseRect.measure(self, mount, constraints)
|
|
return Sized(measured.width, measured.height)
|
|
}
|
|
}
|
|
class Actions {
|
|
rect: WideRect
|
|
count: Object
|
|
function widen(self: Actions): Unit {
|
|
self.rect.width = 260
|
|
self.count.increment()
|
|
}
|
|
}
|
|
rect = WideRect(180, 60, 8, "#ED6A5A")
|
|
count = ui.state(0)
|
|
actions = Actions(rect, count)
|
|
button = Button("扩大矩形")
|
|
button.onClick(actions.widen)
|
|
root = Column(24, 16, TextBlock("参数可以更宽,返回类型可以更具体", 2), rect, button, ui.textOf(count, "value"))
|
|
page = Page()
|
|
page.title = "方法覆写契约"
|
|
page.render(root)
|