class Tessell::Kit::Context

Defined in:

tessell/kit/context.cr

Constant Summary

MEASURE_CACHE_CAP = 4096

文本测量缓存(issue #6/#24/#29):两代淘汰的有界缓存, 键 (text, font_id, size, max_width)。 正确性不依赖任何人清空——键含文本内容,内容变化天然产生新键; clear_text_cache 是表格/行情这类高频换文本集合应用的内存卫生措施 (整体数据快照替换后调用一次即可,不必每帧)。容量有界:cur 代满 MEASURE_CACHE_CAP 条时整体换代(old=cur,cur 重建),old 命中会提升回 cur。

Constructors

Instance Method Summary

Constructor Detail

def self.new(theme : Theme = Theme.light, metrics : TextMetrics = StubTextMetrics.new, scale : Float32 = 1.0_f32, now_ms : Int64 = 0_i64) #

[View source]

Instance Method Detail

def advance_time(now_ms : Int64) : Nil #

[View source]
def clear_text_cache : Nil #

[View source]
def device_font_size(size : Float32) : Float32 #

DPI 只影响文本设备字号;逻辑布局尺寸仍由 Metrics 给出。


[View source]
def font_id_for(text : String, weight : FontWeight) : Int32 #

FontWeight → font_id(issue #29):按栈内字重匹配的覆盖脸;无栈或 无覆盖返回 0(默认 face)。


[View source]
def font_stack : Tessell::Text::FontStack | Nil #

多 face 字体栈(issue #29):nil = 单 face。设置后组件的 FontWeight 经 font_id_for 解析为 face 的 font_id,一路传到 Painter。


[View source]
def font_stack=(font_stack : Tessell::Text::FontStack | Nil) #

多 face 字体栈(issue #29):nil = 单 face。设置后组件的 FontWeight 经 font_id_for 解析为 face 的 font_id,一路传到 Painter。


[View source]
def line_height(size : Float32) : Float32 #

[View source]
def measure_text(text : String, size : Float32, max_width : Float32, font_id : Int32) : Size #

[View source]
def measure_text(text : String, size : Float32, font_id : Int32) : Size #

face 维度测量(issue #29):font_id = 0 表示默认 face。


[View source]
def measure_text(text : String, size : Float32, max_width : Float32) : Size #

[View source]
def measure_text(text : String, size : Float32) : Size #

逻辑单位契约(issue #14):以设备字号测量(与 Painter 提交的实际 字形尺寸一致),再除回 scale 返回逻辑尺寸。组件在 scale=1 与 scale=2 下得到相同逻辑 bounds,宿主无须自写除法适配器。


[View source]
def metrics : TextMetrics #

[View source]
def now_ms : Int64 #

[View source]
def overlay_host : OverlayHost | Nil #

[View source]
def overlay_host=(overlay_host : OverlayHost | Nil) #

[View source]
def render_theme : Tessell::Render::Theme #

核心 Render::Theme 镜像(issue #8):Kit Palette 覆盖组件语义, 行情/网格/涨跌等扩展 token(panel/grid/up/down 等)从这里读, 应用不再自建平行 Palette。


[View source]
def scale : Float32 #

[View source]
def scale=(value : Float32) : Nil #

DPI/缩放变更(issue #30):scale 与文本测量缓存联动。缓存的测量值 是设备像素口径,对旧 scale 全部失效——改 scale 与清缓存在同一个 入口里完成,避免调用方漏清导致旧值漂移。


[View source]
def supports_external_texture : Bool #

后端是否支持外部纹理通道(issue #45):内置 Software/GL 后端均为 true;宿主自建不支持纹理的后端时置 false——Kit::Image 据此跳过 绘制(a11y 仍报 Role::Image),消除"静默空白"。


[View source]
def supports_external_texture=(supports_external_texture : Bool) #

后端是否支持外部纹理通道(issue #45):内置 Software/GL 后端均为 true;宿主自建不支持纹理的后端时置 false——Kit::Image 据此跳过 绘制(a11y 仍报 Role::Image),消除"静默空白"。


[View source]
def text_cache_hits : Int32 #

缓存观测面(issue #24):应用据此判断是否需要 clear_text_cache。


[View source]
def text_cache_misses : Int32 #

[View source]
def text_cache_size : Int32 #

[View source]
def text_cache_stats : NamedTuple(hits: Int32, misses: Int32, size: Int32) #

与 CachingMeasurer#stats 同风格的汇总读数。


[View source]
def text_metrics(size : Float32) : Tessell::Text::FontMetrics #

字体度量(逻辑单位,issue #6):组件不再猜 baseline(旧 hack 是 0.36 * size),用 ascent/descent/line_height 做垂直居中。


[View source]
def theme : Theme #

[View source]
def theme=(theme : Theme) : Nil #

[View source]