Launcher: long names and descriptions end in an ellipsis
Deploy to the handset / build-and-deploy (push) Successful in 2m21s
CI / test (push) Canceled after 2m38s

They ran under the scrollbar and off the popup's edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 23:17:26 -08:00
1 parent 5c83cdaa22
commit 4e6a8005dd
1 file changed
+58 -7
+58 -7
View File
@@ -430,9 +430,10 @@ pub fn render_popup(
let thumb = scroll_thumb(total, st)
let bar = if thumb is Some(_) { scrollbar_w - 6 } else { 0 }
let part = first_part(total, st)
if part > 0 {
ops.push(@types.DrawOp::PushClip(@ui.rect(lx, header_h, w - lx, max_rows * row_h)))
}
// Nothing of a row shows past the list: not its top or bottom when partly scrolled off, nor the
// end of a text wider than `fit` reckoned.
ops.push(@types.DrawOp::PushClip(@ui.rect(lx, header_h, w - lx - bar - 6, max_rows * row_h)))
let text_w = w - lx - bar - 12 - 56
for i = 0; i < shown.length(); i = i + 1 {
let a = shown[i]
let y = header_h + i * row_h - part
@@ -451,14 +452,12 @@ pub fn render_popup(
let glyph = if a.glyph.length() > 0 { a.glyph } else { @dock.app_glyph(a.id, a.name) }
ops.append(@dock.app_icon(cx, cy, icon_px - 2, a.id, glyph))
}
ops.push(@ui.text(lx + 56, y + 14, a.name, fs, fg, bold=true))
ops.push(@ui.text(lx + 56, y + 14, fit(a.name, fs, text_w, bold=true), fs, fg, bold=true))
// An app without a comment (a web app, say) shows its category there.
let about = if a.comment.length() > 0 { a.comment } else { a.category }
ops.push(@ui.text(lx + 56, y + 31, about, fs - 3, sub))
ops.push(@ui.text(lx + 56, y + 31, fit(about, fs - 3, text_w), fs - 3, sub))
}
if part > 0 {
ops.push(@types.DrawOp::PopClip)
}
match thumb {
Some((ty, th)) => {
ops.push(@ui.fill_rect(@ui.rect(w - 11, header_h + 4, 5, max_rows * row_h - 8), p.surface, radius=2))
@@ -494,6 +493,39 @@ pub fn render_popup(
ops
}
///| About how wide `c` is in the desktop's UI font, in hundredths of the text size.
fn char_w(c : Char) -> Int {
match c {
'i' | 'j' | 'l' | 'I' | ' ' | '.' | ',' | ':' | ';' | '\'' | '!' | '|' => 28
'f' | 'r' | 't' | '(' | ')' | '[' | ']' | '-' | '/' | '1' => 38
'm' | 'w' => 86
'M' | 'W' | '@' | '%' | '&' => 92
'A'..='Z' => 68
_ if c.to_int() < 0x2E80 => 56
_ => 100 // CJK, emoji
}
}
///| `s` cut to `w` pixels at `size` with an ellipsis.
fn fit(s : String, size : Int, w : Int, bold~ : Bool = false) -> String {
let room = w * 100 / (if size > 0 { size } else { 1 }) * 100 / (if bold { 108 } else { 100 })
let dots = 90
let out = StringBuilder::new()
let mut used = 0
let mut cut = "" // what still leaves room for the ellipsis
for c in s {
used = used + char_w(c)
if used > room {
return cut.trim_end().to_owned() + "…"
}
out.write_char(c)
if used + dots <= room {
cut = out.to_string()
}
}
s
}
///| Index in `listed` of the app row under a popup-local point, or -1.
pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> Int {
let n = listed(apps, st).length()
@@ -964,6 +996,25 @@ test "the list scrolls with the wheel and the scrollbar" {
assert_eq(st.scroll, 0)
}
///|
test "texts wider than the list end in an ellipsis" {
assert_eq(fit("short", 10, 60), "short")
assert_eq(fit("a longer text", 10, 50), "a longer…") // no space before the ellipsis
assert_eq(fit("iiiiiiiiiiiiiiiiiiii", 10, 60), "iiiiiiiiiiiiiiiiiiii") // narrow letters
assert_eq(fit("", 10, 60), "")
let long = "Resource monitor that shows usage and stats for processor, memory, disks and network"
let apps = long_catalog().map(a => { ..a, comment: long })
let st = State::new()
st.open = true
let ops = render_popup(apps, test_tokens(), st)
let shown = ops.filter_map(o => match o {
Text(t) if t.text.has_prefix("Resource") => Some(t.text)
_ => None
})
assert_eq(shown.length(), max_rows)
assert_true(shown.iter().all(t => t.has_suffix("…") && t.length() > 35))
}
///|
test "a finger scrolls the list by pixels" {
let apps = long_catalog()