hex/src/rune_ui/screenshot_thumbnail/card.rs
Kit Langton a65a5e375f
feat(screenshots): record the screen, and keep captures until you close them (#1371)
* Talk over a screenshot: dictation words go with the shot

* Regenerate the screenshot editor goldens with the words row

* Cover the card held while someone talks over it

* Add the listening card's goldens

* Record the screen from Screenshots, ending in the corner card and a trim editor

* Move the capture timeline out, add the recording goldens and feature map

* Keep the replay's start on Windows quiet

* Keep the timeline move's imports and the replay start quiet off macOS

* Clear the record shortcut without returning its change

* Fix the macOS lints the recording left

* screenshots: only the open editor takes a dictation

A dictation taken while only the corner card showed used to talk over the
shot: the card held, showed "Listening…", and the words opened the shot in
the editor. That took the shortcut's normal paste away from everyone who
never asked for it.

Now only an open editor takes the words. While the card shows, a dictation
pastes as it did before the Lab, the card keeps its few seconds, and its
listening pill, hold and the narration path that opened the shot are gone.
The card's own card/listen/heard API goes with it, so nothing else can reach
the shot but the editor.

The i18n Screenshots rows move to i18n/labs.rs, where the Labs rows live,
so the main table stays under the source cap after dev's merge.

* screenshots: the editor's pieces come from the kit, and a shot grows in from where it was taken

The editor's toolbar was hand-made: five canvas-drawn tool glyphs in bespoke
hover chips, a bare ✕, a bare microphone, and action buttons stretched past
the kit's own height. The card's ✕ was a filled button beside them. They now
come from the rest of Hex: the tools are line icons beside the theme's own,
drawn by rune-kit icon buttons that fill while a tool is picked, ✕ and the
microphone and clear-words are the kit's ghost icon buttons like a capsule's,
and Copy, Save and Send to… are the kit's buttons at their own size. The
trim handles take the kit's corner.

A shot now grows in from the rectangle it was taken from. The card's overlay
is the whole display, so it can start anywhere on it: an area or window shot
starts at exactly the rectangle captured, at that size and place, and springs
into its corner slot on one spring that never overshoots its size, leaving
the same way. A whole-display shot keeps the slide in from the edge, and
Reduce Motion still only fades.

* screenshots: regenerate the editor and card goldens for the look pass

* docs: the card grows in from the shot's rectangle, and the editor is the kit's

* screenshots: a recording saves itself to the screenshots folder, as a shot does

* screenshots: cards stay until closed, stack in the corner, and take CleanShot's keys

* screenshots: Restore Last Capture in the menu bar brings back the card closed last

* screenshots: a Captures pane lists the last 30 days of shots and recordings

* screenshots: goldens for the card stack and the Captures pane, and its playground paths

* screenshots: the card's Return and the editor's file are macOS-only

* screenshots: pin that cards of any shape share the corner's right edge

* screenshots: keep macos_rune.rs and app_settings.rs under the file cap
2026-11-09 08:18:56 -08:00

167 lines
5.8 KiB
Rust

//! How the stack draws: each card in its slot, the newest in the corner.
use rune::{Anim, Cursor, Cx, El, PopupItem, PopupMenu, Spring, SpringPair, Transition, Tx, el};
use rune_kit::{ControlSize, IconButton, IconButtonVariant};
use super::{
CLOSE_INSET, CLOSE_RADIUS, CardKey, Cards, ENTER, Entry, FADE, INSET, LEAVE, PILL_H, RADIUS,
REDUCED, TRAVEL_SCALE, ZOOM,
};
use crate::desktop::i18n::tr;
use crate::rune_ui::controls::Paint;
static CLOSE: &rune::Icon = &rune_theme_opencode::icons::CLOSE;
pub(crate) fn view(s: &Cards, cx: &mut Cx<Cards>) -> El {
let p = Paint::new(cx.system_dark(), cx.env().scale);
let (sw, sh) = s.screen;
let reduced = cx.is_reduced_motion();
let mut root = el()
.key("screenshot-thumbnail")
.size(sw, sh)
.hover_motion_within(Anim::INSTANT, Anim::INSTANT);
for (card, (id, rect)) in s.cards.iter().zip(s.slots()) {
debug_assert_eq!(card.id, id);
root = root.child(entry(p, card, rect, s.hovered == Some(id), reduced));
}
root
}
/// One card at `rect`.
fn entry(p: Paint, card: &Entry, rect: [f32; 4], hovered: bool, reduced: bool) -> El {
let k = p.k;
let id = card.id;
let [x, y, w, h] = rect;
let mut shell = el()
.key(format!("card-{id}"))
.absolute(x, y)
.size(w, h)
.radius(RADIUS)
.fill(k.c.bg_base);
for shadow in &k.elevation.floating {
shell = shell.box_shadow(*shadow);
}
let close = IconButton::new(CLOSE)
.variant(IconButtonVariant::Ghost)
.control_size(ControlSize::Small)
.label(tr("Close"))
.on_press_tx(move |s: &mut Cards, tx| s.close(id, tx))
.build(k)
.key("close")
.absolute(CLOSE_INSET, CLOSE_INSET)
.opacity(if hovered { 1.0 } else { 0.0 })
.opacity_motion(FADE);
// A note ("Copied") stands in for a recording's length while it shows.
let pill = match (&card.note, &card.shot.recording) {
(Some((note, _)), _) => Some(label(p, note.clone())),
(None, Some(recording)) => Some(label(
p,
super::editor::clip::duration_label(recording.duration_ms),
)),
(None, None) => None,
}
.map(|pill| {
pill.key("pill")
.absolute(CLOSE_INSET, h - CLOSE_INSET - PILL_H)
});
let shell = shell
.pixels_fit(card.shot.image.pixels(), rune::SurfaceFit::Fit)
.cursor(Cursor::Pointer)
.on_press_tx(move |s: &mut Cards, tx| s.open(id, tx))
.on_secondary_press(move |_: &mut Cards, press, tx| menu(id, press, tx))
.drag_out(move |s: &Cards| {
s.get(id)
.map(|card| rune::DragItem::new().file(card.shot.path.clone()))
})
.child(
el().absolute(0.0, 0.0)
.size(w, h)
.radius(RADIUS)
.border(p.hair, k.c.border_weak),
)
.hit()
.on_hover_change(move |s: &mut Cards, on, tx| {
if on {
s.hover(Some(id));
} else if s.hovered == Some(id) {
s.hover(None);
}
tx.animated();
})
// The older cards make room on the HUD's spring; Reduce Motion
// moves them at once.
.motion(if reduced { Spring::NONE } else { ENTER })
.transition(travel(card, rect, reduced))
.child(close);
match pill {
Some(pill) => shell.child(pill),
None => shell,
}
}
/// How a card comes and goes. A shot grows in from the rectangle it was
/// taken from, at that rectangle's size and place, and shrinks into its
/// slot; without one (a whole display, a recording, or once it has been in
/// a moment) it comes and goes past the display's right edge, leaning back
/// about the corner it rests in. Reduce Motion only fades.
fn travel(card: &Entry, [x, y, w, _]: [f32; 4], reduced: bool) -> Transition {
if reduced {
Transition::opacity().springs(SpringPair::new(REDUCED, REDUCED))
} else if let Some([cx0, cy0, cw, _]) = card.capture {
let scale = (cw / w).max(0.02);
Transition::offset(cx0 - x, cy0 - y)
.combined(Transition::scale_anchor(scale, rune::Vec2::new(0.0, 0.0)))
.springs(SpringPair::new(ZOOM, LEAVE))
} else {
Transition::offset(w + INSET, 0.0)
.combined(Transition::scale_anchor(
TRAVEL_SCALE,
rune::Vec2::new(1.0, 1.0),
))
.springs(SpringPair::new(ENTER, LEAVE))
}
}
/// The card's right-click menu.
fn menu(id: u64, press: rune::PointerPress, tx: &mut Tx) {
let menu = PopupMenu::new()
.item(PopupItem::new("edit", tr("Open in Editor")))
.item(PopupItem::new("copy", tr("Copy")))
.item(PopupItem::new("reveal", tr("Show in Finder")))
.separator()
.item(PopupItem::new("trash", tr("Move to Trash")))
.item(PopupItem::new("close", tr("Close")));
tx.popup_menu(menu, press, move |s: &mut Cards, picked, tx| {
let key = match picked {
Some("edit") => CardKey::Edit,
Some("copy") => CardKey::Copy,
Some("reveal") => CardKey::Reveal,
Some("trash") => CardKey::Trash,
Some("close") => CardKey::Close,
_ => return,
};
s.act(id, key, tx);
});
}
/// A short label in the card's bottom-left corner: a recording's length,
/// or a note.
fn label(p: Paint, text: String) -> El {
let k = p.k;
let mut pill = rune::row()
.h(PILL_H)
.px(8.0)
.gap(6.0)
.center_y()
.radius(CLOSE_RADIUS)
.fill(k.c.bg_base);
for shadow in &k.elevation.floating {
pill = pill.box_shadow(*shadow);
}
pill.child(
rune::text(text)
.font(crate::rune_ui::capture_capsule::surface::small())
.color(p.text())
.single_line(),
)
}