diff --git a/docs/test-checklist.md b/docs/test-checklist.md index 2be5fbe..122d18a 100644 --- a/docs/test-checklist.md +++ b/docs/test-checklist.md @@ -141,7 +141,7 @@ image, a cancel brought the thumbnail back, and a swipe still dismissed it. ## Polish -- [ ] Region: while dragging, a `W × H` label follows the pointer (physical pixels, same as the saved PNG), flipping near the edges. +- [ ] Region: while dragging, a square-cornered `W × H` label follows the pointer (physical pixels, same as the saved PNG), flipping near the edges. - [ ] Shift locks the dimension you move first; Alt grows from the centre; Space held moves the selection, and after letting go resizing continues without a jump; Space before a drag still switches to window mode. - [ ] `[capture] window_shadow = true`: window shots get a soft shadow following the rounded corners; preview, clipboard and file all have it. - [ ] Each shot is a two-hit "ka-chunk" (macOS-like) with a metallic clatter that grows from shot 2; shots in quick succession play sounds 1 → 5 getting faster and brighter, then 6, 7, 6, 7 (a climbing bell arpeggio over a glide) rising endlessly; every shot about as loud; after a 5 s pause it starts at 1 again. `valw __combo-demo` plays the whole sequence for tuning. diff --git a/src/region.rs b/src/region.rs index 87ee4e9..c163919 100644 --- a/src/region.rs +++ b/src/region.rs @@ -178,7 +178,8 @@ impl Surface { ((crate::toolbar::draw::measure(&text) + 12.0) as f64 * scale).ceil() as u32, ((crate::toolbar::draw::LABEL * 1.2 + 12.0) as f64 * scale).ceil() as u32, ); - let pill = crate::toolbar::draw::pill(size, scale as f32, &text); + // Square corners: sharp, like the rest of the shell. + let pill = crate::toolbar::draw::pill(size, scale as f32, &text, 0.0); let at = render::label_origin( (px * scale, py * scale), (pill.width(), pill.height()), diff --git a/src/toolbar/draw.rs b/src/toolbar/draw.rs index 5ebd051..3d8e4b9 100644 --- a/src/toolbar/draw.rs +++ b/src/toolbar/draw.rs @@ -7,7 +7,7 @@ use crate::toolbar::layout::{Layout, MenuItem, Rect, Target}; use crate::toolbar::state::ToolbarState; pub const LABEL: f32 = 13.0; -const RADIUS: f32 = 12.0; +pub const RADIUS: f32 = 12.0; const BACKGROUND: [u8; 4] = [0x1c, 0x1c, 0x1e, 230]; const SELECTED: [u8; 4] = [255, 255, 255, 46]; const HOVER: [u8; 4] = [255, 255, 255, 26]; @@ -130,8 +130,9 @@ pub fn bar( p } -/// The countdown pill: a rounded background with `text` centred. -pub fn pill(size: (u32, u32), scale: f32, s: &str) -> Pixmap { +/// A pill: a background with corners of `radius` and `text` centred (the +/// countdown is rounded, the region's size label square). +pub fn pill(size: (u32, u32), scale: f32, s: &str, radius: f32) -> Pixmap { let mut p = Pixmap::new(size.0.max(1), size.1.max(1)).expect("the pill has a size"); let r = Rect { x: 0.0, @@ -139,7 +140,7 @@ pub fn pill(size: (u32, u32), scale: f32, s: &str) -> Pixmap { w: size.0 as f32 / scale, h: size.1 as f32 / scale, }; - rounded(&mut p, r, RADIUS, BACKGROUND, scale); + rounded(&mut p, r, radius, BACKGROUND, scale); let left = (r.w - measure(s)) / 2.0; label(&mut p, r, left, s, scale); p @@ -220,9 +221,16 @@ mod tests { assert_eq!(out, [30, 20, 10, 255]); } + #[test] + fn a_square_pill_fills_its_corners() { + let corner = |p: &Pixmap| p.pixel(0, 0).unwrap().alpha(); + assert_eq!(corner(&pill((72, 40), 1.0, "5", RADIUS)), 0, "rounded"); + assert!(corner(&pill((72, 40), 1.0, "5", 0.0)) > 200, "square"); + } + #[test] fn the_pill_shows_its_text() { - let p = pill((72, 40), 1.0, "5"); + let p = pill((72, 40), 1.0, "5", RADIUS); let lit = p .pixels() .iter() diff --git a/src/toolbar/mod.rs b/src/toolbar/mod.rs index 93981fd..cf27d01 100644 --- a/src/toolbar/mod.rs +++ b/src/toolbar/mod.rs @@ -380,7 +380,7 @@ impl Pill { (PILL.0 as f64 * self.scale).round() as u32, (PILL.1 as f64 * self.scale).round() as u32, ); - let pixmap = draw::pill((pw, ph), self.scale as f32, &self.text); + let pixmap = draw::pill((pw, ph), self.scale as f32, &self.text, draw::RADIUS); let Ok((buffer, canvas)) = self.pool.create_buffer( pw as i32, ph as i32,