forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

interact.rs694 lines, 31.7 KiBHistoryRawDownload
1//! What a pointer is doing: the drags, the ghosts, the trims and the key repeat.
2
3use crate::*;
4use engine::project::TrimWalls;
5
6/// A library row being dragged: the file and which of its audio streams that
7/// row is, which is the whole of what a row names. Where it lands does not
8/// change what is inserted.
9pub(crate) struct AssetDrag(pub(crate) PathBuf, pub(crate) usize);
10
11/// A clip already on the timeline being dragged: the lane it is on and its index
12/// there, which is how every other edit names a clip. Unlike an [`AssetDrag`]
13/// nothing is inserted -- the same clip changes lane and keeps the frames it
14/// plays -- but where along the bed it is let go is exactly where it lands, less
15/// the offset the hand grabbed it at ([`Player::grab`]).
16#[derive(Clone)]
17pub(crate) struct ClipDrag {
18 pub(crate) lane: Lane,
19 pub(crate) idx: usize,
20 /// The clip that was picked up, so the drop can find it again: gpui freezes
21 /// the payload for the whole gesture, and an edit made *during* one -- a
22 /// stroke deletes, undoes or pastes, none of which a drag blocks -- ripples
23 /// the indices under it. The index alone would then name a different take at
24 /// the release, and the drag would move a clip nobody touched (see
25 /// [`live_idx`]).
26 pub(crate) clip: Clip,
27}
28
29/// A *palette* subtitle row being dragged onto a subtitle lane: which track of
30/// [`PlaybackSession::subtitles`] it is, which is the whole of what a row names.
31/// The window it lands with is the track's own, from its first microsecond to
32/// its last cue -- a placement is trimmed after it is placed, like every clip
33/// here.
34pub(crate) struct SubPick(pub(crate) usize);
35
36/// A subtitle already placed on a lane being dragged: [`ClipDrag`]'s twin, and
37/// carrying the placement itself for that struct's reason -- an edit made during
38/// the gesture moves the indices gpui froze into the payload, so the drop finds
39/// its placement by value ([`Player::dragged_sub`]) rather than by an index that
40/// may since have become another caption's.
41#[derive(Clone, Copy)]
42pub(crate) struct SubDrag {
43 pub(crate) lane: Lane,
44 pub(crate) idx: usize,
45 pub(crate) sub: SubClip,
46}
47
48/// A track *header* being dragged: which track the hand took hold of, to be
49/// let go over the header of the one whose place it is to take
50/// ([`Player::reorder_lane`]). The lane alone -- a track carries its own clips
51/// wherever it goes, so unlike a [`ClipDrag`] there is nothing else to name.
52#[derive(Clone, Copy)]
53pub(crate) struct LaneDrag(pub(crate) Lane);
54
55/// Where a header drag in flight would leave the track in the hand: the lane
56/// whose slot it is about to take, and whether the line is drawn at that lane's
57/// top edge (it is coming up from below) or its bottom one. The drop indicator
58/// every editor draws between two tracks, and the header answer to the ghost a
59/// clip drag lays on a lane ([`Ghost`]) -- stale between gestures, which costs
60/// nothing because it is drawn only while one is live.
61#[derive(Clone, Copy, PartialEq)]
62pub(crate) struct LaneDrop {
63 pub(crate) lane: Lane,
64 pub(crate) above: bool,
65}
66
67/// Where the drag in flight would leave what it is carrying: the lane the
68/// pointer is over, the snapped head the release will commit ([`landing`]), and
69/// how long the thing is. Drawn on that lane as a translucent box the size of
70/// the take, so a landing is *seen* before the release rather than discovered
71/// after it -- the line ([`Player::snap_cue`]) marks the frame, this shows the
72/// body. `refused` is a drop the lane cannot take -- a picture over an audio
73/// track, a sound over a video one -- tinted rather than silent, because the
74/// refusal is coming at the release either way ([`lane_refuses`],
75/// [`Project::move_clip`]).
76#[derive(Clone, Copy, PartialEq)]
77pub(crate) struct Ghost {
78 pub(crate) lane: Lane,
79 pub(crate) start: u32,
80 /// Timeline frames, which a speed has already been counted into: the box is
81 /// as wide as the clip is *long where it lands*. Zero for a library row of
82 /// unknown length, drawn as a head marker.
83 pub(crate) frames: u32,
84 /// The swatch of the file being carried ([`file_tint`]), so the
85 /// ghost reads as the thing in the hand.
86 pub(crate) tint: u32,
87 pub(crate) refused: bool,
88}
89
90/// A clip edge being dragged: which end of which clip, and the timeline frame
91/// the pointer has pulled it to. The box on screen is drawn from `to` while this
92/// is set and the engine hears about it once, at the release
93/// ([`Player::commit_trim`]) -- one edit, one undo step for the whole gesture,
94/// exactly as an equalizer drag works.
95#[derive(Clone, Copy)]
96pub(crate) struct Trim {
97 pub(crate) lane: Lane,
98 pub(crate) idx: usize,
99 pub(crate) edge: Edge,
100 /// Where the edge stood at the press: with `to`, the delta the whole group
101 /// follows by -- each member's own edge moves this far, clamped to its own
102 /// room, which is exactly what the engine commits at the release.
103 pub(crate) from: u32,
104 /// Already clamped by `PlaybackSession::trim_room`, so the width drawn from
105 /// it is the width the release commits -- an edge stops under the pointer
106 /// rather than snapping back after the fact.
107 pub(crate) to: u32,
108 /// The dragged placement's group, so the boxes of everything it names --
109 /// clips and captions alike -- follow the edge on screen exactly as the
110 /// engine will move them.
111 pub(crate) link: Option<u32>,
112}
113
114/// A box select in flight: pressed on empty bed at `from`, pulled to `to`
115/// (window coordinates). Under [`MARQUEE_SLOP`] it is still a click.
116#[derive(Clone, Copy)]
117pub(crate) struct Marquee {
118 pub(crate) from: Point<Pixels>,
119 pub(crate) to: Point<Pixels>,
120}
121
122/// How far the pointer must travel before a press on empty bed becomes a box.
123pub(crate) const MARQUEE_SLOP: f32 = 4.;
124
125impl Marquee {
126 /// Whether the pointer has travelled far enough for this to be a box.
127 pub(crate) fn live(&self) -> bool {
128 let (dx, dy) = (f32::from(self.to.x - self.from.x), f32::from(self.to.y - self.from.y));
129 dx.abs() >= MARQUEE_SLOP || dy.abs() >= MARQUEE_SLOP
130 }
131
132 /// Left, top, right, bottom of the box.
133 pub(crate) fn edges(&self) -> (Pixels, Pixels, Pixels, Pixels) {
134 (
135 self.from.x.min(self.to.x),
136 self.from.y.min(self.to.y),
137 self.from.x.max(self.to.x),
138 self.from.y.max(self.to.y),
139 )
140 }
141}
142
143/// Which of the three pro trims a gesture or key makes (roll, slip, slide).
144#[derive(Clone, Copy, PartialEq, Eq, Debug)]
145pub(crate) enum ProKind {
146 /// The cut after `idx` moves; both clips at it change, the length does not.
147 Roll,
148 /// The clip shows another part of its file, in the same slot.
149 Slip,
150 /// The clip moves between its neighbours, which give and take the frames.
151 Slide,
152}
153
154/// A shift-drag in flight on a clip edge (roll) or body (slip, slide). Like
155/// [`Trim`] it is tracked on the root and the engine hears about it once, at
156/// the release -- one edit, one undo step.
157#[derive(Clone, Copy)]
158pub(crate) struct ProDrag {
159 pub(crate) lane: Lane,
160 /// The clip the engine call is made on: for a roll, the clip *before* the
161 /// cut being dragged (the edge strip's own clip, or the one ahead of it).
162 pub(crate) idx: usize,
163 pub(crate) kind: ProKind,
164 /// The timeline frame under the pointer at the press.
165 pub(crate) from: u32,
166 /// Timeline frames moved so far, already clamped to the room the engine
167 /// answers (slip is clamped by the engine itself at the release).
168 pub(crate) by: i64,
169}
170
171/// How long a trim edge's handle flashes warn when the pointer runs past a
172/// media wall (the source has no more frames that way).
173pub(crate) const TRIM_FLASH: std::time::Duration = std::time::Duration::from_millis(120);
174
175/// The media-wall stop an edge is pinned against, live: the edge is kept at a
176/// bound while it is pulled through it, and the warn flash is for that stop
177/// alone. `since` is when it began, `wall` the frame it is pinned to, so a
178/// pointer that stays past the same wall is one stop, not a flash per sample.
179#[derive(Clone, Copy)]
180pub(crate) struct TrimFlash {
181 pub(crate) lane: Lane,
182 pub(crate) idx: usize,
183 pub(crate) edge: Edge,
184 pub(crate) wall: u32,
185 pub(crate) since: Instant,
186}
187
188impl TrimFlash {
189 /// Whether this edge's handle is still flashing.
190 pub(crate) fn lit(&self, lane: Lane, idx: usize, edge: Edge) -> bool {
191 (self.lane, self.idx, self.edge) == (lane, idx, edge) && self.since.elapsed() < TRIM_FLASH
192 }
193}
194
195/// The media wall a trim stopped against, if the pointer wanted past it: `at`
196/// is where the pointer asked the edge to be, `to` where the engine let it
197/// stand, `walls` the room the edge has. `None` when nothing was refused, or
198/// when the bound that held is a neighbour or the timeline's own start, which
199/// carry no flash -- only the source's end does.
200pub(crate) fn media_wall_stop(at: u32, to: u32, walls: TrimWalls) -> Option<u32> {
201 if at < walls.lo && to == walls.lo && walls.lo_media {
202 return Some(walls.lo);
203 }
204 if at > walls.hi && to == walls.hi && walls.hi_media {
205 return Some(walls.hi);
206 }
207 None
208}
209
210/// The handle width [`trims`] is built on: a box below three of these has no
211/// trim zones at all. The zones themselves are [`TRIM_REACH`] either side of
212/// each edge, which is wider than this strip, so this is the floor, not the
213/// hit size.
214pub(crate) const EDGE_W: f32 = 6.;
215
216/// How far a trim's hit zone reaches on *each* side of a clip edge: 24 px
217/// centred on the edge, so the hand finds it by aim alone (WCAG 2.5.8,
218/// [`HIT_MIN`]). The visible handle of a selected clip is [`TRIM_HANDLE`]
219/// wide; the rest of the zone is a target, not a drawing.
220pub(crate) const TRIM_REACH: f32 = HIT_MIN / 2.;
221
222/// The drawn trim handle a selected clip shows inside each edge.
223#[cfg_attr(not(test), allow(dead_code))]
224pub(crate) const TRIM_HANDLE: f32 = 12.;
225
226/// How far one edge's trim zone reaches, as `(inside, outside)` px from the
227/// edge. `room` is the gap to the neighbour on that side (`f32::INFINITY`
228/// where there is none): the outside reach stops at the middle of that gap, so
229/// where two clips meet the clip under the pointer wins its own half of the
230/// join.
231///
232/// The inside reach shrinks on a clip under 48 px to a quarter of its width,
233/// which keeps the middle half of it a move target -- the middle third is
234/// what the rule guarantees, and a quarter leaves it room to breathe.
235pub(crate) fn trim_zone(width: f32, room: f32) -> (f32, f32) {
236 (
237 TRIM_REACH.min(width / 4.),
238 TRIM_REACH.min(room.max(0.) / 2.),
239 )
240}
241
242/// A fade handle's own hit zone, at each *top* corner of an audio clip's box --
243/// never the trim strip's height, which is [`EDGE_W`] wide down the whole box
244/// ([`trims`]) and would swallow a fade press if the two overlapped. Sitting
245/// just inside the trim strip rather than on top of it, so one gesture is
246/// still exactly one thing: the outer [`EDGE_W`] column lengthens or shortens
247/// the clip, this small square at its top corner shapes the fade instead.
248pub(crate) const FADE_HANDLE_W: f32 = 10.;
249/// Only the label row's own height tall -- a fade handle reaching down into
250/// the waveform would sit on top of the body drag and the waveform's own
251/// tooltip both.
252pub(crate) const FADE_HANDLE_H: f32 = 10.;
253
254/// A fade handle being dragged: which clip, which end (`is_in` for the head's
255/// ramp-up, the tail's ramp-down otherwise), and the gesture's own state --
256/// `press_x` to measure the pixel delta from, `start` the fade length the
257/// press found, `to` what the drag is showing right now, `cap` the clip's own
258/// length in frames ([`Project::set_fade_in`]'s own clamp, so the drag never
259/// draws past what a release would refuse). One clip, no group: unlike a trim
260/// a fade never drags a neighbour, and unlike a caption it never wants a
261/// track's walls.
262#[derive(Clone, Copy)]
263pub(crate) struct FadeDrag {
264 pub(crate) lane: Lane,
265 pub(crate) idx: usize,
266 pub(crate) is_in: bool,
267 pub(crate) press_x: Pixels,
268 pub(crate) start: u32,
269 pub(crate) to: u32,
270 pub(crate) cap: u32,
271}
272
273/// What a volume-envelope drag holds: one key, or the line between key `i` and key `i + 1`.
274#[derive(Clone, Copy, Debug, PartialEq, Eq)]
275pub(crate) enum GainGrab {
276 Key(usize),
277 Segment(usize),
278}
279
280/// A volume-envelope drag on one audio clip, tracked on the root like a fade is. A key moves in
281/// time (between its neighbours and the clip's own source range) and in dB; a segment moves both
282/// of its keys up or down by the same dB. `keys` is the envelope at the press, which the release
283/// compares against; `shown` is what the drag is showing and what the release commits, in one
284/// undo step. Positions are window pixels, and `origin` and `size` are the clip's own box.
285#[derive(Clone, Debug)]
286pub(crate) struct GainEdit {
287 pub(crate) lane: Lane,
288 pub(crate) idx: usize,
289 pub(crate) grab: GainGrab,
290 pub(crate) press: Point<Pixels>,
291 pub(crate) origin: Point<Pixels>,
292 pub(crate) size: Size<Pixels>,
293 pub(crate) keys: Vec<engine::GainKey>,
294 pub(crate) shown: Vec<engine::GainKey>,
295 /// The clip's own gain, the source range a key may move in, its speed and the timeline's
296 /// pixels per frame, read at the press.
297 pub(crate) clip_gain: f32,
298 pub(crate) in_frame: u32,
299 pub(crate) out_frame: u32,
300 pub(crate) speed: f64,
301 pub(crate) px_per_frame: f32,
302 /// For a key: the display dB the press was over, less the key's own. For a segment: the dB
303 /// under the press. A move adds the pointer's change to it.
304 pub(crate) grab_db: f32,
305}
306
307/// Whether a clip box this wide gets its two trim strips at all. Below three
308/// handles wide the pair would occlude the whole box: every press on it would
309/// trim, and the clip could not be selected, dragged to another lane or picked
310/// up by its middle -- which is exactly what a jumpcut leaves behind
311/// ([`Player::cut_silences`] manufactures a great many short clips). Above it,
312/// what is left between the two strips is a handle's width of body in its own
313/// right. A clip too short for its handles is trimmed by zooming in first: the
314/// bed is a magnifier, and the strip grows with the box.
315pub(crate) fn trims(width: f32) -> bool {
316 width >= 3. * EDGE_W
317}
318
319/// How wide a clip's box is *drawn*, given the width its own length is worth
320/// (`span`). Never under [`HIT_MIN`], even where that is wider than the clip is
321/// long: zoomed far out a short take is worth a fraction of a pixel, and a box
322/// nobody can put a pointer on is a clip that cannot be selected, dragged, given
323/// a menu or reached at all -- which is strictly worse than one drawn a few
324/// pixels too wide. The same call [`cue_box`] makes for a mark, and what every
325/// editor draws.
326///
327/// A drawing only: [`Scale::time_at`] still reads the bed, so a press inside the
328/// padding names the frame it points at, and the box's head is the clip's own.
329pub(crate) fn clip_width(span: f32) -> f32 {
330 span.max(HIT_MIN)
331}
332
333/// The sheet a card or a menu is painted on: the whole window, and the mouse
334/// stops at it. Occluding is what tells gpui that nothing under this sheet is
335/// hovered any more (`Hitbox::is_hovered`) -- without it the window carries on
336/// hovering behind an open menu and pops *its* tooltip over the menu's items,
337/// which is a card being painted over by the thing it covers.
338///
339/// Every card and every menu takes its sheet from here, so no surface can be
340/// drawn over the top of one by having been given a plain scrim.
341pub(crate) fn scrim() -> Div {
342 div().absolute().inset_0().occlude()
343}
344
345/// The body every hanging menu is drawn on: the clip menu, the library row
346/// menu and the open choice list, one shape for all three.
347///
348/// It exists because the three drifted: each carried its own copy of the
349/// plate chrome, so styling one (the picker, 2026-08-21) left the other two
350/// painting the legacy raised grey -- the user's "right click menu in library
351/// is old too". A plate is `panel` with a seam around it and a 6px radius
352/// (DESIGN §2/§4); the legacy tree keeps its own raised sheet. One function,
353/// so the next change reaches all three or none.
354pub(crate) fn menu_plate(id: &'static str, x: f32, y: f32) -> Stateful<Div> {
355 // The one popup look (REDESIGN §1.6): every menu starts from `kit::plate`.
356 crate::ui::kit::plate(6.)
357 .id(id)
358 .absolute()
359 .left(px(x))
360 .top(px(y))
361 .w(px(crate::layout::MENU_W))
362 .flex()
363 .flex_col()
364 .p(px(crate::layout::MENU_PAD))
365}
366
367/// The sheet a card with a *slider* in it takes instead: the same scrim, with
368/// the window's own drag listeners on it as well.
369///
370/// A scrim occludes, and occluding is where gpui's hit test stops
371/// (`Hitbox::is_hovered`, window.rs:788) -- so while a card is up the root is
372/// not hovered anywhere behind it and its `on_mouse_move`/`on_mouse_up` hear
373/// nothing at all. Every drag in this window is tracked from the root, because
374/// each of them starts on a strip a few pixels wide that the pointer leaves at
375/// once ([`Player::drag_move`]), so a card's handles were set by the press and
376/// then frozen: the value never followed the hand and the release never wrote.
377/// The scrim is the one surface above the occluder that covers the whole card,
378/// so the same two listeners go here, and a drag that leaves the card is picked
379/// up by the root's copy of them without a seam.
380pub(crate) fn drag_scrim(cx: &Context<Player>) -> Div {
381 scrim()
382 .on_mouse_move(cx.listener(Player::drag_move))
383 .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release))
384}
385
386/// The seam between two panels, and the handle that resizes them: a strip
387/// [`SPLIT_W`] wide with the resize cursor of its axis on it, which is the whole
388/// of how a person finds out the layout moves at all.
389///
390/// The press is all this element does. The gesture itself is the root's, like
391/// every other drag in this window ([`Player::drag_move`]): a 6 px strip is not
392/// where the pointer stays, and a divider whose own listeners tracked it would
393/// stop following the hand on the first move. `stop_propagation` so the press
394/// never reaches the region under it -- a seam over the timeline must not scrub.
395///
396/// Drawn to the ghost grammar (DESIGN §11.2): nothing at rest -- a room whose
397/// every seam is inked is the "crowded" the user named -- then one hairline of
398/// dim ink under the pointer, and the same line one step brighter while the
399/// hand is actually holding it. The band below is the *hit* area throughout;
400/// only one 1 px line inside it is ever painted. `held` is the seam this window is
401/// dragging right now ([`Player::split_drag`]), which the pointer leaves on the
402/// first move -- so the lit line has to come from the model, not from `hover`.
403///
404/// What the *hand* aims at is wider than what the eye is given: the press and
405/// the resize cursor live on a [`GRAB_W`] band centred on the *line the eye
406/// sees* -- one row above the strip, so it reaches past the panel edge the
407/// strip stands in front of rather than being centred on the strip -- mounted
408/// absolutely so it overlays its neighbours instead of pushing them (the strip
409/// keeps its [`SPLIT_W`] of layout, and `layout::split_drag_size` keeps
410/// answering in strip coordinates). A 6 px target missed by 5 px is a resize
411/// the hand cannot find, which is the same as no resize at all (user
412/// 2026-09-09: "panes should be enlargable and shrinkable" -- they already
413/// were). The hairline is painted *by the band*, not by the strip, so the
414/// whole band lights it: a line raised only by the pixels that already grab
415/// the seam tells a hand nothing. The bench's band ([`BENCH_GRAB_H`]) is every
416/// other seam's reach: the section head under it is gone (cleanse round 2) and
417/// the ruler that starts the bench now answers presses itself, so a deeper
418/// band would eat scrubs at the film's own top edge.
419///
420/// A double press resets the seam to the window's own share
421/// ([`Splits::clear`]): the cheap way back from a layout dragged somewhere
422/// unusable, and the one every editor's dividers answer to.
423pub(crate) fn divider(split: Split, held: bool, cx: &mut Context<Player>) -> Div {
424 let across = matches!(split, Split::Timeline | Split::Bench);
425 // Named per seam anyway ([`BENCH_GRAB_H`] is [`GRAB_W`] since the bench
426 // lost its section head): every neighbour's first row carries content the
427 // hand may want instead -- the bench's ruler scrubs, the dock's rows start
428 // at its very edge, the legacy timeline's are the edit toolbar's buttons.
429 let grab = match split {
430 Split::Bench => BENCH_GRAB_H,
431 _ => GRAB_W,
432 };
433 // Named per seam: `group_hover` resolves by name through one global map,
434 // so two dividers sharing a name would light each other.
435 let group = format!("seam-{split:?}");
436 div()
437 .flex_none()
438 .when(across, |d| d.h(px(SPLIT_W)).w_full())
439 .when(!across, |d| d.w(px(SPLIT_W)).h_full())
440 .relative()
441 .child(
442 div()
443 .absolute()
444 .group(group.clone())
445 .when(across, |d| {
446 d.left_0()
447 .right_0()
448 .top(px(-1.))
449 .h(px(grab))
450 .cursor_row_resize()
451 })
452 .when(!across, |d| {
453 d.top_0()
454 .bottom_0()
455 .left(px(-1.))
456 .w(px(grab))
457 .cursor_col_resize()
458 })
459 .on_mouse_down(
460 MouseButton::Left,
461 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
462 match event.click_count >= 2 {
463 // The reset is written where a release would have written
464 // the drag, the same small round trip: a seam put back by
465 // hand must not come back on the next launch.
466 true => {
467 this.split_drag = None;
468 this.splits.clear(split);
469 crate::layout::save_stance_splits(&this.splits);
470 }
471 false => {
472 this.split_drag = Some(split);
473 this.split_press = Some((event.position, false));
474 }
475 }
476 cx.notify();
477 cx.stop_propagation();
478 }),
479 )
480 // The hairline the eye is given, painted *inside* the band and
481 // one pixel thick, so the whole band -- not the 6 px strip it
482 // hangs on -- is what lights it. A line only the pixels that
483 // already hit the seam can raise tells the hand nothing it did
484 // not already know.
485 .child(
486 div()
487 .absolute()
488 .when(across, |d| {
489 d.left_0().right_0().top(px(1.)).h(px(1.)).border_t_1()
490 })
491 .when(!across, |d| {
492 d.top_0().bottom_0().left(px(1.)).w(px(1.)).border_l_1()
493 })
494 .border_color(match held {
495 true => gpui::Hsla::from(rgb(INK3())),
496 false => gpui::transparent_black(),
497 })
498 // Lit under the pointer: the second half of "this can be
499 // dragged", said before the button goes down rather than
500 // after.
501 .when(!held, |d| {
502 d.group_hover(group, |s| s.border_color(rgb(STROKE_DIVIDER())))
503 }),
504 ),
505 )
506}
507
508/// The grab on a lane's bottom edge (DESIGN §5 "Lane heights"): 2px inside the
509/// lane's edge and 12px past it -- the 2px [`ROW_GAP`] plus 10px of the lane
510/// below. It starts at the head's right edge, so the bed carries it and a head
511/// keeps its own bottom pixels for its reorder grab and switches. It stays out
512/// of the lane's bottom 2px and so does not cover the key marks drawn on a
513/// clip's foot (`ui/bench_stance/lane.rs`), which must take their own presses.
514/// A press starts the drag (`Player::lane_resize`, read by `drag_move`); a
515/// double-click puts the lane back to its kind's default.
516pub(crate) fn lane_resize_band(
517 lane: Lane,
518 h: f32,
519 left: f32,
520 cx: &mut Context<Player>,
521) -> impl IntoElement + use<> {
522 const ABOVE_H: f32 = 2.;
523 const BELOW_H: f32 = 12.;
524 let key = crate::ui::bench_stance::lane_key(lane);
525 // Named per lane: `group_hover` resolves by name through one global map.
526 let group = format!("lane-resize-{key}");
527 div()
528 .id(SharedString::from(format!("bench-lane-resize-{key}")))
529 .absolute()
530 .group(group.clone())
531 .left(px(left))
532 .right_0()
533 .top(px(h - ABOVE_H))
534 .h(px(ABOVE_H + BELOW_H))
535 .cursor_row_resize()
536 .on_mouse_down(
537 MouseButton::Left,
538 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
539 match event.click_count >= 2 {
540 true => this.reset_lane_h(lane, cx),
541 // The grab is the pointer's y less the height the lane
542 // has now, so a drag sets the height from the pointer
543 // alone (`Player::drag_lane_resize`) and never jumps.
544 false => {
545 this.lane_resize = Some((lane, f32::from(event.position.y) - h));
546 cx.notify();
547 }
548 }
549 cx.stop_propagation();
550 }),
551 )
552 // The hairline at the lane's edge, lit under the pointer -- the same
553 // "this can be dragged" cue a seam gives (`divider`).
554 .child(
555 div()
556 .absolute()
557 .left_0()
558 .right_0()
559 .top(px(ABOVE_H - 1.))
560 .h(px(1.))
561 .group_hover(group, |s| s.bg(rgb(STROKE_DIVIDER()))),
562 )
563}
564
565/// A press that stops here. What every card's body hands its scrim: the scrim
566/// closes the card on a press, and the card is painted after it, so this listener
567/// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant
568/// for a button never closes the card out from under its own click -- the rule
569/// the menus already follow ([`Player::library_card`]).
570pub(crate) fn swallow(_: &MouseDownEvent, _: &mut Window, cx: &mut App) {
571 cx.stop_propagation();
572}
573
574/// How close to an edge a dragged clip has to be let go for it to land *on* it:
575/// the snap every timeline has, in pixels rather than frames so that it feels
576/// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two
577/// takes must still be able to leave a gap of a few frames there.
578pub(crate) const SNAP_PX: f64 = 5.;
579
580/// The same magnet, wider, for a drag's own *release* -- a library row or a
581/// clip let go of, rather than an edge nudged one frame at a time. The user's
582/// own complaint ("to drop at 0.0 you must be exactly at 0.0") is a 5px
583/// window read at zoom: past a couple of minutes on screen a pixel is worth
584/// several frames, and 5px of aim is not forgiving enough to feel like a
585/// magnet at all. Twice [`SNAP_PX`], [`Scale::drop_snap_frames`].
586pub(crate) const DROP_SNAP_PX: f64 = 10.;
587
588/// The scrollbar's thumb never narrows past this, however long the timeline:
589/// a thumb a pixel wide is a thumb no hand can hold. A quarter of the ruler's
590/// own seek strip, which is the idiom it sits under.
591pub(crate) const SCROLL_THUMB_MIN: f32 = 24.;
592
593/// The thickness of a scrollbar bar as drawn, in the one dimension the strip
594/// spans: the height of the horizontal one under the lanes, the width of the
595/// vertical one on the beds' right edge. This is what the layout spends.
596pub(crate) const SCROLL_BAR_H: f32 = 6.;
597
598/// The hit area of a scrollbar strip, in the same dimension: a hand must be
599/// able to find it without aiming (WCAG 2.5.8, [`HIT_MIN`]). The strip's row
600/// is [`SCROLL_ROW_H`] tall; the band reaches [`SCROLL_HIT_UP`] above it into
601/// the bottom of the lanes and [`SCROLL_HIT_DOWN`] below it, so the band is
602/// at least [`HIT_MIN`] and the lanes give up no more than 8px for it.
603pub(crate) const SCROLL_HIT: f32 = HIT_MIN;
604
605/// Where a held key would land, which is the whole of what auto-repeat has to
606/// know. [`Player::repeat_scope`] answers it from the same state the handler
607/// walks below itself.
608#[derive(Clone, Copy, PartialEq, Eq, Debug)]
609pub(crate) enum Repeat {
610 /// A card with values in it owns the keyboard: equalizer, colour, speed or
611 /// silence. Its arrows are sliders.
612 Card,
613 /// Nobody does, so the keymap answers -- and only one pair of its actions
614 /// is a value being moved rather than a thing being done once.
615 Keymap,
616 /// A stroke is being captured, an export is running, or an overlay with no
617 /// value in it is up. Nothing there is worth a repeat.
618 Nothing,
619}
620
621/// Whether a *held* stroke means it again. One press is always one action; a
622/// hold is only ever a value running, so this is what tells the two apart.
623///
624/// The cards' arrows, because that is what every one of them moves a slider
625/// with -- and only the arrows, so the equalizer's `r` cannot flatten five
626/// bands forty times a second and the silence card's `enter` cannot cut forty
627/// places again on the next tick. Outside a card the volume pair and nothing
628/// else: play, cut, delete, save, export and every other binding is a one-shot,
629/// exactly as it was when the handler filtered every held key alike.
630pub(crate) fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool {
631 match scope {
632 Repeat::Card => matches!(key, "up" | "down" | "left" | "right"),
633 Repeat::Keymap => matches!(
634 action,
635 Some(
636 ActionId::VolumeUp
637 | ActionId::VolumeDown
638 // A zoom is a value being moved as much as a level is:
639 // held, it runs from the whole timeline down to a handful
640 // of frames and stops there. The fit is one press.
641 | ActionId::ZoomIn
642 | ActionId::ZoomOut
643 )
644 ),
645 Repeat::Nothing => false,
646 }
647}
648
649#[cfg(test)]
650mod tests {
651 use super::*;
652
653 fn walls(lo_media: bool, hi_media: bool) -> TrimWalls {
654 TrimWalls {
655 lo: 1,
656 hi: 9,
657 lo_media,
658 hi_media,
659 }
660 }
661
662 #[test]
663 fn a_stop_flashes_only_at_a_media_wall_the_pointer_wanted_past() {
664 // Past the source's end: flash. Past a neighbour, or inside the room:
665 // nothing to say.
666 assert_eq!(media_wall_stop(12, 9, walls(false, true)), Some(9));
667 assert_eq!(media_wall_stop(12, 9, walls(false, false)), None);
668 assert_eq!(media_wall_stop(0, 1, walls(true, false)), Some(1));
669 assert_eq!(media_wall_stop(0, 1, walls(false, true)), None);
670 assert_eq!(media_wall_stop(5, 5, walls(true, true)), None);
671 // A clamp that did not clamp the pointer's ask is not a stop.
672 assert_eq!(media_wall_stop(9, 9, walls(true, true)), None);
673 }
674
675 #[test]
676 fn a_flash_lights_its_own_edge_for_its_window_only() {
677 let lane = Lane::V1;
678 let fresh = TrimFlash {
679 lane,
680 idx: 2,
681 edge: Edge::End,
682 wall: 9,
683 since: Instant::now(),
684 };
685 assert!(fresh.lit(lane, 2, Edge::End));
686 assert!(!fresh.lit(lane, 2, Edge::Start));
687 assert!(!fresh.lit(lane, 3, Edge::End));
688 let spent = TrimFlash {
689 since: Instant::now() - TRIM_FLASH - Duration::from_millis(1),
690 ..fresh
691 };
692 assert!(!spent.lit(lane, 2, Edge::End));
693 }
694}