class
Tessell::Kit::Context
- Tessell::Kit::Context
- Reference
- Object
Defined in:
tessell/kit/context.crConstant 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
- #advance_time(now_ms : Int64) : Nil
- #clear_text_cache : Nil
-
#device_font_size(size : Float32) : Float32
DPI 只影响文本设备字号;逻辑布局尺寸仍由 Metrics 给出。
-
#font_id_for(text : String, weight : FontWeight) : Int32
FontWeight → font_id(issue #29):按栈内字重匹配的覆盖脸;无栈或 无覆盖返回 0(默认 face)。
-
#font_stack : Tessell::Text::FontStack | Nil
多 face 字体栈(issue #29):nil = 单 face。设置后组件的 FontWeight 经 font_id_for 解析为 face 的 font_id,一路传到 Painter。
-
#font_stack=(font_stack : Tessell::Text::FontStack | Nil)
多 face 字体栈(issue #29):nil = 单 face。设置后组件的 FontWeight 经 font_id_for 解析为 face 的 font_id,一路传到 Painter。
- #line_height(size : Float32) : Float32
- #measure_text(text : String, size : Float32, max_width : Float32, font_id : Int32) : Size
-
#measure_text(text : String, size : Float32, font_id : Int32) : Size
face 维度测量(issue #29):font_id = 0 表示默认 face。
- #measure_text(text : String, size : Float32, max_width : Float32) : Size
-
#measure_text(text : String, size : Float32) : Size
逻辑单位契约(issue #14):以设备字号测量(与 Painter 提交的实际 字形尺寸一致),再除回 scale 返回逻辑尺寸。组件在 scale=1 与 scale=2 下得到相同逻辑 bounds,宿主无须自写除法适配器。
- #metrics : TextMetrics
- #now_ms : Int64
- #overlay_host : OverlayHost | Nil
- #overlay_host=(overlay_host : OverlayHost | Nil)
-
#render_theme : Tessell::Render::Theme
核心 Render::Theme 镜像(issue #8):Kit Palette 覆盖组件语义, 行情/网格/涨跌等扩展 token(panel/grid/up/down 等)从这里读, 应用不再自建平行 Palette。
- #scale : Float32
-
#scale=(value : Float32) : Nil
DPI/缩放变更(issue #30):scale 与文本测量缓存联动。缓存的测量值 是设备像素口径,对旧 scale 全部失效——改 scale 与清缓存在同一个 入口里完成,避免调用方漏清导致旧值漂移。
-
#supports_external_texture : Bool
后端是否支持外部纹理通道(issue #45):内置 Software/GL 后端均为 true;宿主自建不支持纹理的后端时置 false——Kit::Image 据此跳过 绘制(a11y 仍报 Role::Image),消除"静默空白"。
-
#supports_external_texture=(supports_external_texture : Bool)
后端是否支持外部纹理通道(issue #45):内置 Software/GL 后端均为 true;宿主自建不支持纹理的后端时置 false——Kit::Image 据此跳过 绘制(a11y 仍报 Role::Image),消除"静默空白"。
-
#text_cache_hits : Int32
缓存观测面(issue #24):应用据此判断是否需要 clear_text_cache。
- #text_cache_misses : Int32
- #text_cache_size : Int32
-
#text_cache_stats : NamedTuple(hits: Int32, misses: Int32, size: Int32)
与 CachingMeasurer#stats 同风格的汇总读数。
-
#text_metrics(size : Float32) : Tessell::Text::FontMetrics
字体度量(逻辑单位,issue #6):组件不再猜 baseline(旧 hack 是
0.36 * size),用 ascent/descent/line_height 做垂直居中。 - #theme : Theme
- #theme=(theme : Theme) : Nil
Constructor Detail
Instance Method Detail
FontWeight → font_id(issue #29):按栈内字重匹配的覆盖脸;无栈或 无覆盖返回 0(默认 face)。
多 face 字体栈(issue #29):nil = 单 face。设置后组件的 FontWeight 经 font_id_for 解析为 face 的 font_id,一路传到 Painter。
多 face 字体栈(issue #29):nil = 单 face。设置后组件的 FontWeight 经 font_id_for 解析为 face 的 font_id,一路传到 Painter。
face 维度测量(issue #29):font_id = 0 表示默认 face。
逻辑单位契约(issue #14):以设备字号测量(与 Painter 提交的实际 字形尺寸一致),再除回 scale 返回逻辑尺寸。组件在 scale=1 与 scale=2 下得到相同逻辑 bounds,宿主无须自写除法适配器。
核心 Render::Theme 镜像(issue #8):Kit Palette 覆盖组件语义, 行情/网格/涨跌等扩展 token(panel/grid/up/down 等)从这里读, 应用不再自建平行 Palette。
DPI/缩放变更(issue #30):scale 与文本测量缓存联动。缓存的测量值 是设备像素口径,对旧 scale 全部失效——改 scale 与清缓存在同一个 入口里完成,避免调用方漏清导致旧值漂移。
后端是否支持外部纹理通道(issue #45):内置 Software/GL 后端均为 true;宿主自建不支持纹理的后端时置 false——Kit::Image 据此跳过 绘制(a11y 仍报 Role::Image),消除"静默空白"。
后端是否支持外部纹理通道(issue #45):内置 Software/GL 后端均为 true;宿主自建不支持纹理的后端时置 false——Kit::Image 据此跳过 绘制(a11y 仍报 Role::Image),消除"静默空白"。
与 CachingMeasurer#stats 同风格的汇总读数。
字体度量(逻辑单位,issue #6):组件不再猜 baseline(旧 hack 是
0.36 * size),用 ascent/descent/line_height 做垂直居中。