Gamerig Library: fit the screen without scrolling, draw over the wallpaper
CI / test (push) Successful in 2m32s

The grid picks the roomiest card density that fits (fewer description and hint lines, narrower
cards, then name and buttons only) before it would scroll. The module now draws over the
desktop wallpaper with glassy panels and cards; Background setting Wallpaper (default) or Solid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgvjzw8hHirxRsXSsE
This commit is contained in:
Claude committed 2026-11-26 03:14:18 +00:00
1 parent f556df2f4b
commit 1154437050
5 files changed
+133 -31

No files matched your search

@@ -1,9 +1,9 @@
///| The library replaces the wallpaper (gamerig's own background) and only redraws on events and ///| The library draws over the wallpaper (glassy panels; its Solid setting covers it) and only redraws on events and
/// when the shell has new data from the daemon: it never animates. /// when the shell has new data from the daemon: it never animates.
///| ///|
pub fn backdrop() -> WallpaperMode { pub fn backdrop() -> WallpaperMode {
REPLACE_WALLPAPER OVER_WALLPAPER
} }
///| ///|
+5 -1
View File
@@ -32,7 +32,11 @@ or pick **Gamerig Library** in Settings > Desktop.
shows under the title for a few seconds. shows under the title for a few seconds.
* Keyboard: arrows move the selection, Enter launches it (or switches to it), Backspace and * Keyboard: arrows move the selection, Enter launches it (or switches to it), Backspace and
Escape edit the search; the wheel scrolls the grid. Escape edit the search; the wheel scrolls the grid.
* Module settings (right-click the desktop): Colours, *Follow desktop* (gamerig dark or light * It fits the screen: when the cards don't fit, they get narrower and say less (fewer
description and hint lines, then name and buttons only) before the grid would scroll.
* It is the desktop's "wallpaper": panels and cards are glassy and the desktop wallpaper shows
through. Module settings (right-click the desktop): Background, *Wallpaper* or *Solid*
(gamerig's own background colour); Colours, *Follow desktop* (gamerig dark or light
after the desktop theme), *Dark* or *Light*. after the desktop theme), *Dark* or *Light*.
Not there yet: the Add App dialog and the per-app logs view (both are in the web library), and Not there yet: the Add App dialog and the per-app logs view (both are in the web library), and
Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 168 KiB

+20
View File
@@ -169,3 +169,23 @@ test "disconnected: says it is waiting, and the error" {
assert_true(t.contains("Waiting for the library daemon…")) assert_true(t.contains("Waiting for the library daemon…"))
assert_true(t.contains("Library daemon not reachable")) assert_true(t.contains("Library daemon not reachable"))
} }
///|
test "nine games fit a 1280x720 desktop without scrolling, and the wallpaper shows through" {
let lib = @gamelib.Library::new()
let base = sample_state().games[1]
let games = Array::makei(9, i => { ..base, id: "g" + i.to_string(), featured: i < 2 })
let ops = lib.render(games, [], @gamelib.Rig::unknown(), { w: 1280, h: 720 }, tokens())
assert_true(lib.content_h <= lib.view_h, msg="grid \{lib.content_h} > view \{lib.view_h}")
// No opaque full-screen background in the default Wallpaper mode.
match ops[0] {
FillRect(f) => assert_true(f.rect.h != 720 || f.color.a.to_int() < 255)
_ => ()
}
assert_true(lib.set_config("background", "Solid"))
let ops = lib.render(games, [], @gamelib.Rig::unknown(), { w: 1280, h: 720 }, tokens())
match ops[0] {
FillRect(f) => assert_eq(f.color.a.to_int(), 255)
_ => fail("no background")
}
}
+106 -28
View File
@@ -50,6 +50,9 @@ pub(all) struct ConfigEntry {
///| ///|
pub let colors_choices : Array[String] = ["Follow desktop", "Dark", "Light"] pub let colors_choices : Array[String] = ["Follow desktop", "Dark", "Light"]
///| Behind the library: the desktop's wallpaper through glassy panels, or gamerig's solid colour.
pub let background_choices : Array[String] = ["Wallpaper", "Solid"]
///| Gamerig's colours. ///| Gamerig's colours.
pub(all) struct Pal { pub(all) struct Pal {
bg : @types.Color bg : @types.Color
@@ -134,6 +137,7 @@ pub(all) struct Library {
mut selected : String mut selected : String
mut focused : Bool mut focused : Bool
mut colors : String mut colors : String
mut background : String
/// From the last render: where things are, the cards in order with their columns, and the /// From the last render: where things are, the cards in order with their columns, and the
/// grid's height and viewport (for the wheel). /// grid's height and viewport (for the wheel).
regions : Array[(@types.Rect, Hit)] regions : Array[(@types.Rect, Hit)]
@@ -154,6 +158,7 @@ pub fn Library::new() -> Library {
selected: "", selected: "",
focused: false, focused: false,
colors: "Follow desktop", colors: "Follow desktop",
background: "Wallpaper",
regions: [], regions: [],
shown: [], shown: [],
content_h: 0, content_h: 0,
@@ -235,6 +240,25 @@ pub fn wrap(s : String, w : Int, size : Int, max : Int) -> Array[String] {
///| The palette for the colours setting and the desktop theme. ///| The palette for the colours setting and the desktop theme.
fn Library::pal(self : Library, tokens : @theme.Tokens) -> Pal { fn Library::pal(self : Library, tokens : @theme.Tokens) -> Pal {
let p = self.solid_pal(tokens)
if self.background == "Solid" {
return p
}
// Over the wallpaper: the panels and cards let it show through, the wallpaper itself is the
// background.
let a = if p.dark { 0 } else { 30 }
{
..p,
bg: @ui.with_alpha(p.bg, 0),
panel: @ui.with_alpha(p.panel, 170 + a),
card: @ui.with_alpha(p.card, 215 + a / 2),
card_hover: @ui.with_alpha(p.card_hover, 235),
row_sel: @ui.with_alpha(p.row_sel, 210),
}
}
///|
fn Library::solid_pal(self : Library, tokens : @theme.Tokens) -> Pal {
match self.colors { match self.colors {
"Dark" => Pal::dark() "Dark" => Pal::dark()
"Light" => Pal::light() "Light" => Pal::light()
@@ -429,19 +453,38 @@ fn Library::button(
w w
} }
///| Height of a card `w` wide: header, description, hint and buttons. ///| How much a card says at density `lv` (0 the most): (description lines, hint lines, padding).
fn card_height(g : Game, w : Int) -> Int { /// The grid picks the roomiest density that fits the screen, so the library doesn't scroll.
let inner = w - 40 fn dense(lv : Int) -> (Int, Int, Int) {
let desc = wrap(g.description, inner, fs, 3).length() match lv {
let hint = if g.installed || g.install_hint == "" { 0 } else { wrap(g.install_hint, inner - 20, fs_small, 3).length() } 0 => (3, 3, 20)
20 + 48 + 14 + desc * 22 + (if hint > 0 { 10 + hint * 18 } else { 0 }) + 20 + 30 + 20 1 => (2, 2, 18)
2 => (2, 1, 16)
3 => (1, 0, 14)
_ => (0, 0, 12)
}
}
///| Densities and narrowest card widths tried, in order, until the grid fits.
let fit_steps : Array[(Int, Int)] = [
(0, 280), (1, 280), (1, 240), (2, 240), (2, 210), (3, 240), (3, 210), (3, 180), (4, 210), (4, 180), (4, 150),
]
///| Height of a card `w` wide at density `lv`: header, description, hint and buttons.
fn card_height(g : Game, w : Int, lv : Int) -> Int {
let (dl, hl, pad) = dense(lv)
let inner = w - 2 * pad
let desc = if dl == 0 { 0 } else { wrap(g.description, inner, fs, dl).length() }
let hint = if hl == 0 || g.installed || g.install_hint == "" { 0 } else { wrap(g.install_hint, inner - 20, fs_small, hl).length() }
pad + 48 + (if desc > 0 { 14 + desc * 22 } else { 4 }) + (if hint > 0 { 10 + hint * 18 } else { 0 }) + 14 + 30 + pad
} }
///| Place the cards: (game index, x, y, w, h) in grid coordinates (0, 0 at the grid's top-left), ///| Place the cards: (game index, x, y, w, h) in grid coordinates (0, 0 at the grid's top-left),
/// featured games two columns wide when there are two, rows as tall as their tallest card. /// featured games two columns wide when there are two, rows as tall as their tallest card.
pub fn grid_layout(games : Array[Game], inner_w : Int) -> (Array[(Int, Int, Int, Int, Int)], Int, Int) { pub fn grid_layout(games : Array[Game], inner_w : Int, lv? : Int = 0, min_w? : Int = card_min_w) -> (Array[(Int, Int, Int, Int, Int)], Int, Int) {
let gap = grid_gap(lv)
let cols = { let cols = {
let n = (inner_w + gap) / (card_min_w + gap) let n = (inner_w + gap) / (min_w + gap)
if n < 1 { 1 } else { n } if n < 1 { 1 } else { n }
} }
let col_w = (inner_w - gap * (cols - 1)) / cols let col_w = (inner_w - gap * (cols - 1)) / cols
@@ -470,7 +513,7 @@ pub fn grid_layout(games : Array[Game], inner_w : Int) -> (Array[(Int, Int, Int,
col = 0 col = 0
} }
let w = col_w * span + gap * (span - 1) let w = col_w * span + gap * (span - 1)
out.push((i, col * (col_w + gap), y, w, card_height(g, w))) out.push((i, col * (col_w + gap), y, w, card_height(g, w, lv)))
row.push(out.length() - 1) row.push(out.length() - 1)
col = col + span col = col + span
} }
@@ -478,6 +521,26 @@ pub fn grid_layout(games : Array[Game], inner_w : Int) -> (Array[(Int, Int, Int,
(out, total, cols) (out, total, cols)
} }
///| The gap between cards at density `lv`.
fn grid_gap(lv : Int) -> Int {
if lv >= 3 { 12 } else { gap }
}
///| The roomiest grid that fits `inner_h`: (cells, height, columns, density). The densest when
/// none does (it scrolls then).
pub fn grid_fit(games : Array[Game], inner_w : Int, inner_h : Int) -> (Array[(Int, Int, Int, Int, Int)], Int, Int, Int) {
let mut last = (([] : Array[(Int, Int, Int, Int, Int)]), 0, 1, 4)
for st in fit_steps {
let (lv, mw) = st
let (cells, total, cols) = grid_layout(games, inner_w, lv~, min_w=mw)
last = (cells, total, cols, lv)
if total <= inner_h {
break
}
}
last
}
///| Draw the whole library for an output `size`. ///| Draw the whole library for an output `size`.
pub fn Library::render( pub fn Library::render(
self : Library, self : Library,
@@ -494,7 +557,12 @@ pub fn Library::render(
self.regions.clear() self.regions.clear()
self.games = games self.games = games
let ops : Array[@types.DrawOp] = [] let ops : Array[@types.DrawOp] = []
ops.push(@ui.fill_rect(@ui.rect(0, 0, w, h), p.bg)) if self.background == "Solid" {
ops.push(@ui.fill_rect(@ui.rect(0, 0, w, h), p.bg))
} else {
// A light veil under the top bar keeps its text readable on any wallpaper.
ops.push(@ui.fill_rect(@ui.rect(0, 0, w, top_h), @ui.with_alpha(p.panel, 120)))
}
let side_w = if w >= 1100 { 272 } else if w >= 700 { 220 } else { 0 } let side_w = if w >= 1100 { 272 } else if w >= 700 { 220 } else { 0 }
let main_x = if side_w > 0 { side_w + 16 } else { 8 } let main_x = if side_w > 0 { side_w + 16 } else { 8 }
let body_h = h - top_h - bottom - 8 let body_h = h - top_h - bottom - 8
@@ -571,7 +639,8 @@ pub fn Library::render(
let gy = top_h + 88 let gy = top_h + 88
let gw = mw - 48 let gw = mw - 48
let gh = body_h - 88 - 16 let gh = body_h - 88 - 16
let (cells, total, cols) = grid_layout(shown, gw) let (cells, total, cols, lv) = grid_fit(shown, gw, gh)
let gap = grid_gap(lv)
self.content_h = total self.content_h = total
self.view_h = gh self.view_h = gh
self.clamp_scroll() self.clamp_scroll()
@@ -596,7 +665,7 @@ pub fn Library::render(
if y + ch < gy - 8 || y > gy + gh + 8 { if y + ch < gy - 8 || y > gy + gh + 8 {
continue continue
} }
self.render_card(ops, shown[i], modes_of(modes, shown[i].id), gx + x, y, cw, ch, p, gy, gh) self.render_card(ops, shown[i], modes_of(modes, shown[i].id), gx + x, y, cw, ch, p, gy, gh, lv)
} }
ops.push(@types.DrawOp::PopClip) ops.push(@types.DrawOp::PopClip)
// A scrollbar when the grid is taller than its view. // A scrollbar when the grid is taller than its view.
@@ -709,7 +778,9 @@ fn Library::render_card(
p : Pal, p : Pal,
clip_y : Int, clip_y : Int,
clip_h : Int, clip_h : Int,
lv : Int,
) -> Unit { ) -> Unit {
let (dl, hl, pad) = dense(lv)
let r = @ui.rect(x, y, w, h) let r = @ui.rect(x, y, w, h)
let hov = match self.hover { let hov = match self.hover {
Card(id) | Button(id, _) | StopButton(id) | FocusButton(id) => id == g.id Card(id) | Button(id, _) | StopButton(id) | FocusButton(id) => id == g.id
@@ -721,34 +792,34 @@ fn Library::render_card(
} }
// Icon tile, name and badges. // Icon tile, name and badges.
let (tbg, tfg) = tile_colors(g.icon, p) let (tbg, tfg) = tile_colors(g.icon, p)
ops.push(@ui.fill_rect(@ui.rect(x + 20, y + 20, 44, 44), tbg, radius=10)) ops.push(@ui.fill_rect(@ui.rect(x + pad, y + pad, 44, 44), tbg, radius=10))
draw_glyph(ops, g.icon, x + 30, y + 30, 24, tfg, letter=g.name.to_array()[:1].to_owned() |> String::from_array) draw_glyph(ops, g.icon, x + pad + 10, y + pad + 10, 24, tfg, letter=g.name.to_array()[:1].to_owned() |> String::from_array)
ops.push(@ui.text(x + 78, y + 32, ellipsize(g.name, w - 98, 16), 16, p.fg, bold=true)) ops.push(@ui.text(x + pad + 58, y + pad + 12, ellipsize(g.name, w - 2 * pad - 58, 16), 16, p.fg, bold=true))
let bx = x + 76 let bx = x + pad + 56
let bw = badge(ops, bx, y + 48, category_badge(g.category), p.badge_bg, p.badge_fg) let bw = badge(ops, bx, y + pad + 28, category_badge(g.category), p.badge_bg, p.badge_fg)
let st = g.status() let st = g.status()
let (sbg, sfg) = match st { let (sbg, sfg) = match st {
Ready | Running => (p.ok_bg, p.ok) Ready | Running => (p.ok_bg, p.ok)
NotInstalled => (p.badge_bg, p.badge_fg) NotInstalled => (p.badge_bg, p.badge_fg)
} }
ignore(badge(ops, bx + bw + 6, y + 48, st.label(), sbg, sfg)) ignore(badge(ops, bx + bw + 6, y + pad + 28, st.label(), sbg, sfg))
// Description and hint. // Description and hint.
let mut ty = y + 20 + 48 + 14 + 11 let mut ty = y + pad + 48 + 14 + 11
for line in wrap(g.description, w - 40, fs, 3) { for line in (if dl == 0 { [] } else { wrap(g.description, w - 2 * pad, fs, dl) }) {
ops.push(@ui.text(x + 20, ty, line, fs, p.fg)) ops.push(@ui.text(x + pad, ty, line, fs, p.fg))
ty = ty + 22 ty = ty + 22
} }
if !g.installed && g.install_hint != "" { if hl > 0 && !g.installed && g.install_hint != "" {
ty = ty + 10 - 2 ty = ty + 10 - 2
draw_glyph(ops, "Info", x + 20, ty - 7, 14, p.muted) draw_glyph(ops, "Info", x + pad, ty - 7, 14, p.muted)
for line in wrap(g.install_hint, w - 60, fs_small, 3) { for line in wrap(g.install_hint, w - 2 * pad - 20, fs_small, hl) {
ops.push(@ui.text(x + 40, ty, line, fs_small, p.muted)) ops.push(@ui.text(x + pad + 20, ty, line, fs_small, p.muted))
ty = ty + 18 ty = ty + 18
} }
} }
// Buttons, at the bottom. // Buttons, at the bottom.
let by = y + h - 20 - 30 let by = y + h - pad - 30
let mut bx = x + 20 let mut bx = x + pad
if g.running { if g.running {
bx = bx + self.button(ops, bx, by, "Switch to", "ExternalLink", true, FocusButton(g.id), p) + 8 bx = bx + self.button(ops, bx, by, "Switch to", "ExternalLink", true, FocusButton(g.id), p) + 8
bx = bx + self.button(ops, bx, by, "Stop", "Stop", false, StopButton(g.id), p) + 8 bx = bx + self.button(ops, bx, by, "Stop", "Stop", false, StopButton(g.id), p) + 8
@@ -982,7 +1053,10 @@ fn Library::key(self : Library, k : String) -> (Bool, Action) {
///| The right-click settings. ///| The right-click settings.
pub fn Library::config_items(self : Library) -> Array[ConfigEntry] { pub fn Library::config_items(self : Library) -> Array[ConfigEntry] {
[{ key: "colors", label: "Colours", choices: colors_choices, value: self.colors }] [
{ key: "background", label: "Background", choices: background_choices, value: self.background },
{ key: "colors", label: "Colours", choices: colors_choices, value: self.colors },
]
} }
///| Set one; true when it changed something on screen. ///| Set one; true when it changed something on screen.
@@ -992,6 +1066,10 @@ pub fn Library::set_config(self : Library, key : String, value : String) -> Bool
self.colors = value self.colors = value
true true
} }
"background" if background_choices.contains(value) => {
self.background = value
true
}
_ => false _ => false
} }
} }