Desktop card: click and drag it around the wallpaper

Press on the card (when no window covers it) to grab it; it follows the pointer,
clamped to the screen, with a hand cursor on hover and grabbing while dragged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-24 23:41:31 -08:00
1 parent 783618b89f
commit bca69d8c90
4 files changed
+100 -6

No files matched your search

+39 -4
View File
@@ -10,7 +10,8 @@ let desktop_widget_h : Int = 120
///|
fn render_desktop_widget(
screen_w : Int,
x0 : Int,
y0 : Int,
tokens : @theme.Tokens,
at : @types.Datetime,
out : Array[@scene.DrawOp],
@@ -38,7 +39,41 @@ fn render_desktop_widget(
tokens.palette.foreground,
),
]
let x0 = screen_w - desktop_widget_w - 24
translate(ops, x0, 24, out)
translate(@moon.render_disc(@ui.size(56, 56), tokens, p), x0 + desktop_widget_w - 56 - 18, 24 + 18, out)
translate(ops, x0, y0, out)
translate(@moon.render_disc(@ui.size(56, 56), tokens, p), x0 + desktop_widget_w - 56 - 18, y0 + 18, out)
}
///| Default top-right position of the card, and the clamp that keeps it on screen.
fn DesktopShell::desk_pos(self : DesktopShell) -> (Int, Int) {
let (x, y) = if self.desk_set {
(self.desk_x, self.desk_y)
} else {
(self.screen_w - desktop_widget_w - 24, 24)
}
let mx = if self.screen_w > desktop_widget_w { self.screen_w - desktop_widget_w } else { 0 }
let my = if self.screen_h > desktop_widget_h { self.screen_h - desktop_widget_h } else { 0 }
(if x < 0 { 0 } else if x > mx { mx } else { x }, if y < 0 { 0 } else if y > my { my } else { y })
}
///| True if (x, y) is over the desktop card.
pub fn DesktopShell::desk_hit(self : DesktopShell, x : Int, y : Int) -> Bool {
let (cx, cy) = self.desk_pos()
x >= cx && x < cx + desktop_widget_w && y >= cy && y < cy + desktop_widget_h
}
///| Start dragging the card if the press is on it. Call only when no window covers (x, y).
pub fn DesktopShell::desk_press(self : DesktopShell, x : Int, y : Int) -> Bool {
if !self.desk_hit(x, y) {
return false
}
let (cx, cy) = self.desk_pos()
self.desk_drag = true
self.desk_off_x = x - cx
self.desk_off_y = y - cy
true
}
///| True while the card is being dragged.
pub fn DesktopShell::desk_dragging(self : DesktopShell) -> Bool {
self.desk_drag
}