Applications menu and Icon Desktop: show each app's .desktop icon
CI / test (push) Failing after 2m56s
CI / test (push) Failing after 2m56s
The launcher's rows drew a letter circle and the Icon Desktop fell back to letter tiles for every app that wasn't in the dock: the shell only published icons for windows' and dock apps. publish_icons now also covers the rows the open Applications menu lists (only those, so opening it looks up a handful of icons) and every catalog app when the desktop module imports icons. Lookups are the dock's (theme chain, absolute Icon= paths, PNG on the native host, SVG too on the wasm host, generic app icon, then the letter tile) and cached per id; an unchanged icons table is no longer re-sent every frame. launcher-widget imports icons; the JS host has an icons stub (always 0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hkhaM5djqPXPQNs7QR
This commit is contained in:
12 files changed
+273
-29
No files matched your search
@@ -123,6 +123,21 @@ fn visible_rows(n : Int) -> Int {
|
||||
if n > max_rows { max_rows } else { n }
|
||||
}
|
||||
|
||||
///| The apps the popup lists now: the filtered catalog, capped at the rows that fit. The shell
|
||||
/// publishes icons for exactly these while the menu is open.
|
||||
pub fn shown_rows(apps : Array[@types.AppEntry], st : State) -> Array[@types.AppEntry] {
|
||||
let shown = filter(apps, st.query)
|
||||
let n = visible_rows(shown.length())
|
||||
if n >= shown.length() {
|
||||
shown
|
||||
} else {
|
||||
shown[:n].to_array()
|
||||
}
|
||||
}
|
||||
|
||||
///| Side of an app's icon in its row.
|
||||
let icon_px : Int = 32
|
||||
|
||||
///|
|
||||
pub fn popup_size(apps : Array[@types.AppEntry], st : State) -> @types.Size {
|
||||
let rows = visible_rows(filter(apps, st.query).length())
|
||||
@@ -197,10 +212,13 @@ pub fn render_button(
|
||||
}
|
||||
|
||||
///|
|
||||
///| Draw the open popup. `icon` gives an app id's .desktop icon as an image handle (0: none, the
|
||||
/// app's letter tile is drawn instead, the same one the dock uses).
|
||||
pub fn render_popup(
|
||||
apps : Array[@types.AppEntry],
|
||||
t : @theme.Tokens,
|
||||
st : State,
|
||||
icon~ : (String) -> UInt = _ => 0U,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let size = popup_size(apps, st)
|
||||
let w = size.w.reinterpret_as_int()
|
||||
@@ -235,8 +253,15 @@ pub fn render_popup(
|
||||
}
|
||||
let fg = if i == st.hover { p.accent_foreground } else { p.foreground }
|
||||
let sub = if i == st.hover { p.accent_foreground } else { p.foreground_muted }
|
||||
ops.push(@ui.circle(30, y + row_h / 2 - 1, 15, p.surface_hover))
|
||||
ops.push(@ui.text(30, y + row_h / 2 - 1, a.glyph, fs, fg, align=CENTER, bold=true))
|
||||
let cx = 30
|
||||
let cy = y + row_h / 2 - 1
|
||||
let h = icon(a.id)
|
||||
if h != 0U {
|
||||
ops.push(@types.DrawOp::Image({ rect: @ui.rect(cx - icon_px / 2, cy - icon_px / 2, icon_px, icon_px), image: h }))
|
||||
} else {
|
||||
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(56, y + 14, a.name, fs, fg, bold=true))
|
||||
ops.push(@ui.text(56, y + 31, a.comment, fs - 3, sub))
|
||||
}
|
||||
@@ -539,3 +564,65 @@ test "session row: a click on an app disarms, and app rows don't reach the row"
|
||||
ignore(handle_event(apps, st, Popup, PointerDown({ x: 20, y: 60 }), _ => Ok(())))
|
||||
assert_eq(st.armed, -1)
|
||||
}
|
||||
|
||||
///| The image ops of a drawing, with the handles they draw.
|
||||
fn images(ops : Array[@types.DrawOp]) -> Array[UInt] {
|
||||
ops.filter_map(op => match op { Image(img) => Some(img.image); _ => None })
|
||||
}
|
||||
|
||||
///|
|
||||
test "rows draw the app's .desktop icon, or the letter tile when it has none" {
|
||||
let apps = sample_apps()
|
||||
let st = State::new()
|
||||
st.open = true
|
||||
let asked : Array[String] = []
|
||||
let icon = fn(id : String) {
|
||||
asked.push(id)
|
||||
if id == "b" { 0U } else if id == "a" { 7U } else { 9U }
|
||||
}
|
||||
let ops = render_popup(apps, test_tokens(), st, icon~)
|
||||
assert_eq(asked, ["a", "b", "c"])
|
||||
assert_eq(images(ops), [7U, 9U])
|
||||
// Files has no icon: its tile shows its glyph.
|
||||
assert_true(ops.iter().any(op => match op { Text(t) => t.text == "F"; _ => false }))
|
||||
// With a search only the matching rows ask for icons.
|
||||
st.query = "term"
|
||||
asked.clear()
|
||||
assert_eq(images(render_popup(apps, test_tokens(), st, icon~)), [7U])
|
||||
assert_eq(asked, ["a"])
|
||||
}
|
||||
|
||||
///|
|
||||
test "shown_rows is the filtered list, capped at the rows that fit" {
|
||||
let apps : Array[@types.AppEntry] = []
|
||||
for i = 0; i < 12; i = i + 1 {
|
||||
apps.push({ id: "app" + i.to_string(), name: "App " + i.to_string(), comment: "", category: "", glyph: "" })
|
||||
}
|
||||
let st = State::new()
|
||||
assert_eq(shown_rows(apps, st).length(), max_rows)
|
||||
st.query = "App 1"
|
||||
assert_eq(shown_rows(apps, st).map(a => a.id), ["app1", "app10", "app11"])
|
||||
}
|
||||
|
||||
///|
|
||||
fn test_tokens() -> @theme.Tokens {
|
||||
{
|
||||
name: "t",
|
||||
palette: {
|
||||
desktop_top: @ui.color(0, 0, 0, 255),
|
||||
desktop_bottom: @ui.color(0, 0, 0, 255),
|
||||
surface: @ui.color(30, 30, 30, 255),
|
||||
surface_hover: @ui.color(40, 40, 40, 255),
|
||||
surface_popup: @ui.color(30, 30, 30, 255),
|
||||
foreground: @ui.color(255, 255, 255, 255),
|
||||
foreground_muted: @ui.color(150, 150, 150, 255),
|
||||
accent: @ui.color(60, 120, 220, 255),
|
||||
accent_foreground: @ui.color(255, 255, 255, 255),
|
||||
border: @ui.color(60, 60, 60, 255),
|
||||
},
|
||||
font_size: 14U,
|
||||
radius: 6U,
|
||||
spacing: 6U,
|
||||
panel_height: 44U,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user