forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB0563cbfTahinli2 months ago824 commits

interact.rs428 lines, 21.2 KiBHistoryRawDownload
1//! What a pointer is doing: the drags, the ghosts, the trims and the key repeat.
2
3use crate::*;
4
5/// A library row being dragged: the file and which of its audio streams that
6/// row is, which is the whole of what a row names. Where it lands does not
7/// change what is inserted.
8pub(crate) struct AssetDrag(pub(crate) PathBuf, pub(crate) usize);
9
10/// A clip already on the timeline being dragged: the lane it is on and its index
11/// there, which is how every other edit names a clip. Unlike an [`AssetDrag`]
12/// nothing is inserted -- the same clip changes lane and keeps the frames it
13/// plays -- but where along the bed it is let go is exactly where it lands, less
14/// the offset the hand grabbed it at ([`Player::grab`]).
15#[derive(Clone, Copy)]
16pub(crate) struct ClipDrag {
17 pub(crate) lane: Lane,
18 pub(crate) idx: usize,
19 /// The clip that was picked up, so the drop can find it again: gpui freezes
20 /// the payload for the whole gesture, and an edit made *during* one -- a
21 /// stroke deletes, undoes or pastes, none of which a drag blocks -- ripples
22 /// the indices under it. The index alone would then name a different take at
23 /// the release, and the drag would move a clip nobody touched (see
24 /// [`live_idx`]).
25 pub(crate) clip: Clip,
26}
27
28/// A *palette* subtitle row being dragged onto a subtitle lane: which track of
29/// [`PlaybackSession::subtitles`] it is, which is the whole of what a row names.
30/// The window it lands with is the track's own, from its first microsecond to
31/// its last cue -- a placement is trimmed after it is placed, like every clip
32/// here.
33pub(crate) struct SubPick(pub(crate) usize);
34
35/// A subtitle already placed on a lane being dragged: [`ClipDrag`]'s twin, and
36/// carrying the placement itself for that struct's reason -- an edit made during
37/// the gesture moves the indices gpui froze into the payload, so the drop finds
38/// its placement by value ([`Player::dragged_sub`]) rather than by an index that
39/// may since have become another caption's.
40#[derive(Clone, Copy)]
41pub(crate) struct SubDrag {
42 pub(crate) lane: Lane,
43 pub(crate) idx: usize,
44 pub(crate) sub: SubClip,
45}
46
47/// A track *header* being dragged: which track the hand took hold of, to be
48/// let go over the header of the one whose place it is to take
49/// ([`Player::reorder_lane`]). The lane alone -- a track carries its own clips
50/// wherever it goes, so unlike a [`ClipDrag`] there is nothing else to name.
51#[derive(Clone, Copy)]
52pub(crate) struct LaneDrag(pub(crate) Lane);
53
54/// Where a header drag in flight would leave the track in the hand: the lane
55/// whose slot it is about to take, and whether the line is drawn at that lane's
56/// top edge (it is coming up from below) or its bottom one. The drop indicator
57/// every editor draws between two tracks, and the header answer to the ghost a
58/// clip drag lays on a lane ([`Ghost`]) -- stale between gestures, which costs
59/// nothing because it is drawn only while one is live.
60#[derive(Clone, Copy, PartialEq)]
61pub(crate) struct LaneDrop {
62 pub(crate) lane: Lane,
63 pub(crate) above: bool,
64}
65
66/// Where the drag in flight would leave what it is carrying: the lane the
67/// pointer is over, the snapped head the release will commit ([`landing`]), and
68/// how long the thing is. Drawn on that lane as a translucent box the size of
69/// the take, so a landing is *seen* before the release rather than discovered
70/// after it -- the line ([`Player::snap_cue`]) marks the frame, this shows the
71/// body. `refused` is a drop the lane cannot take -- a picture over an audio
72/// track, a sound over a video one -- tinted rather than silent, because the
73/// refusal is coming at the release either way ([`lane_refuses`],
74/// [`Project::move_clip`]).
75#[derive(Clone, Copy, PartialEq)]
76pub(crate) struct Ghost {
77 pub(crate) lane: Lane,
78 pub(crate) start: u32,
79 /// Timeline frames, which a speed has already been counted into: the box is
80 /// as wide as the clip is *long where it lands*. Zero for a library row of
81 /// unknown length, drawn as a head marker.
82 pub(crate) frames: u32,
83 /// The swatch of the file being carried ([`file_tint`]), so the
84 /// ghost reads as the thing in the hand.
85 pub(crate) tint: u32,
86 pub(crate) refused: bool,
87}
88
89/// A clip edge being dragged: which end of which clip, and the timeline frame
90/// the pointer has pulled it to. The box on screen is drawn from `to` while this
91/// is set and the engine hears about it once, at the release
92/// ([`Player::commit_trim`]) -- one edit, one undo step for the whole gesture,
93/// exactly as an equalizer drag works.
94#[derive(Clone, Copy)]
95pub(crate) struct Trim {
96 pub(crate) lane: Lane,
97 pub(crate) idx: usize,
98 pub(crate) edge: Edge,
99 /// Where the edge stood at the press: with `to`, the delta the whole group
100 /// follows by -- each member's own edge moves this far, clamped to its own
101 /// room, which is exactly what the engine commits at the release.
102 pub(crate) from: u32,
103 /// Already clamped by `PlaybackSession::trim_room`, so the width drawn from
104 /// it is the width the release commits -- an edge stops under the pointer
105 /// rather than snapping back after the fact.
106 pub(crate) to: u32,
107 /// The dragged placement's group, so the boxes of everything it names --
108 /// clips and captions alike -- follow the edge on screen exactly as the
109 /// engine will move them.
110 pub(crate) link: Option<u32>,
111}
112
113/// How wide a clip's edge is as a *target*: the strip at each end where a press
114/// means "make this longer or shorter" instead of "move this to another lane".
115/// Wide enough to hit, narrow enough that the middle of even a small box is
116/// still the body.
117pub(crate) const EDGE_W: f32 = 6.;
118
119/// A fade handle's own hit zone, at each *top* corner of an audio clip's box --
120/// never the trim strip's height, which is [`EDGE_W`] wide down the whole box
121/// ([`trims`]) and would swallow a fade press if the two overlapped. Sitting
122/// just inside the trim strip rather than on top of it, so one gesture is
123/// still exactly one thing: the outer [`EDGE_W`] column lengthens or shortens
124/// the clip, this small square at its top corner shapes the fade instead.
125pub(crate) const FADE_HANDLE_W: f32 = 10.;
126/// Only the label row's own height tall -- a fade handle reaching down into
127/// the waveform would sit on top of the body drag and the waveform's own
128/// tooltip both.
129pub(crate) const FADE_HANDLE_H: f32 = 10.;
130
131/// A fade handle being dragged: which clip, which end (`is_in` for the head's
132/// ramp-up, the tail's ramp-down otherwise), and the gesture's own state --
133/// `press_x` to measure the pixel delta from, `start` the fade length the
134/// press found, `to` what the drag is showing right now, `cap` the clip's own
135/// length in frames ([`Project::set_fade_in`]'s own clamp, so the drag never
136/// draws past what a release would refuse). One clip, no group: unlike a trim
137/// a fade never drags a neighbour, and unlike a caption it never wants a
138/// track's walls.
139#[derive(Clone, Copy)]
140pub(crate) struct FadeDrag {
141 pub(crate) lane: Lane,
142 pub(crate) idx: usize,
143 pub(crate) is_in: bool,
144 pub(crate) press_x: Pixels,
145 pub(crate) start: u32,
146 pub(crate) to: u32,
147 pub(crate) cap: u32,
148}
149
150/// Whether a clip box this wide gets its two trim strips at all. Below three
151/// handles wide the pair would occlude the whole box: every press on it would
152/// trim, and the clip could not be selected, dragged to another lane or picked
153/// up by its middle -- which is exactly what a jumpcut leaves behind
154/// ([`Player::cut_silences`] manufactures a great many short clips). Above it,
155/// what is left between the two strips is a handle's width of body in its own
156/// right. A clip too short for its handles is trimmed by zooming in first: the
157/// bed is a magnifier, and the strip grows with the box.
158pub(crate) fn trims(width: f32) -> bool {
159 width >= 3. * EDGE_W
160}
161
162/// How wide a clip's box is *drawn*, given the width its own length is worth
163/// (`span`). Never under [`HIT_MIN`], even where that is wider than the clip is
164/// long: zoomed far out a short take is worth a fraction of a pixel, and a box
165/// nobody can put a pointer on is a clip that cannot be selected, dragged, given
166/// a menu or reached at all -- which is strictly worse than one drawn a few
167/// pixels too wide. The same call [`cue_box`] makes for a mark, and what every
168/// editor draws.
169///
170/// A drawing only: [`Scale::time_at`] still reads the bed, so a press inside the
171/// padding names the frame it points at, and the box's head is the clip's own.
172pub(crate) fn clip_width(span: f32) -> f32 {
173 span.max(HIT_MIN)
174}
175
176/// The sheet a card or a menu is painted on: the whole window, and the mouse
177/// stops at it. Occluding is what tells gpui that nothing under this sheet is
178/// hovered any more (`Hitbox::is_hovered`) -- without it the window carries on
179/// hovering behind an open menu and pops *its* tooltip over the menu's items,
180/// which is a card being painted over by the thing it covers.
181///
182/// Every card and every menu takes its sheet from here, so no surface can be
183/// drawn over the top of one by having been given a plain scrim.
184pub(crate) fn scrim() -> Div {
185 div().absolute().inset_0().occlude()
186}
187
188/// The body every hanging menu is drawn on: the clip menu, the library row
189/// menu and the open choice list, one shape for all three.
190///
191/// It exists because the three drifted: each carried its own copy of the
192/// plate chrome, so styling one (the picker, 2026-08-21) left the other two
193/// painting the legacy raised grey -- the user's "right click menu in library
194/// is old too". A plate is `panel` with a seam around it and a 6px radius
195/// (DESIGN §2/§4); the legacy tree keeps its own raised sheet. One function,
196/// so the next change reaches all three or none.
197pub(crate) fn menu_plate(id: &'static str, x: f32, y: f32) -> Stateful<Div> {
198 div()
199 .id(id)
200 .absolute()
201 .left(px(x))
202 .top(px(y))
203 .w(px(crate::layout::MENU_W))
204 .flex()
205 .flex_col()
206 .p(px(crate::layout::MENU_PAD))
207 .rounded(px(6.))
208 .bg(rgb(crate::ui::theme::DARK_PANEL()))
209 .border_1()
210 .border_color(rgba(crate::ui::theme::DARK_SEAM()))
211}
212
213/// The sheet a card with a *slider* in it takes instead: the same scrim, with
214/// the window's own drag listeners on it as well.
215///
216/// A scrim occludes, and occluding is where gpui's hit test stops
217/// (`Hitbox::is_hovered`, window.rs:788) -- so while a card is up the root is
218/// not hovered anywhere behind it and its `on_mouse_move`/`on_mouse_up` hear
219/// nothing at all. Every drag in this window is tracked from the root, because
220/// each of them starts on a strip a few pixels wide that the pointer leaves at
221/// once ([`Player::drag_move`]), so a card's handles were set by the press and
222/// then frozen: the value never followed the hand and the release never wrote.
223/// The scrim is the one surface above the occluder that covers the whole card,
224/// so the same two listeners go here, and a drag that leaves the card is picked
225/// up by the root's copy of them without a seam.
226pub(crate) fn drag_scrim(cx: &mut Context<Player>) -> Div {
227 scrim()
228 .on_mouse_move(cx.listener(Player::drag_move))
229 .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release))
230}
231
232/// The seam between two panels, and the handle that resizes them: a strip
233/// [`SPLIT_W`] wide with the resize cursor of its axis on it, which is the whole
234/// of how a person finds out the layout moves at all.
235///
236/// The press is all this element does. The gesture itself is the root's, like
237/// every other drag in this window ([`Player::drag_move`]): a 6 px strip is not
238/// where the pointer stays, and a divider whose own listeners tracked it would
239/// stop following the hand on the first move. `stop_propagation` so the press
240/// never reaches the region under it -- a seam over the timeline must not scrub.
241///
242/// Drawn to the ghost grammar (DESIGN §11.2): nothing at rest -- a room whose
243/// every seam is inked is the "crowded" the user named -- then one hairline of
244/// dim ink under the pointer, and the same line one step brighter while the
245/// hand is actually holding it. The band below is the *hit* area throughout;
246/// only one 1 px line inside it is ever painted. `held` is the seam this window is
247/// dragging right now ([`Player::split_drag`]), which the pointer leaves on the
248/// first move -- so the lit line has to come from the model, not from `hover`.
249///
250/// What the *hand* aims at is wider than what the eye is given: the press and
251/// the resize cursor live on a [`GRAB_W`] band centred on the *line the eye
252/// sees* -- one row above the strip, so it reaches past the panel edge the
253/// strip stands in front of rather than being centred on the strip -- mounted
254/// absolutely so it overlays its neighbours instead of pushing them (the strip
255/// keeps its [`SPLIT_W`] of layout, and `layout::split_drag_size` keeps
256/// answering in strip coordinates). A 6 px target missed by 5 px is a resize
257/// the hand cannot find, which is the same as no resize at all (user
258/// 2026-09-09: "panes should be enlargable and shrinkable" -- they already
259/// were). The hairline is painted *by the band*, not by the strip, so the
260/// whole band lights it: a line raised only by the pixels that already grab
261/// the seam tells a hand nothing. The bench's band is deeper still
262/// ([`BENCH_GRAB_H`]) -- the row under its seam is the bench's own section
263/// head, and that is where a hand aiming at "the top of the timeline" lands.
264///
265/// A double press resets the seam to the window's own share
266/// ([`Splits::clear`]): the cheap way back from a layout dragged somewhere
267/// unusable, and the one every editor's dividers answer to.
268pub(crate) fn divider(split: Split, held: bool, cx: &mut Context<Player>) -> Div {
269 let across = matches!(split, Split::Timeline | Split::Bench);
270 // A row seam parts the picture from a panel whose own first row is its
271 // section head -- empty land -- so the bench's band reaches down through
272 // it ([`BENCH_GRAB_H`]). Every other seam keeps [`GRAB_W`]: the dock's
273 // neighbour is a list whose rows start at its very edge, and the legacy
274 // timeline's is the edit toolbar's buttons.
275 let grab = match split {
276 Split::Bench => BENCH_GRAB_H,
277 _ => GRAB_W,
278 };
279 // Named per seam: `group_hover` resolves by name through one global map,
280 // so two dividers sharing a name would light each other.
281 let group = format!("seam-{split:?}");
282 div()
283 .flex_none()
284 .when(across, |d| d.h(px(SPLIT_W)).w_full())
285 .when(!across, |d| d.w(px(SPLIT_W)).h_full())
286 .relative()
287 .child(
288 div()
289 .absolute()
290 .group(group.clone())
291 .when(across, |d| {
292 d.left_0()
293 .right_0()
294 .top(px(-1.))
295 .h(px(grab))
296 .cursor_row_resize()
297 })
298 .when(!across, |d| {
299 d.top_0()
300 .bottom_0()
301 .left(px(-1.))
302 .w(px(grab))
303 .cursor_col_resize()
304 })
305 .on_mouse_down(
306 MouseButton::Left,
307 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
308 match event.click_count >= 2 {
309 // The reset is written where a release would have written
310 // the drag, the same small round trip: a seam put back by
311 // hand must not come back on the next launch.
312 true => {
313 this.split_drag = None;
314 this.splits.clear(split);
315 crate::layout::save_stance_splits(&this.splits);
316 }
317 false => this.split_drag = Some(split),
318 }
319 cx.notify();
320 cx.stop_propagation();
321 }),
322 )
323 // The hairline the eye is given, painted *inside* the band and
324 // one pixel thick, so the whole band -- not the 6 px strip it
325 // hangs on -- is what lights it. A line only the pixels that
326 // already hit the seam can raise tells the hand nothing it did
327 // not already know.
328 .child(
329 div()
330 .absolute()
331 .when(across, |d| {
332 d.left_0().right_0().top(px(1.)).h(px(1.)).border_t_1()
333 })
334 .when(!across, |d| {
335 d.top_0().bottom_0().left(px(1.)).w(px(1.)).border_l_1()
336 })
337 .border_color(match held {
338 true => gpui::Hsla::from(rgb(INK3())),
339 false => gpui::transparent_black(),
340 })
341 // Lit under the pointer: the second half of "this can be
342 // dragged", said before the button goes down rather than
343 // after.
344 .when(!held, |d| {
345 d.group_hover(group, |s| s.border_color(rgb(STROKE_DIVIDER())))
346 }),
347 ),
348 )
349}
350
351/// A press that stops here. What every card's body hands its scrim: the scrim
352/// closes the card on a press, and the card is painted after it, so this listener
353/// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant
354/// for a button never closes the card out from under its own click -- the rule
355/// the menus already follow ([`Player::library_card`]).
356pub(crate) fn swallow(_: &MouseDownEvent, _: &mut Window, cx: &mut App) {
357 cx.stop_propagation();
358}
359
360/// How close to an edge a dragged clip has to be let go for it to land *on* it:
361/// the snap every timeline has, in pixels rather than frames so that it feels
362/// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two
363/// takes must still be able to leave a gap of a few frames there.
364pub(crate) const SNAP_PX: f64 = 5.;
365
366/// The same magnet, wider, for a drag's own *release* -- a library row or a
367/// clip let go of, rather than an edge nudged one frame at a time. The user's
368/// own complaint ("to drop at 0.0 you must be exactly at 0.0") is a 5px
369/// window read at zoom: past a couple of minutes on screen a pixel is worth
370/// several frames, and 5px of aim is not forgiving enough to feel like a
371/// magnet at all. Twice [`SNAP_PX`], [`Scale::drop_snap_frames`].
372pub(crate) const DROP_SNAP_PX: f64 = 10.;
373
374/// The scrollbar's thumb never narrows past this, however long the timeline:
375/// a thumb a pixel wide is a thumb no hand can hold. A quarter of the ruler's
376/// own seek strip, which is the idiom it sits under.
377pub(crate) const SCROLL_THUMB_MIN: f32 = 24.;
378
379/// The thickness of a scrollbar strip's hit area, in the one dimension the
380/// strip spans: the height of the horizontal one under the lanes, the width
381/// of the vertical one on the beds' right edge. The bar inside it looks 6 px,
382/// and the strip that takes the press is thicker for the ruler strip's
383/// reason -- a hand must be able to find it without aiming (WCAG 2.5.8).
384pub(crate) const SCROLL_HIT: f32 = 14.;
385
386/// Where a held key would land, which is the whole of what auto-repeat has to
387/// know. [`Player::repeat_scope`] answers it from the same state the handler
388/// walks below itself.
389#[derive(Clone, Copy, PartialEq, Eq, Debug)]
390pub(crate) enum Repeat {
391 /// A card with values in it owns the keyboard: equalizer, colour, speed or
392 /// silence. Its arrows are sliders.
393 Card,
394 /// Nobody does, so the keymap answers -- and only one pair of its actions
395 /// is a value being moved rather than a thing being done once.
396 Keymap,
397 /// A stroke is being captured, an export is running, or an overlay with no
398 /// value in it is up. Nothing there is worth a repeat.
399 Nothing,
400}
401
402/// Whether a *held* stroke means it again. One press is always one action; a
403/// hold is only ever a value running, so this is what tells the two apart.
404///
405/// The cards' arrows, because that is what every one of them moves a slider
406/// with -- and only the arrows, so the equalizer's `r` cannot flatten five
407/// bands forty times a second and the silence card's `enter` cannot cut forty
408/// places again on the next tick. Outside a card the volume pair and nothing
409/// else: play, cut, delete, save, export and every other binding is a one-shot,
410/// exactly as it was when the handler filtered every held key alike.
411pub(crate) fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool {
412 match scope {
413 Repeat::Card => matches!(key, "up" | "down" | "left" | "right"),
414 Repeat::Keymap => matches!(
415 action,
416 Some(
417 ActionId::VolumeUp
418 | ActionId::VolumeDown
419 // A zoom is a value being moved as much as a level is:
420 // held, it runs from the whole timeline down to a handful
421 // of frames and stops there. The fit is one press.
422 | ActionId::ZoomIn
423 | ActionId::ZoomOut
424 )
425 ),
426 Repeat::Nothing => false,
427 }
428}