docs: 逐模块细化中文逻辑注释并覆盖测试与示例
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// 原生视觉协议直接返回托管数据:Constraints/MeasureResult、Bounds/Arrangement 和 DisplayList 都可在源码中查询。
|
||||
// onMount 作为业务阶段收集结果;实际布局/绘制计算仍受只读规则约束。
|
||||
// 把协议探测结果保存到普通业务字段,textOf 将其中一部分显示出来。
|
||||
class VisualResults {
|
||||
width: Number
|
||||
height: Number
|
||||
@@ -5,8 +8,10 @@ class VisualResults {
|
||||
childY: Number
|
||||
color: String
|
||||
}
|
||||
// 继承原生矩形,在自身挂载后用该 Mount 显式调用 measure/paint。
|
||||
class ProbeRect: RectBlock {
|
||||
results: VisualResults
|
||||
// 有限最大宽 120 约束自然宽 200;另用自定义 Bounds 查询绘制颜色,把返回结果写进共享 results。
|
||||
function onMount(self: ProbeRect, mount: Mount): Unit {
|
||||
measured = self.measure(mount, Constraints(0, 0, 120, 80))
|
||||
self.results.width = measured.width
|
||||
@@ -15,14 +20,17 @@ class ProbeRect: RectBlock {
|
||||
self.results.color = drawing.commands.at(0).color
|
||||
}
|
||||
}
|
||||
// 在挂载回调中探测原生排列,复用当前结构的稳定子槽。
|
||||
class ProbeColumn: Column {
|
||||
results: VisualResults
|
||||
// 给定绝对起点(20,30)及容器范围,原生 padding=24 使首子项位于(44,54)。
|
||||
function onMount(self: ProbeColumn, mount: Mount): Unit {
|
||||
positions = self.arrange(mount, Bounds(20, 30, 500, 300))
|
||||
self.results.childX = positions.children.at(0).x
|
||||
self.results.childY = positions.children.at(0).y
|
||||
}
|
||||
}
|
||||
// 先创建结果容器,再将它作为源子类字段共享;root 的最后一个参数是该字段,不是视觉子项。
|
||||
results = VisualResults(0, 0, 0, 0, "等待挂载")
|
||||
rect = ProbeRect(200, 60, 12, "#DDEEFF", results)
|
||||
root = ProbeColumn(24, 16, TextBlock("对象的原生视觉协议", 2), rect, TextBlock("约束测量宽度"), ui.textOf(results, "width"), TextBlock("绘制颜色"), ui.textOf(results, "color"), results)
|
||||
|
||||
Reference in New Issue
Block a user