ludic/packages/ludic.ui/tooltip_text.ludic
2026-09-24 22:06:27 +03:00

30 lines
1.2 KiB
Text

# tooltip_text.ludic - a title in the program's language (whole when the translator knows it whole,
# else line by line, and not inside translate="no"), and a title for the keyboard's focus
var tt_by_keys: bool = false # the focus moved by the keyboard since the pointer last moved
var tt_focus_seen: string = ""
# the focused element, when the keyboard put the focus there and it has a title; else null
function tt_focused(scope: UiNode, x: float, y: float) -> UiNode {
if in_last.x != x or in_last.y != y { tt_by_keys = false }
if fc_visible and fc_key != "" and fc_key != tt_focus_seen { tt_by_keys = true }
tt_focus_seen = fc_key
if not tt_by_keys or not fc_visible { return null }
let n = fr_node(scope, fc_key)
if n == null or n.akeys == null or ui_attr_text(n, "title") == "" { return null }
return n
}
function tt_translate(n: UiNode, s: string) -> string {
var at = n
while at != null {
let say = ui_attr_text(at, "translate")
if say == "no" { return s }
if say == "yes" { break }
at = at.parent
}
let whole = ui_tr(s)
if whole != s { return whole }
let lines = tt_lines(s)
if len(lines) < 2 { return whole }
var out = ui_tr(lines[0])
for i in 1 .. len(lines) { out = out + "\n" + ui_tr(lines[i]) }
return out
}