Face unlock window: live camera preview, Snap, thumbnails, one password on Apply
CI / test (push) Failing after 12m30s
CI / test (push) Failing after 12m30s
Settings > Session "Add or remove faces…" (and "Remove…" on a face) opens a compositor-drawn Face unlock window instead of running root steps one by one: - chandra-face camera runs as the user (no password): it streams a small live picture with the face box and a cropped thumbnail per snap; the snaps' embeddings stay in that process, nothing is written to disk. - Click a snap to drop it; mark saved faces Remove/Keep. - Apply saves the snaps as one face and removes the marked ones in one root `chandra-face apply` (JSON on stdin, validated) through run0/pkexec: one password prompt. - New raster host function image-pixels (host-wasm, wasmhost, native) for the window's pictures. Tests: camera session and apply in face/test_face.py; the window end to end against a fake tool in compositor/host/face_test.mbt. Docs explain why the change itself still needs root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
This commit is contained in:
74 files changed
+2617
-89
No files matched your search
@@ -193,6 +193,10 @@ pub(all) struct ChandraCompositor {
|
||||
mut polkit_bus : String
|
||||
mut auth : AuthUi?
|
||||
auth_swallow : Array[UInt]
|
||||
/// The Face unlock window (face_window.mbt): where its controls were drawn, and the change of
|
||||
/// it last drawn.
|
||||
face_hits : Array[(@scene.Rect, FaceHit)]
|
||||
mut face_rev : Int
|
||||
mut auth_routes : Array[@polkit.HelperRoute]
|
||||
mut keymap : (Bytes, @polkit.Keymap)?
|
||||
/// How requests are put into words (tests pass their own process lookups); None: the usual.
|
||||
@@ -236,6 +240,8 @@ pub fn ChandraCompositor::new(
|
||||
polkit_bus: "",
|
||||
auth: None,
|
||||
auth_swallow: [],
|
||||
face_hits: [],
|
||||
face_rev: -1,
|
||||
auth_routes: [],
|
||||
keymap: None,
|
||||
auth_describe: None,
|
||||
@@ -478,6 +484,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
self.kiosk_tick()
|
||||
self.portal_tick()
|
||||
self.auth_tick()
|
||||
self.face_window_tick()
|
||||
self.control_tick()
|
||||
let events = self.server.poll_events()
|
||||
for ev in events {
|
||||
@@ -906,6 +913,7 @@ fn ChandraCompositor::build_scene(
|
||||
panel_ops.append(self.switcher_ops())
|
||||
}
|
||||
panel_ops.append(self.screenshot_ops())
|
||||
panel_ops.append(self.face_window_ops())
|
||||
panel_ops.append(self.auth_ops())
|
||||
self.frames_built = self.frames_built + 1
|
||||
self.run_shell_actions()
|
||||
@@ -1506,6 +1514,10 @@ pub fn ChandraCompositor::handle_input(
|
||||
if self.auth_input(ev) {
|
||||
return
|
||||
}
|
||||
// So does the Face unlock window (below the password dialog it opens on Apply).
|
||||
if self.face_window_input(ev) {
|
||||
return
|
||||
}
|
||||
match ev {
|
||||
Key(code, pressed) => {
|
||||
self.track_modifier_key(code, pressed)
|
||||
@@ -1868,6 +1880,9 @@ pub fn ChandraCompositor::desired_cursor(self : ChandraCompositor) -> UInt {
|
||||
Some(ui) => return self.auth_cursor(ui)
|
||||
None => ()
|
||||
}
|
||||
if self.shell.face.window is Some(_) {
|
||||
return if self.face_window_hit() is Some(_) { 4U } else { 1U }
|
||||
}
|
||||
match self.shot {
|
||||
Some(o) => return self.overlay_cursor(o)
|
||||
None => ()
|
||||
|
||||
@@ -20,6 +20,27 @@ fn fake_face_tool(dir : String) -> String {
|
||||
#|remove)
|
||||
#| grep -v "^face $2 " "$S/faces" > "$S/faces.new"; mv "$S/faces.new" "$S/faces"
|
||||
#| echo "done Removed face $2" ;;
|
||||
#|camera)
|
||||
#| # The Face unlock window's camera: a grey 4x3 picture with a face box, a white 2x2
|
||||
#| # thumbnail per snap, and an apply that changes the faces file.
|
||||
#| pic() { printf 'frame 4 3 1 0 2 2 36\n'; head -c 36 /dev/zero | tr '\000' '\200'; }
|
||||
#| echo "info Look at the camera and press Snap"; pic
|
||||
#| n=0; kept=0
|
||||
#| while read -r cmd arg; do
|
||||
#| case "$cmd" in
|
||||
#| snap) n=$((n+1)); kept=$((kept+1)); printf 'snap %d 2 2 12\n' $n; head -c 12 /dev/zero | tr '\000' '\377'; pic ;;
|
||||
#| drop) kept=$((kept-1)); pic ;;
|
||||
#| apply)
|
||||
#| echo "info Waiting for the password…"
|
||||
#| for id in $(echo "$arg" | tr ',' ' '); do
|
||||
#| grep -v "^face $id " "$S/faces" > "$S/faces.new"; mv "$S/faces.new" "$S/faces"
|
||||
#| done
|
||||
#| [ $kept -gt 0 ] && printf 'face 2\tFace 2\t2026-11-26\n' >> "$S/faces"
|
||||
#| echo "$kept $arg" > "$S/applied"
|
||||
#| echo "done Added Face 2 and removed 1 face"; echo "applied 0"; exit 0 ;;
|
||||
#| quit) exit 0 ;;
|
||||
#| esac
|
||||
#| done ;;
|
||||
#|pam)
|
||||
#| if [ "$2" = enable ]; then echo "polkit-1,sudo" > "$S/pam"; else : > "$S/pam"; fi
|
||||
#| echo "done ok" ;;
|
||||
@@ -65,7 +86,7 @@ fn face_click(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit
|
||||
}
|
||||
|
||||
///|
|
||||
test "Settings > Session: face unlock lists faces, adds one, turns it on, removes one" {
|
||||
test "Settings > Session: face unlock lists faces and turns it on" {
|
||||
let dir = "/tmp/chandra-face-test-" + @sys.getpid().to_string()
|
||||
let tool = fake_face_tool(dir)
|
||||
let comp = new_comp("face")
|
||||
@@ -77,12 +98,8 @@ test "Settings > Session: face unlock lists faces, adds one, turns it on, remove
|
||||
assert_true(texts.contains("Face unlock"))
|
||||
assert_true(texts.contains("Use my face for passwords"))
|
||||
assert_true(texts.contains("added 2026-11-20"))
|
||||
assert_true(texts.contains("Add a face…"))
|
||||
assert_true(texts.contains("Add or remove faces…"))
|
||||
assert_false(comp.shell.face.in_use())
|
||||
// Add a face: the tool's progress shows, then the new face.
|
||||
face_click(comp, "Add a face…", 10U)
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Face 2") }))
|
||||
assert_true(face_texts(comp).contains("Added Face 2"))
|
||||
// The switch: polkit-1 and sudo try the face first.
|
||||
face_click(comp, "Use my face for passwords", 20U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.in_use() }))
|
||||
@@ -90,13 +107,57 @@ test "Settings > Session: face unlock lists faces, adds one, turns it on, remove
|
||||
if shots != "" {
|
||||
ignore(@sys.write_file_bytes(shots + "/16-settings-face.png", @renderer.encode_png_compressed(comp.compose_frame())))
|
||||
}
|
||||
// Remove takes a second click.
|
||||
face_click(comp, "Remove", 30U)
|
||||
assert_true(face_texts(comp).contains("Click again to remove"))
|
||||
assert_eq(comp.shell.face.faces.length(), 2)
|
||||
face_click(comp, "Click again to remove", 40U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.faces.length() == 1 }))
|
||||
assert_eq(comp.shell.face.faces[0].1, "Face 2")
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
fn face_key(comp : @host.ChandraCompositor, code : UInt, t : UInt) -> Unit {
|
||||
comp.handle_input(@nested.InputEvent::Key(code, true), t)
|
||||
comp.handle_input(@nested.InputEvent::Key(code, false), t + 1U)
|
||||
ignore(comp.compose_frame())
|
||||
}
|
||||
|
||||
///|
|
||||
test "the Face unlock window: live picture, snaps, a face marked for removal, one Apply" {
|
||||
let dir = "/tmp/chandra-face-win-" + @sys.getpid().to_string()
|
||||
let tool = fake_face_tool(dir)
|
||||
let comp = new_comp("facewin")
|
||||
comp.shell.set_face_tool(["/bin/sh", tool])
|
||||
assert_true(comp.shell.open_settings(Session))
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Desk") }))
|
||||
// "Remove…" on a face opens the window with that face marked; nothing is removed yet.
|
||||
face_click(comp, "Remove…", 10U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
|
||||
let w = comp.shell.face.window.unwrap()
|
||||
assert_eq(w.remove, ["1"])
|
||||
assert_eq((w.pic_w, w.pic_h, w.face_box), (4, 3, Some((1, 0, 2, 2))))
|
||||
assert_eq(w.message, "Look at the camera and press Snap")
|
||||
// Space snaps (the window has the keyboard), twice; one snap is dropped again.
|
||||
face_key(comp, 57U, 20U)
|
||||
assert_true(face_settle(comp, fn() { w.snaps.length() == 1 }))
|
||||
face_key(comp, 57U, 30U)
|
||||
assert_true(face_settle(comp, fn() { w.snaps.length() == 2 }))
|
||||
assert_eq(w.message, "2 pictures: snap more, or press Apply")
|
||||
comp.shell.face.drop_snap(0)
|
||||
assert_eq(w.snaps.map(s => s.id), ["2"])
|
||||
assert_eq(w.message, "1 picture: turn a little and snap again, or press Apply")
|
||||
let shots = @sys.getenv("CHANDRA_AUTH_SHOTS")
|
||||
if shots != "" {
|
||||
ignore(@sys.write_file_bytes(shots + "/17-face-window.png", @renderer.encode_png_compressed(comp.compose_frame())))
|
||||
}
|
||||
assert_eq(comp.shell.face.faces.length(), 1)
|
||||
// Enter applies: one run for the snap and the removal; the window closes, Settings shows it.
|
||||
face_key(comp, 28U, 40U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window is None }))
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Face 2") }))
|
||||
assert_eq(comp.shell.face.faces.map(f => f.1), ["Face 2"])
|
||||
assert_eq(comp.shell.face.message, "Added Face 2 and removed 1 face")
|
||||
assert_eq(@sys.read_file_bytes(dir + "/applied") |> @utf8.decode_lossy, "1 1\n")
|
||||
// Esc cancels without changing anything.
|
||||
face_click(comp, "Add or remove faces…", 50U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window is Some(_) }))
|
||||
face_key(comp, 1U, 60U)
|
||||
assert_true(comp.shell.face.window is None)
|
||||
comp.close()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
///| The Face unlock window (docs/face-unlock.md): Settings > Session > "Add or remove faces…"
|
||||
/// opens it. A live camera picture with the face box, Snap to keep the picture in view (its
|
||||
/// thumbnail shows below; click one to drop it), the saved faces with Remove / Keep, and Apply,
|
||||
/// which saves the snaps and removes the marked faces in one root step: polkit asks for the
|
||||
/// password once, in the password dialog drawn above this window.
|
||||
///
|
||||
/// The camera runs as the user (`chandra-face camera`, compositor/shell/face.mbt); the pictures
|
||||
/// only live in memory, and only the face data (embeddings) is saved.
|
||||
///
|
||||
/// Like the password dialog it is drawn by the compositor above the windows, on a dimmed
|
||||
/// screen, and takes the keyboard and the pointer while it is up: Space snaps, Enter applies,
|
||||
/// Esc cancels.
|
||||
|
||||
///| A control of the window.
|
||||
pub(all) enum FaceHit {
|
||||
Snap
|
||||
DropSnap(Int)
|
||||
ToggleFace(String)
|
||||
Apply
|
||||
Cancel
|
||||
} derive(Eq)
|
||||
|
||||
///| Follow the camera process and redraw when the window changed.
|
||||
fn ChandraCompositor::face_window_tick(self : ChandraCompositor) -> Unit {
|
||||
let f = self.shell.face
|
||||
f.poll_window()
|
||||
if f.window_rev != self.face_rev {
|
||||
self.face_rev = f.window_rev
|
||||
self.damage.mark_full()
|
||||
}
|
||||
}
|
||||
|
||||
///| The control under the pointer.
|
||||
fn ChandraCompositor::face_window_hit(self : ChandraCompositor) -> FaceHit? {
|
||||
let x = self.ptr_x.to_int()
|
||||
let y = self.ptr_y.to_int()
|
||||
for h in self.face_hits {
|
||||
let r = h.0
|
||||
if x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h {
|
||||
return Some(h.1)
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///| Do what control `h` does.
|
||||
fn ChandraCompositor::face_window_activate(self : ChandraCompositor, h : FaceHit) -> Unit {
|
||||
let f = self.shell.face
|
||||
match h {
|
||||
Snap => f.snap()
|
||||
DropSnap(i) => f.drop_snap(i)
|
||||
ToggleFace(id) => f.toggle_remove(id)
|
||||
Apply => f.apply()
|
||||
Cancel => f.cancel_window()
|
||||
}
|
||||
self.damage.mark_full()
|
||||
}
|
||||
|
||||
///| Input while the window is up: all of it goes to the window.
|
||||
fn ChandraCompositor::face_window_input(self : ChandraCompositor, ev : @nested.InputEvent) -> Bool {
|
||||
if self.shell.face.window is None {
|
||||
return false
|
||||
}
|
||||
match ev {
|
||||
Key(code, pressed) => {
|
||||
if code == key_lsuper || code == key_rsuper {
|
||||
self.super_solo = false
|
||||
}
|
||||
if pressed {
|
||||
self.auth_swallow.push(code)
|
||||
if code == key_esc {
|
||||
self.face_window_activate(Cancel)
|
||||
} else if code == key_enter || code == key_kp_enter {
|
||||
self.face_window_activate(Apply)
|
||||
} else if code == key_space {
|
||||
self.face_window_activate(Snap)
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Modifiers(_, _, _, _) => true
|
||||
PointerMove(x, y) => {
|
||||
self.ptr_x = x
|
||||
self.ptr_y = y
|
||||
self.damage.mark_full()
|
||||
true
|
||||
}
|
||||
PointerButton(button, pressed) => {
|
||||
if pressed && button == 272U {
|
||||
match self.face_window_hit() {
|
||||
Some(h) => self.face_window_activate(h)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Scroll(_, _, _) => true
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
let key_space : UInt = 57
|
||||
|
||||
///| The window, when it is open.
|
||||
fn ChandraCompositor::face_window_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
|
||||
let ops : Array[@scene.DrawOp] = []
|
||||
let f = self.shell.face
|
||||
let win = match f.window {
|
||||
Some(w) => w
|
||||
None => {
|
||||
self.face_hits.clear()
|
||||
return ops
|
||||
}
|
||||
}
|
||||
let p = self.theme.palette
|
||||
let (err_c, _) = auth_colors(p)
|
||||
let fs = self.theme.font_size
|
||||
let rad = self.theme.radius + 2
|
||||
let sw = self.output_w
|
||||
let sh = self.output_h
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), @scene.Rgba::new(0, 0, 0, 150), 0))
|
||||
let w = (sw - 32).min(560)
|
||||
let pad = 24
|
||||
let inner = w - pad * 2
|
||||
let hover = self.face_window_hit()
|
||||
let body : Array[@scene.DrawOp] = []
|
||||
let hits : Array[(@scene.Rect, FaceHit)] = []
|
||||
let mut y = pad
|
||||
body.push(@scene.DrawOp::Text(pad, y + 7, "FACE UNLOCK", fs - 3, p.accent, @scene.TextAlign::Left, true))
|
||||
y = y + 18
|
||||
body.push(@scene.DrawOp::Text(pad, y + (fs + 8) / 2, "Add or remove faces", fs + 3, p.foreground, @scene.TextAlign::Left, true))
|
||||
y = y + fs + 10
|
||||
let intro = "Snap a few pictures: straight on, turned a little, with and without glasses. " +
|
||||
"Pictures stay in memory; Apply saves only the face data, after one password."
|
||||
for l in wrap_text(intro, fs - 1, false, false, inner) {
|
||||
body.push(@scene.DrawOp::Text(pad, y + (fs + 4) / 2, l, fs - 1, p.foreground_muted, @scene.TextAlign::Left, false))
|
||||
y = y + fs + 4
|
||||
}
|
||||
y = y + 12
|
||||
// The live picture, as big as fits (4:3 until the first one says otherwise).
|
||||
let (aw, ah) = if win.pic_w > 0 && win.pic_h > 0 { (win.pic_w, win.pic_h) } else { (4, 3) }
|
||||
let max_h = (sh * 2 / 5).max(120)
|
||||
let mut pw = inner
|
||||
let mut ph = pw * ah / aw
|
||||
if ph > max_h {
|
||||
ph = max_h
|
||||
pw = ph * aw / ah
|
||||
}
|
||||
let pr = @scene.Rect::new(pad + (inner - pw) / 2, y, pw, ph)
|
||||
body.push(@scene.DrawOp::FillRect(pr, @scene.Rgba::new(16, 16, 18, 255), rad))
|
||||
if win.picture != 0U && !win.ended {
|
||||
body.push(@scene.DrawOp::Image(pr, win.picture))
|
||||
match win.face_box {
|
||||
Some((bx, by, bw, bh)) => {
|
||||
let r = @scene.Rect::new(pr.x + bx * pw / win.pic_w, pr.y + by * ph / win.pic_h, bw * pw / win.pic_w, bh * ph / win.pic_h)
|
||||
body.push(@scene.DrawOp::StrokeRect(r, p.accent, 2, 6))
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
} else {
|
||||
face_glyph(pr.x + pw / 2, pr.y + ph / 2 - 12, 22, @scene.Rgba::new(120, 120, 128, 255), body)
|
||||
let t = if win.ended { "No camera picture" } else { "Starting the camera…" }
|
||||
body.push(@scene.DrawOp::Text(pr.x + pw / 2, pr.y + ph / 2 + 30, t, fs - 1, @scene.Rgba::new(200, 200, 205, 255), @scene.TextAlign::Center, false))
|
||||
}
|
||||
y = y + ph + 12
|
||||
// What the camera said, and Snap.
|
||||
let bh = 34
|
||||
let snap_w = @renderer.text_width("Snap", fs, true, false) + 40
|
||||
let sr = @scene.Rect::new(pad + inner - snap_w, y, snap_w, bh)
|
||||
let can_snap = !win.applying && !win.ended && win.picture != 0U
|
||||
auth_button(sr, "Snap", true, false, hover == Some(Snap), can_snap, p, fs, rad, body)
|
||||
if can_snap {
|
||||
hits.push((sr, Snap))
|
||||
}
|
||||
let msg_lines = wrap_text(win.message, fs - 1, false, false, inner - snap_w - 12)
|
||||
let mut my = y + bh / 2 - (msg_lines.length() - 1) * (fs + 3) / 2
|
||||
for l in msg_lines {
|
||||
body.push(@scene.DrawOp::Text(pad, my, l, fs - 1, if win.error { err_c } else { p.foreground }, @scene.TextAlign::Left, false))
|
||||
my = my + fs + 3
|
||||
}
|
||||
y = y + bh.max(msg_lines.length() * (fs + 3)) + 14
|
||||
// The snaps: click one to drop it.
|
||||
if win.snaps.length() > 0 {
|
||||
body.push(@scene.DrawOp::Text(pad, y + 8, "New pictures (click one to drop it)", fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))
|
||||
y = y + 20
|
||||
let ts = 64
|
||||
let gap = 8
|
||||
let per_row = ((inner + gap) / (ts + gap)).max(1)
|
||||
for i, s in win.snaps {
|
||||
let r = @scene.Rect::new(pad + i % per_row * (ts + gap), y + i / per_row * (ts + gap), ts, ts)
|
||||
body.push(@scene.DrawOp::Image(r, s.image))
|
||||
let hov = hover == Some(DropSnap(i))
|
||||
body.push(@scene.DrawOp::StrokeRect(r, if hov { err_c } else { p.border }, if hov { 2 } else { 1 }, 4))
|
||||
if hov {
|
||||
// A cross over it: this one goes.
|
||||
body.push(@scene.DrawOp::Circle(r.x + ts - 10, r.y + 10, 8, err_c, true))
|
||||
body.push(@scene.DrawOp::Line(r.x + ts - 13, r.y + 7, r.x + ts - 7, r.y + 13, p.surface_popup, 2))
|
||||
body.push(@scene.DrawOp::Line(r.x + ts - 7, r.y + 7, r.x + ts - 13, r.y + 13, p.surface_popup, 2))
|
||||
}
|
||||
if !win.applying {
|
||||
hits.push((r, DropSnap(i)))
|
||||
}
|
||||
}
|
||||
y = y + (win.snaps.length() + per_row - 1) / per_row * (ts + gap) + 8
|
||||
}
|
||||
// The saved faces, each with Remove / Keep.
|
||||
if f.faces.length() > 0 {
|
||||
body.push(@scene.DrawOp::Text(pad, y + 8, "Saved faces", fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))
|
||||
y = y + 20
|
||||
let rh = 34
|
||||
for face in f.faces {
|
||||
let (id, label, added) = face
|
||||
let marked = win.remove.contains(id)
|
||||
let btn = if marked { "Keep" } else { "Remove" }
|
||||
let bw = @renderer.text_width("Remove", fs - 1, false, false) + 28
|
||||
let br = @scene.Rect::new(pad + inner - bw, y + 3, bw, rh - 6)
|
||||
face_glyph(pad + 12, y + rh / 2, 9, if marked { p.foreground_muted } else { p.foreground }, body)
|
||||
body.push(@scene.DrawOp::Text(pad + 32, y + rh / 2, label, fs, if marked { p.foreground_muted } else { p.foreground }, @scene.TextAlign::Left, !marked))
|
||||
let lw = @renderer.text_width(label, fs, !marked, false)
|
||||
let note = if marked { "will be removed" } else { "added " + added }
|
||||
body.push(@scene.DrawOp::Text(pad + 32 + lw + 10, y + rh / 2, note, fs - 2, if marked { err_c } else { p.foreground_muted }, @scene.TextAlign::Left, false))
|
||||
if marked {
|
||||
body.push(@scene.DrawOp::Line(pad + 30, y + rh / 2, pad + 34 + lw, y + rh / 2, p.foreground_muted, 1))
|
||||
}
|
||||
auth_button(br, btn, false, false, hover == Some(ToggleFace(id)), !win.applying, p, fs - 1, rad, body)
|
||||
if !win.applying {
|
||||
hits.push((br, ToggleFace(id)))
|
||||
}
|
||||
y = y + rh
|
||||
}
|
||||
y = y + 8
|
||||
}
|
||||
// Footer: what Apply will do, Cancel, Apply.
|
||||
y = y + 6
|
||||
body.push(@scene.DrawOp::Line(pad, y, pad + inner, y, p.border, 1))
|
||||
y = y + 14
|
||||
let adds = win.snaps.length()
|
||||
let rems = win.remove.length()
|
||||
let summary = if win.applying {
|
||||
"Saving…"
|
||||
} else if adds == 0 && rems == 0 {
|
||||
"Nothing to save yet"
|
||||
} else {
|
||||
let parts : Array[String] = []
|
||||
if adds > 0 {
|
||||
parts.push("adds a face from " + adds.to_string() + (if adds == 1 { " picture" } else { " pictures" }))
|
||||
}
|
||||
if rems > 0 {
|
||||
parts.push("removes " + rems.to_string() + (if rems == 1 { " face" } else { " faces" }))
|
||||
}
|
||||
let s = parts.join(", ")
|
||||
"Apply " + s
|
||||
}
|
||||
let apply_w = @renderer.text_width("Apply", fs, true, false) + 40
|
||||
let cancel_w = @renderer.text_width("Cancel", fs, false, false) + 32
|
||||
let ar = @scene.Rect::new(pad + inner - apply_w, y, apply_w, bh)
|
||||
let cr = @scene.Rect::new(ar.x - 10 - cancel_w, y, cancel_w, bh)
|
||||
let sl = wrap_text(summary, fs - 2, false, false, cr.x - pad - 12)
|
||||
let sl = if sl.length() > 2 { sl[:2].to_array() } else { sl }
|
||||
let lh = fs + 2
|
||||
for i, l in sl {
|
||||
body.push(@scene.DrawOp::Text(pad, y + bh / 2 - (sl.length() - 1) * lh / 2 + i * lh, l, fs - 2, p.foreground_muted, @scene.TextAlign::Left, false))
|
||||
}
|
||||
auth_button(cr, "Cancel", false, false, hover == Some(Cancel), !win.applying, p, fs, rad, body)
|
||||
auth_button(ar, "Apply", true, false, hover == Some(Apply), win.can_apply(), p, fs, rad, body)
|
||||
if !win.applying {
|
||||
hits.push((cr, Cancel))
|
||||
}
|
||||
if win.can_apply() {
|
||||
hits.push((ar, Apply))
|
||||
}
|
||||
y = y + bh + pad
|
||||
// Centre the card, with the password dialog's shadow.
|
||||
let h = y
|
||||
let cx = (sw - w) / 2
|
||||
let cyy = ((sh - h) / 2).max(8)
|
||||
for k = 1; k <= 4; k = k + 1 {
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx - k * 2, cyy - k * 2 + 6, w + k * 4, h + k * 4), @scene.Rgba::new(0, 0, 0, 22), rad + 6 + k * 2))
|
||||
}
|
||||
let opaque = @scene.Rgba::new(p.surface_popup.r.to_int(), p.surface_popup.g.to_int(), p.surface_popup.b.to_int(), 255)
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx, cyy, w, h), opaque, rad + 6))
|
||||
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(cx, cyy, w, h), p.border, 1, rad + 6))
|
||||
ops.append(offset_ops_all(body, cx, cyy))
|
||||
self.face_hits.clear()
|
||||
for hit in hits {
|
||||
let r = hit.0
|
||||
self.face_hits.push((@scene.Rect::new(r.x + cx, r.y + cyy, r.w, r.h), hit.1))
|
||||
}
|
||||
ops
|
||||
}
|
||||
Reference in new issue
Block a user