Launcher: long names and descriptions end in an ellipsis
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:
1 parent
5c83cdaa22
commit
4e6a8005dd
1 file changed
+58
-7
@@ -430,9 +430,10 @@ pub fn render_popup(
|
|||||||
let thumb = scroll_thumb(total, st)
|
let thumb = scroll_thumb(total, st)
|
||||||
let bar = if thumb is Some(_) { scrollbar_w - 6 } else { 0 }
|
let bar = if thumb is Some(_) { scrollbar_w - 6 } else { 0 }
|
||||||
let part = first_part(total, st)
|
let part = first_part(total, st)
|
||||||
if part > 0 {
|
// Nothing of a row shows past the list: not its top or bottom when partly scrolled off, nor the
|
||||||
ops.push(@types.DrawOp::PushClip(@ui.rect(lx, header_h, w - lx, max_rows * row_h)))
|
// 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 {
|
for i = 0; i < shown.length(); i = i + 1 {
|
||||||
let a = shown[i]
|
let a = shown[i]
|
||||||
let y = header_h + i * row_h - part
|
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) }
|
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.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.
|
// 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 }
|
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)
|
ops.push(@types.DrawOp::PopClip)
|
||||||
}
|
|
||||||
match thumb {
|
match thumb {
|
||||||
Some((ty, th)) => {
|
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))
|
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
|
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.
|
///| 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 {
|
pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> Int {
|
||||||
let n = listed(apps, st).length()
|
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)
|
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" {
|
test "a finger scrolls the list by pixels" {
|
||||||
let apps = long_catalog()
|
let apps = long_catalog()
|
||||||
|
|||||||
Reference in new issue
Block a user