edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBef5832fTahinli3 months ago597 commits
| 1 | //! What a pointer is doing: the drags, the ghosts, the trims and the key repeat. |
| 2 | |
| 3 | use 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. |
| 8 | pub PathBuf, pub 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 | |
| 16 | pub |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 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. |
| 33 | pub 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 | |
| 41 | pub |
| 42 | |
| 43 | |
| 44 | |
| 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 | |
| 52 | pub 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 | |
| 61 | pub |
| 62 | |
| 63 | |
| 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 | |
| 76 | pub |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 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 | |
| 95 | pub |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 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. |
| 117 | pub 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. |
| 125 | pub 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. |
| 129 | pub 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 | |
| 140 | pub |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 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. |
| 158 | pub |
| 159 | |
| 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. |
| 172 | pub |
| 173 | |
| 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. |
| 184 | pub |
| 185 | |
| 186 | |
| 187 | |
| 188 | /// The sheet a card with a *slider* in it takes instead: the same scrim, with |
| 189 | /// the window's own drag listeners on it as well. |
| 190 | /// |
| 191 | /// A scrim occludes, and occluding is where gpui's hit test stops |
| 192 | /// (`Hitbox::is_hovered`, window.rs:788) -- so while a card is up the root is |
| 193 | /// not hovered anywhere behind it and its `on_mouse_move`/`on_mouse_up` hear |
| 194 | /// nothing at all. Every drag in this window is tracked from the root, because |
| 195 | /// each of them starts on a strip a few pixels wide that the pointer leaves at |
| 196 | /// once ([`Player::drag_move`]), so a card's handles were set by the press and |
| 197 | /// then frozen: the value never followed the hand and the release never wrote. |
| 198 | /// The scrim is the one surface above the occluder that covers the whole card, |
| 199 | /// so the same two listeners go here, and a drag that leaves the card is picked |
| 200 | /// up by the root's copy of them without a seam. |
| 201 | pub |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | /// The seam between two panels, and the handle that resizes them: a strip |
| 208 | /// [`SPLIT_W`] wide with the resize cursor of its axis on it, which is the whole |
| 209 | /// of how a person finds out the layout moves at all. |
| 210 | /// |
| 211 | /// The press is all this element does. The gesture itself is the root's, like |
| 212 | /// every other drag in this window ([`Player::drag_move`]): a 6 px strip is not |
| 213 | /// where the pointer stays, and a divider whose own listeners tracked it would |
| 214 | /// stop following the hand on the first move. `stop_propagation` so the press |
| 215 | /// never reaches the region under it -- a seam over the timeline must not scrub. |
| 216 | pub |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | /// A press that stops here. What every card's body hands its scrim: the scrim |
| 236 | /// closes the card on a press, and the card is painted after it, so this listener |
| 237 | /// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant |
| 238 | /// for a button never closes the card out from under its own click -- the rule |
| 239 | /// the menus already follow ([`Player::library_card`]). |
| 240 | pub |
| 241 | |
| 242 | |
| 243 | |
| 244 | /// How close to an edge a dragged clip has to be let go for it to land *on* it: |
| 245 | /// the snap every timeline has, in pixels rather than frames so that it feels |
| 246 | /// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two |
| 247 | /// takes must still be able to leave a gap of a few frames there. |
| 248 | pub const SNAP_PX: f64 = 5.; |
| 249 | |
| 250 | /// The scrollbar's thumb never narrows past this, however long the timeline: |
| 251 | /// a thumb a pixel wide is a thumb no hand can hold. A quarter of the ruler's |
| 252 | /// own seek strip, which is the idiom it sits under. |
| 253 | pub const SCROLL_THUMB_MIN: f32 = 24.; |
| 254 | |
| 255 | /// The thickness of a scrollbar strip's hit area, in the one dimension the |
| 256 | /// strip spans: the height of the horizontal one under the lanes, the width |
| 257 | /// of the vertical one on the beds' right edge. The bar inside it looks 6 px, |
| 258 | /// and the strip that takes the press is thicker for the ruler strip's |
| 259 | /// reason -- a hand must be able to find it without aiming (WCAG 2.5.8). |
| 260 | pub const SCROLL_HIT: f32 = 14.; |
| 261 | |
| 262 | /// Where a held key would land, which is the whole of what auto-repeat has to |
| 263 | /// know. [`Player::repeat_scope`] answers it from the same state the handler |
| 264 | /// walks below itself. |
| 265 | |
| 266 | pub |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | /// Whether a *held* stroke means it again. One press is always one action; a |
| 279 | /// hold is only ever a value running, so this is what tells the two apart. |
| 280 | /// |
| 281 | /// The cards' arrows, because that is what every one of them moves a slider |
| 282 | /// with -- and only the arrows, so the equalizer's `r` cannot flatten five |
| 283 | /// bands forty times a second and the silence card's `enter` cannot cut forty |
| 284 | /// places again on the next tick. Outside a card the volume pair and nothing |
| 285 | /// else: play, cut, delete, save, export and every other binding is a one-shot, |
| 286 | /// exactly as it was when the handler filtered every held key alike. |
| 287 | pub |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | /// The keys that are only ever half a chord. gpui delivers a lone modifier |
| 307 | /// press as a keystroke of its own, and taking one as a binding would leave an |
| 308 | /// action that fires the moment the user reaches for any chord that uses it -- |
| 309 | /// so a capture waits through them instead. |
| 310 | pub |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 |