Files
2026-10-21 14:20:02 +08:00

37 lines
1.3 KiB
Plaintext

class TintRect: RectBlock {
tint: String
function paint(self: TintRect, mount: Mount, geometry: Bounds): DisplayList {
drawing = RectBlock.paint(self, mount, geometry)
drawing.commands.at(0).color = self.tint
return drawing
}
}
class Badge: TextBlock {
background: String
function paint(self: Badge, mount: Mount, geometry: Bounds): DisplayList {
fill = PaintCommand()
fill.kind = "roundedRect"
fill.x = geometry.x
fill.y = geometry.y
fill.width = geometry.width
fill.height = geometry.height
fill.radius = 6
fill.color = self.background
text = TextBlock.paint(self, mount, geometry).commands.at(0)
text.color = "#FFFFFF"
return DisplayList(ObjectList(fill, text))
}
}
class RecolorButton: Button {
target: TintRect
function onEvent(self: RecolorButton, event: Event): Unit {
self.target.tint = "#526AC7"
}
}
rect = TintRect(200, 60, 12, "#DDEEFF", "#ED6A5A")
badge = Badge("Endor 源码正在绘制这个背景", 2, "#237A45")
button = RecolorButton("通过对象方法改变绘制颜色", rect)
root = Column(24, 16, TextBlock("源码 paint 进入真实窗口", 2), rect, rect, badge, button)
page = Page()
page.render(root)