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

+106 -28
View File
@@ -50,6 +50,9 @@ pub(all) struct ConfigEntry {
///|
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.
pub(all) struct Pal {
bg : @types.Color
@@ -134,6 +137,7 @@ pub(all) struct Library {
mut selected : String
mut focused : Bool
mut colors : String
mut background : String
/// From the last render: where things are, the cards in order with their columns, and the
/// grid's height and viewport (for the wheel).
regions : Array[(@types.Rect, Hit)]
@@ -154,6 +158,7 @@ pub fn Library::new() -> Library {
selected: "",
focused: false,
colors: "Follow desktop",
background: "Wallpaper",
regions: [],
shown: [],
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.
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 {
"Dark" => Pal::dark()
"Light" => Pal::light()
@@ -429,19 +453,38 @@ fn Library::button(
w
}
///| Height of a card `w` wide: header, description, hint and buttons.
fn card_height(g : Game, w : Int) -> Int {
let inner = w - 40
let desc = wrap(g.description, inner, fs, 3).length()
let hint = if g.installed || g.install_hint == "" { 0 } else { wrap(g.install_hint, inner - 20, fs_small, 3).length() }
20 + 48 + 14 + desc * 22 + (if hint > 0 { 10 + hint * 18 } else { 0 }) + 20 + 30 + 20
///| How much a card says at density `lv` (0 the most): (description lines, hint lines, padding).
/// The grid picks the roomiest density that fits the screen, so the library doesn't scroll.
fn dense(lv : Int) -> (Int, Int, Int) {
match lv {
0 => (3, 3, 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),
/// 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 n = (inner_w + gap) / (card_min_w + gap)
let n = (inner_w + gap) / (min_w + gap)
if n < 1 { 1 } else { n }
}
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
}
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)
col = col + span
}
@@ -478,6 +521,26 @@ pub fn grid_layout(games : Array[Game], inner_w : Int) -> (Array[(Int, Int, Int,
(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`.
pub fn Library::render(
self : Library,
@@ -494,7 +557,12 @@ pub fn Library::render(
self.regions.clear()
self.games = games
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 main_x = if side_w > 0 { side_w + 16 } else { 8 }
let body_h = h - top_h - bottom - 8
@@ -571,7 +639,8 @@ pub fn Library::render(
let gy = top_h + 88
let gw = mw - 48
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.view_h = gh
self.clamp_scroll()
@@ -596,7 +665,7 @@ pub fn Library::render(
if y + ch < gy - 8 || y > gy + gh + 8 {
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)
// A scrollbar when the grid is taller than its view.
@@ -709,7 +778,9 @@ fn Library::render_card(
p : Pal,
clip_y : Int,
clip_h : Int,
lv : Int,
) -> Unit {
let (dl, hl, pad) = dense(lv)
let r = @ui.rect(x, y, w, h)
let hov = match self.hover {
Card(id) | Button(id, _) | StopButton(id) | FocusButton(id) => id == g.id
@@ -721,34 +792,34 @@ fn Library::render_card(
}
// Icon tile, name and badges.
let (tbg, tfg) = tile_colors(g.icon, p)
ops.push(@ui.fill_rect(@ui.rect(x + 20, y + 20, 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)
ops.push(@ui.text(x + 78, y + 32, ellipsize(g.name, w - 98, 16), 16, p.fg, bold=true))
let bx = x + 76
let bw = badge(ops, bx, y + 48, category_badge(g.category), p.badge_bg, p.badge_fg)
ops.push(@ui.fill_rect(@ui.rect(x + pad, y + pad, 44, 44), tbg, radius=10))
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 + pad + 58, y + pad + 12, ellipsize(g.name, w - 2 * pad - 58, 16), 16, p.fg, bold=true))
let bx = x + pad + 56
let bw = badge(ops, bx, y + pad + 28, category_badge(g.category), p.badge_bg, p.badge_fg)
let st = g.status()
let (sbg, sfg) = match st {
Ready | Running => (p.ok_bg, p.ok)
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.
let mut ty = y + 20 + 48 + 14 + 11
for line in wrap(g.description, w - 40, fs, 3) {
ops.push(@ui.text(x + 20, ty, line, fs, p.fg))
let mut ty = y + pad + 48 + 14 + 11
for line in (if dl == 0 { [] } else { wrap(g.description, w - 2 * pad, fs, dl) }) {
ops.push(@ui.text(x + pad, ty, line, fs, p.fg))
ty = ty + 22
}
if !g.installed && g.install_hint != "" {
if hl > 0 && !g.installed && g.install_hint != "" {
ty = ty + 10 - 2
draw_glyph(ops, "Info", x + 20, ty - 7, 14, p.muted)
for line in wrap(g.install_hint, w - 60, fs_small, 3) {
ops.push(@ui.text(x + 40, ty, line, fs_small, p.muted))
draw_glyph(ops, "Info", x + pad, ty - 7, 14, p.muted)
for line in wrap(g.install_hint, w - 2 * pad - 20, fs_small, hl) {
ops.push(@ui.text(x + pad + 20, ty, line, fs_small, p.muted))
ty = ty + 18
}
}
// Buttons, at the bottom.
let by = y + h - 20 - 30
let mut bx = x + 20
let by = y + h - pad - 30
let mut bx = x + pad
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, "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.
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.
@@ -992,6 +1066,10 @@ pub fn Library::set_config(self : Library, key : String, value : String) -> Bool
self.colors = value
true
}
"background" if background_choices.contains(value) => {
self.background = value
true
}
_ => false
}
}