Add dock module: dock-style quick launcher with magnifying app tiles
CI / test (push) Failing after 23s

- lib/dock: tile layout, hit-testing, magnification, per-app colours (tested)
- components/dock: plasmoid module (imports only app-catalog + app-launch)
- shell: panel widgets now get pointer-move / pointer-leave while hovered

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 00:14:29 -08:00
1 parent 79321790a1
commit 6fc921b431
15 files changed
+930

No files matched your search

+153
View File
@@ -0,0 +1,153 @@
///| Dock-style quick launcher: a row of app tiles that grow under the pointer,
/// click to start. Pure: the component stub passes in the app list and tokens.
///| Most tiles shown; the catalog is ordered defaults, recents, then the rest.
pub let max_tiles : Int = 8
///| Space between tile slots.
let gap : Int = 6
///| Side padding of the whole dock.
let pad : Int = 6
///| Tile edge when not hovered, for a widget `h` pixels tall.
fn base_size(h : Int) -> Int {
let s = h - 14
if s < 16 { 16 } else if s > 32 { 32 } else { s }
}
///| Distance between tile centres.
fn pitch(h : Int) -> Int {
base_size(h) + gap
}
///| Preferred widget width for `n` tiles.
pub fn preferred_width(n : Int) -> Int {
let n = if n > max_tiles { max_tiles } else { n }
pad * 2 + n * pitch(34) - gap
}
///| Index of the tile slot under widget-local `x`, or -1 (outside the tile row / padding / gap).
pub fn tile_at(n : Int, h : Int, x : Int, y : Int) -> Int {
let n = if n > max_tiles { max_tiles } else { n }
if y < 0 || y >= h || x < pad {
return -1
}
let rel = x - pad
let i = rel / pitch(h)
if i >= n {
return -1
}
// The gap between slots belongs to the nearer tile so the cursor never flickers off it.
i
}
///| Edge length of tile `i` given the hovered tile (-1 for none): the hovered tile
/// grows most, its neighbours half as much.
pub fn tile_size(i : Int, hover : Int, h : Int) -> Int {
let base = base_size(h)
let room = h - 4 - base
let extra = if room > 8 { 8 } else if room < 0 { 0 } else { room }
if hover < 0 {
return base
}
let d = if i > hover { i - hover } else { hover - i }
if d == 0 {
base + extra
} else if d == 1 {
base + extra / 2
} else {
base
}
}
///| Tile colours: fixed saturated hues picked from the app id so an app keeps its colour.
let hues : Array[(Int, Int, Int)] = [
(0xE0, 0x5A, 0x4F), (0xE8, 0x92, 0x3A), (0xD9, 0xB5, 0x2E), (0x4F, 0xAE, 0x6B),
(0x2F, 0xA8, 0xA0), (0x3D, 0x8B, 0xE0), (0x7C, 0x5C, 0xD6), (0xC4, 0x55, 0xA8),
]
///|
fn hash(s : String) -> Int {
let mut h = 5381
for c in s {
h = (h * 33 + c.to_int()) & 0x7FFFFFF
}
h
}
///| Colour of an app's tile.
pub fn tile_color(id : String) -> @types.Color {
let (r, g, b) = hues[hash(id) % hues.length()]
@ui.color(r, g, b, 255)
}
///| Draw the dock into `size`. `hover` is the hovered tile index or -1.
pub fn render(
size : @types.Size,
t : @theme.Tokens,
apps : Array[@types.AppEntry],
hover : Int,
) -> Array[@types.DrawOp] {
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let r = t.radius.reinterpret_as_int()
let n = if apps.length() > max_tiles { max_tiles } else { apps.length() }
let ops : Array[@types.DrawOp] = [
@ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface, radius=r + 4),
]
if n == 0 {
ops.push(
@ui.text(w / 2, h / 2, "No apps", t.font_size.reinterpret_as_int() - 2, t.palette.foreground_muted, align=CENTER),
)
return ops
}
let white = @ui.color(255, 255, 255, 255)
for i = 0; i < n; i = i + 1 {
let s = tile_size(i, hover, h)
let cx = pad + i * pitch(h) + base_size(h) / 2
let x = cx - s / 2
let y = (h - s) / 2
let c = tile_color(apps[i].id)
let fill = if i == hover { @ui.lerp_color(c, white, 1, 5) } else { c }
ops.push(@ui.fill_rect(@ui.rect(x, y, s, s), fill, radius=s / 4))
ops.push(
@ui.text(cx, h / 2, apps[i].glyph, s * 11 / 20, white, align=CENTER, bold=true),
)
}
ops
}
///| Name shown for tile `i` (used for the hover tooltip popup).
pub fn tile_name(apps : Array[@types.AppEntry], i : Int) -> String {
if i >= 0 && i < apps.length() && i < max_tiles {
apps[i].name
} else {
""
}
}
///| Pointer events -> (new hover, redraw?, app id to launch). Pure so it can be tested.
pub fn handle(
apps : Array[@types.AppEntry],
hover : Int,
h : Int,
event : @types.InputEvent,
) -> (Int, Bool, String?) {
match event {
PointerMove(p) => {
let i = tile_at(apps.length(), h, p.x, p.y)
(i, i != hover, None)
}
PointerLeave => (-1, hover != -1, None)
PointerDown(p) => {
let i = tile_at(apps.length(), h, p.x, p.y)
if i >= 0 {
(i, true, Some(apps[i].id))
} else {
(hover, false, None)
}
}
_ => (hover, false, None)
}
}
+57
View File
@@ -0,0 +1,57 @@
///|
fn apps() -> Array[@types.AppEntry] {
["a", "b", "c"].map(id => { id, name: id + "!", comment: "", category: "", glyph: id.to_upper() })
}
///|
test "tiles hit-test by slot and grow around the hovered one" {
let h = 34
assert_eq(tile_at(3, h, 0, 10), -1)
assert_eq(tile_at(3, h, 12, 10), 0)
assert_eq(tile_at(3, h, 12 + pitch(h), 10), 1)
assert_eq(tile_at(3, h, 12 + 5 * pitch(h), 10), -1)
assert_true(tile_size(1, 1, h) > tile_size(0, 1, h))
assert_eq(tile_size(2, 0, h), base_size(h))
}
///|
test "click launches the app under the pointer; move sets hover" {
let a = apps()
let (hv, redraw, launch) = handle(a, -1, 34, PointerMove({ x: 12, y: 10 }))
assert_eq(hv, 0)
assert_true(redraw)
assert_true(launch is None)
let (_, _, launch) = handle(a, hv, 34, PointerDown({ x: 12 + pitch(34), y: 10 }))
assert_eq(launch, Some("b"))
let (hv, redraw, _) = handle(a, 0, 34, PointerLeave)
assert_eq(hv, -1)
assert_true(redraw)
}
///|
test "render draws one tile and glyph per app, capped at max_tiles" {
let t : @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,
}
assert_eq(render(@ui.size(preferred_width(3), 34), t, apps(), -1).length(), 1 + 3 * 2)
let many = Array::makei(20, i => ({ id: i.to_string(), name: "n", comment: "", category: "", glyph: "x" } : @types.AppEntry))
assert_eq(render(@ui.size(300, 34), t, many, 2).length(), 1 + max_tiles * 2)
assert_eq(tile_name(apps(), 1), "b!")
assert_eq(tile_name(apps(), 9), "")
}
+5
View File
@@ -0,0 +1,5 @@
import {
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
"moonplasma/desktop/lib/ui" @ui,
}