module Tessell::Layout

Defined in:

tessell/layout.cr

Constant Summary

MEASURE_SLOTS = 8

Class Method Summary

Class Method Detail

def self.arrange(node : LayoutNode, rect : Rect, measurer : Text::Measurer | Nil = nil) : LayoutBox #

---------- Pass B : arrange ----------


[View source]
def self.arrange_cached(node : CachedNode, rect : Rect, measurer : Text::Measurer | Nil = nil) : LayoutBox #

增量 arrange:子尺寸全部命中节点缓存,不触发 measurer。


[View source]
def self.build_cached(node : LayoutNode) : CachedNode #

从纯函数 LayoutNode 树构建增量树。


[View source]
def self.float_eq(a : Float32, b : Float32) : Bool #

[View source]
def self.key_eq(a : Tuple(Float32, Float32, Float32, Float32), b : Tuple(Float32, Float32, Float32, Float32)) : Bool #

键相等:NaN 视为相等(asuka 口径);INFINITY == INFINITY 原生成立。


[View source]
def self.mark_dirty(node : CachedNode) : Int32 #

MarkDirty 父链早停:返回本次新标脏的节点数。祖先已脏即止—— 第二次标同一叶子返回 0(断言用)。


[View source]
def self.measure(node : LayoutNode, constraints : Constraints, measurer : Text::Measurer | Nil = nil) : Size #

---------- Pass A : measure ----------


[View source]
def self.measure_cached(node : CachedNode, constraints : Constraints, measurer : Text::Measurer | Nil = nil) : Size #

增量 measure:环形缓冲命中即返回(零测量);未命中才下沉计算。


[View source]
def self.semantically_same?(a : LayoutNode, b : LayoutNode) : Bool #

布局语义相等(issue #58 单一真相,CachedNode#update 与 replay oracle 共用):id/尺寸/padding/margin/方向/gap/text/子树递归;measured 等缓存 槽不属于语义。


[View source]
def self.solve(node : LayoutNode, constraints : Constraints, origin : Point = Point.new, measurer : Text::Measurer | Nil = nil) : LayoutBox #

便捷入口:measure → constrain → arrange。


[View source]
def self.solve_cached(root : CachedNode, constraints : Constraints, origin : Point = Point.new, measurer : Text::Measurer | Nil = nil) : NamedTuple(box: LayoutBox, changed: Array(String)) #

增量 solve:根 final 单槽命中(未脏且键相同)时返回上帧 box + 空变更, 一次测量都不进;否则增量 measure/arrange,并对比帧间 per-id rect 上报变更。 返回 NamedTuple(box, changed):changed 是 rect 真变的节点 id(对接脏矩形)。


[View source]