ludic/packages/ludic.ui/tooltip_text.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

28 lines
1.3 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
# the focused element, when the keyboard put the focus there and it has a title; else null
function tt_focused(ui_st: mut UiState, scope: UiNode, x: float, y: float) -> UiNode {
if ui_st.in_last.x != x or ui_st.in_last.y != y { ui_st.tt_by_keys = false }
if ui_st.fc_visible and ui_st.fc_key != "" and ui_st.fc_key != ui_st.tt_focus_seen { ui_st.tt_by_keys = true }
ui_st.tt_focus_seen = ui_st.fc_key
if not ui_st.tt_by_keys or not ui_st.fc_visible { return null }
let n = fr_node(scope, ui_st.fc_key)
if n == null or n.akeys == null or ui_attr_text(n, "title") == "" { return null }
return n
}
function tt_translate(ui_st: UiState, 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(ui_st, s)
if whole != s { return whole }
let lines = tt_lines(s)
if len(lines) < 2 { return whole }
var out = ui_tr(ui_st, lines[0])
for i in 1 .. len(lines) { out = out + "\n" + ui_tr(ui_st, lines[i]) }
return out
}