forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBef5832fTahinli3 months ago597 commits

layout.rs544 lines, 27.4 KiBHistoryRawDownload
1//! The window's fixed geometry: what every region is measured in.
2
3use crate::*;
4
5/// ...and the narrowest it is drawn: a library row whose length the engine has
6/// not measured yet has a landing place but no width, and a head marker says
7/// where it goes where a zero-width box would say nothing.
8pub(crate) const GHOST_MIN: f32 = 2.;
9
10/// Fixed so the video region takes every pixel the window gains and the controls
11/// never clip at 640x360.
12pub(crate) const HEADER_H: f32 = 32.;
13// 28 button row + 24 scrub strip + two 48 lanes + the timecode line + the gaps
14// between them, with a few px of slack so a taller text line cannot push a lane
15// off the bottom. The window measures itself from [`timeline_h`] now, so this
16// figure is the guards' anchor for it and sits with them.
17#[cfg(test)]
18pub(crate) const PANEL_H: f32 = 220.;
19/// How many lane rows are drawn before the lane column starts scrolling: past
20/// this the panel would be taller than the picture it belongs under, and a
21/// timeline that pushes the video off the window is not a timeline.
22pub(crate) const LANES_MAX: usize = 6;
23pub(crate) const LANE_H: f32 = 48.;
24/// A caption lane's own height, thinner than a media one: a subtitle box
25/// carries a name, a rate badge and the cue band under it
26/// ([`Player::lane_row`]) and none of a clip's waveform or its full-height
27/// plate, so the strip that used to draw the whole row's worth of nothing is
28/// the regression this constant undoes.
29///
30/// Floored at [`HIT_MIN`] rather than the 20 px a first pass at "thin" landed
31/// on: the header's show/hide eye is the row's one surviving click target
32/// once the remove button moves off it onto the right button
33/// ([`Player::lane_row`]), and that eye fills the row's full height -- so
34/// anything under `HIT_MIN` here is a WCAG 2.5.8 target shrunk to chase a
35/// pixel count, not a thinner lane. This is the whole gap between the two
36/// harness variants the task asked for: 20 is not shippable at all, 24 is,
37/// so 24 is the only variant landed.
38pub(crate) const SUB_LANE_H: f32 = HIT_MIN;
39/// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes
40/// and the ruler above them start at the same pixel and are the same width --
41/// one x-to-time mapping for the whole timeline. `HEADER_GAP` is part of that
42/// offset and is therefore shared by all three rows.
43pub(crate) const HEADER_W: f32 = 40.;
44pub(crate) const HEADER_GAP: f32 = 4.;
45/// The label row inside a clip; a waveform paints under it, never through it.
46pub(crate) const LABEL_H: f32 = 15.;
47/// A clip narrower than this shows no name: two characters and an ellipsis say
48/// nothing that the tint has not already said, and cost the picture a smear.
49pub(crate) const LABEL_MIN_W: f32 = 36.;
50/// Peak buckets per second of source. Fixed and modest on purpose: `peaks`
51/// allocates one bucket per window, so a rate taken from anything the user can
52/// influence is an allocation bomb -- and 40 is already finer than the pixels a
53/// clip is ever given.
54///
55/// corner-cut: "finer than the pixels" stops being true once the timeline is
56/// zoomed -- past ~25 ms per bucket the envelope reads as steps rather than as
57/// a shape. Ceiling: [`View::max_zoom`]'s 8 frames across the bed. The upgrade
58/// is a second, finer pass over the visible span only, cached like `waves` is.
59pub(crate) const WAVE_BPS: u32 = 40;
60/// How many stand-ins may be in flight at once -- the engine's own number, not
61/// a second one that happens to agree: the proxy cache sweeps with room left
62/// for exactly this many encodes ([`engine::proxy::reserve`]), so a front-end
63/// that started more would put the disk past the cap by whatever it added.
64pub(crate) const PROXIES_AT_ONCE: usize = engine::proxy::AT_ONCE;
65/// Pixels per envelope column. Coarser than a pixel: the eye reads the shape,
66/// and a path with a point per pixel is a path per repaint.
67pub(crate) const WAVE_COL: f32 = 2.;
68/// The most columns one envelope is ever built from. A waveform is drawn into
69/// the slice of its box that is on the bed ([`visible_slice`]), and a bed is a
70/// screen wide, so nothing on screen ever reaches this -- it is the backstop for
71/// a box laid out wider than any screen, whose path would otherwise cost a point
72/// per two pixels of a width nobody can see and stall the repaint that was
73/// meant to draw the wave.
74pub(crate) const WAVE_COLS_MAX: usize = 4096;
75/// WCAG 2.5.8: nothing clickable is smaller than this. The scrub bar stays 6 px
76/// to look at -- `RULER_HIT_H` is the strip that has to be hit.
77pub(crate) const HIT_MIN: f32 = 24.;
78/// The media library's column: a share of the window rather than a fixed width,
79/// so it yields on a narrow one, and never more than a third of it -- the
80/// picture is what this program is for and keeps the majority at every size.
81/// The floor is what a file name and a timecode need to be readable at all.
82pub(crate) const LIBRARY_FRAC: f32 = 0.2;
83pub(crate) const LIBRARY_MIN_W: f32 = 120.;
84pub(crate) const LIBRARY_MAX_W: f32 = 220.;
85/// A library row: a name over its duration, two lines and a click target, so
86/// `HIT_MIN` binds it like every other one.
87pub(crate) const ROW_H: f32 = 32.;
88/// The tint swatch down the left of a row: the same colour that source's clips
89/// wear in the lanes, which is the whole of the panel<->timeline association.
90pub(crate) const SWATCH_W: f32 = 4.;
91/// How far the encode has come, drawn under the stop square on a library row.
92/// Inside a `HIT_MIN` cell with a little air each side, so the bar never reaches
93/// the edge of the target it belongs to.
94pub(crate) const PROXY_BAR_W: f32 = HIT_MIN - 10.;
95pub(crate) const CONTROL_H: f32 = 28.;
96/// The volume slider beside its button: a hundred steps across it, so a pixel
97/// is finer than a step and the drag reads as continuous.
98pub(crate) const VOLUME_W: f32 = 110.;
99pub(crate) const RULER_HIT_H: f32 = HIT_MIN;
100/// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits
101/// cannot push the layout around.
102pub(crate) const TIME_W: f32 = 200.;
103/// The keybindings card: a row per action, a title and a status line, inside a
104/// 360 px tall window. The rows are click targets, so `HIT_MIN` binds them too.
105/// Wider than the export card, and for the same reason that one is wider than
106/// this used to be: at 320 the longest labels ("Remove the last video track (it
107/// must be empty)") ran straight over the stroke printed at the other end of
108/// their row. Every label in the registry fits beside its stroke here, and the
109/// one that cannot -- a row waiting for a key to be pressed -- truncates rather
110/// than overprinting. Still inside the 640 px floor.
111pub(crate) const KEYS_W: f32 = 480.;
112pub(crate) const KEYS_ROW_H: f32 = HIT_MIN;
113/// How much of the row list is on screen at once; past this it scrolls. What
114/// keeps the card inside the smallest window no matter how many actions the
115/// editor grows -- ten rows fit here, and the eleventh is a scroll away.
116pub(crate) const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H;
117/// The same for the export card, which carries two summary lines and a button
118/// under its list and so has less room: a section header, six codecs, the
119/// container, five qualities and the destination are more rows than a 360 px
120/// window holds. Eight on screen, which is the whole format section and its
121/// header -- what a user picks first is never behind a scroll.
122pub(crate) const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H;
123/// The export card is wider than the keybindings one: its rows carry a key, a
124/// name *and* what the choice means, and the two summary lines under them state
125/// the whole file. At `KEYS_W` every one of those wrapped to two lines, which is
126/// the card the user called unfriendly. Still inside the 640 px floor with the
127/// scrim showing either side of it.
128pub(crate) const EXPORT_W: f32 = 420.;
129/// The column the key of a row is printed in, wide enough for `0–9`: every row
130/// in the export card says what picks it, so the card is drivable by keyboard
131/// without a legend to memorise.
132pub(crate) const EXPORT_KEY_W: f32 = 26.;
133/// Everything in the export card that is *not* the row list: the title, the
134/// status line, the head and tail of the summary, the button, the gaps between
135/// them and the padding around the lot. What the list may be is the window
136/// minus this -- and never less than [`EXPORT_ROWS_H`], which is the number
137/// that makes the card fit the 360 px floor.
138pub(crate) const EXPORT_FIXED_H: f32 = 17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.;
139/// The menu a right-click on a clip opens: wide enough for the longest label
140/// beside the stroke that does the same thing, with the click targets `HIT_MIN`
141/// binds like every other list here.
142pub(crate) const MENU_W: f32 = 260.;
143pub(crate) const MENU_ROW_H: f32 = HIT_MIN;
144pub(crate) const MENU_PAD: f32 = 6.;
145
146/// A cue's text, and the line it sits on. Fixed rather than a share of the
147/// picture: the video region is 108 px tall at the 640x360 floor and a
148/// proportional size there would be unreadable at exactly the size where it has
149/// to be read.
150pub(crate) const SUB_TEXT: f32 = 14.;
151pub(crate) const SUB_LINE_H: f32 = 18.;
152/// How far off the bottom of the picture the plate sits.
153pub(crate) const SUB_BOTTOM: f32 = 8.;
154/// The same, once the transient bars that hang off that bottom edge (import,
155/// seek, notice) are `bars_h` tall: the cue steps up over them and comes back
156/// down the frame they leave, which is what a player does with its OSD -- the
157/// alternative, a notice drawn over the line being read, loses both of them.
158///
159/// `bars_h` is *measured* ([`height_probe`]) and never counted: a notice wraps
160/// to as many lines as the window is narrow, and any constant here would be
161/// right at one width. Nothing hanging there means nothing to step over, so the
162/// no-notice position is [`SUB_BOTTOM`] exactly, to the pixel.
163pub(crate) fn sub_bottom(bars_h: f32) -> f32 {
164 // A box that was never painted measures zero, and a negative is not a
165 // height -- either way there is nothing to clear.
166 SUB_BOTTOM + bars_h.max(0.)
167}
168/// A mark narrower than this is still drawn this wide: a one-frame cue on a
169/// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says
170/// the track is empty. The silence preview's marks are floored by it too -- they
171/// are the same kind of thing, a picture of where something is and no target.
172pub(crate) const SUB_CUE_MIN_W: f32 = 2.;
173/// How much of the subtitle list in the library column is on screen at once,
174/// past which it scrolls -- the media list above it is what keeps the height.
175pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H;
176/// The row naming the file a block of tracks came out of. Always drawn where
177/// there is more than one file -- the list already scrolls past `SUB_ROWS_H`,
178/// so a short window loses tracks under the fold rather than the name saying
179/// whose they are. A click folds it, so it binds `HIT_MIN` like every other
180/// target.
181pub(crate) const SUB_HEAD_H: f32 = HIT_MIN;
182/// How much of a subtitle row's width the file's name in front of the label may
183/// take. Half: which file and which language are both worth reading, and a name
184/// given the whole row is a row where the language is what gets truncated.
185pub(crate) const SUB_STEM_SHARE: f32 = 0.5;
186/// Roughly how wide one character of an 11 px list row is. Generous on purpose:
187/// the element truncates for real, and a budget that overshoots would have the
188/// element cut the tail off after [`clip_middle`] had already kept it.
189pub(crate) const LIST_CHAR_W: f32 = 6.;
190/// The fewest characters a clipped name is cut to, however narrow the column
191/// gets: past this there is nothing on either side of the gap to read.
192pub(crate) const LIST_CLIP_MIN: usize = 5;
193/// How long the export card's Subtitles line may get before it counts tracks
194/// instead of naming them ([`subtitle_plan`]). Three lines of that row's value
195/// box, at [`LIST_CHAR_W`] to a character: [`EXPORT_W`] less the row's padding
196/// and gap, its tick and [`EXPORT_KEY_W`] key column, and the word "Subtitles"
197/// in front of the value. Not a track count -- what walks the Destination row
198/// off the bottom of the card is the *wrapping*, and thirty-five one-word
199/// labels wrap less than three long ones.
200pub(crate) const SUB_PLAN_CHARS: usize = (3.
201 * (EXPORT_W - 12. - 12. - (10. + 8. + EXPORT_KEY_W + 8. + 9. * LIST_CHAR_W))
202 / LIST_CHAR_W) as usize;
203
204/// The one key name this file still spells out, and gpui's spelling of it: it
205/// is the way out of a capture and out of the overlay, and both have to work
206/// while the keymap itself is what is being changed -- so neither can go
207/// through the keymap to find it.
208pub(crate) const ESCAPE: &str = "escape";
209
210/// How tall a column of `lanes` rows is, gaps included -- the panel's own gap
211/// between them, since the rows sit in it.
212pub(crate) fn lanes_h(lanes: usize) -> f32 {
213 match lanes {
214 0 => 0.,
215 n => n as f32 * LANE_H + (n - 1) as f32 * 8.,
216 }
217}
218
219/// How tall one lane row is: [`LANE_H`] for a media track, [`SUB_LANE_H`] for
220/// a caption one -- the one place that answer is decided, since
221/// [`lanes_h_mixed`], [`lanes_shown_mixed`] and [`rows_below_mixed`] all walk
222/// off it and a track drawn at one height and measured at another is a fold
223/// line that lands on the wrong row.
224pub(crate) fn lane_h(kind: LaneKind) -> f32 {
225 match kind {
226 LaneKind::Subtitle => SUB_LANE_H,
227 LaneKind::Video | LaneKind::Audio => LANE_H,
228 }
229}
230
231/// [`lanes_h`] for a real stack of lanes rather than a bare count: a project
232/// with a caption track in it is shorter than that many `LANE_H` rows, and
233/// the column, the fold and the affordance below it all have to agree on
234/// exactly how much shorter, or "N more below" is answering a box nothing
235/// draws at.
236pub(crate) fn lanes_h_mixed(kinds: &[LaneKind]) -> f32 {
237 match kinds.len() {
238 0 => 0.,
239 n => kinds.iter().copied().map(lane_h).sum::<f32>() + (n - 1) as f32 * 8.,
240 }
241}
242
243/// [`lanes_shown`] for a real stack: the largest prefix of `kinds` whose
244/// drawn height still fits `box_h`, on the same boundary [`lanes_shown`]
245/// draws it at (`lanes_h(k) <= box_h`) -- so a uniform stack answers exactly
246/// what [`lanes_shown`] already did, and a mixed one answers the row count
247/// its own heights actually reach.
248pub(crate) fn lanes_shown_mixed(kinds: &[LaneKind], box_h: f32) -> usize {
249 (0..=kinds.len())
250 .rev()
251 .find(|&k| lanes_h_mixed(&kinds[..k]) <= box_h)
252 .unwrap_or(0)
253 .max(1)
254}
255
256/// [`rows_below`] for a real stack: `scrolled` read against each row's own
257/// top rather than a uniform `LANE_H + 8` stride, so a column with a thin
258/// caption track in it still says the true count once that track has
259/// scrolled by.
260pub(crate) fn rows_below_mixed(kinds: &[LaneKind], box_h: f32, scrolled: f32) -> usize {
261 // Row `k`'s own top, in the same units `scrolled` is given in: nothing
262 // for the first row, and every row before it plus the gap that follows
263 // each one for the rest.
264 let top = |k: usize| -> f32 {
265 match k {
266 0 => 0.,
267 k => lanes_h_mixed(&kinds[..k]) + 8.,
268 }
269 };
270 let past = (0..=kinds.len())
271 .min_by(|&a, &b| {
272 (scrolled - top(a))
273 .abs()
274 .partial_cmp(&(scrolled - top(b)).abs())
275 .unwrap()
276 })
277 .unwrap_or(0);
278 kinds
279 .len()
280 .saturating_sub(past + lanes_shown_mixed(kinds, box_h))
281}
282
283/// The same question for a column whose rows are not one height -- the
284/// inspector's sections -- answered in pixels off what the scroll itself
285/// reports: how far it may still be taken (`max_offset`) less how far it has
286/// been (`offset`, which gpui keeps negative going down).
287pub(crate) fn px_below(max_offset_h: f32, offset_y: f32) -> f32 {
288 (max_offset_h + offset_y).max(0.)
289}
290
291/// How tall the panel is with `lanes` tracks in it: [`PANEL_H`] is sized for the
292/// two a project starts with, and every further one adds its own row -- up to
293/// [`LANES_MAX`], past which the lane column scrolls instead and the panel stops
294/// growing. Only the guards ask, so it sits with them.
295#[cfg(test)]
296pub(crate) fn panel_h(lanes: usize) -> f32 {
297 PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2)
298}
299
300/// How tall the timeline region is: its own padding, the timecode line, the
301/// ruler, the scrollbar strip under the lanes when there is one to draw, and
302/// the gaps between them, plus a row per lane. Measured from its parts rather
303/// than taken off `PANEL_H` -- the button row moved out of it
304/// ([`Player::toolbar`]), and a height still carrying that row's pixels is a
305/// height that cuts the last lane off the bottom of the window.
306pub(crate) fn timeline_h(lanes: usize, scroll: bool) -> f32 {
307 timeline_fixed_h(scroll) + lanes_h(lanes.clamp(2, LANES_MAX))
308}
309
310/// 8+8 padding, the timecode line, the 24 px ruler strip and the two 8 px gaps
311/// between the three rows, with a couple of px of slack so a taller text line
312/// cannot push a lane off the bottom. The scrollbar strip's row is *not* here:
313/// the strip comes and goes with the zoom, so its pixels are carried by
314/// [`timeline_fixed_h`] alone, where every derivation that must agree with
315/// what is drawn reads them together.
316pub(crate) const TIMELINE_FIXED_H: f32 = 16. + 18. + 8. + RULER_HIT_H + 8. + 4.;
317
318/// The panel's fixed furniture with its scrollbar strip while the timeline has
319/// somewhere to scroll to. With nowhere to go the strip is not drawn -- a bar
320/// for a view that cannot move is a bar teaching nothing -- and its row goes
321/// with it, out of every budget at once: a height still carrying the row would
322/// hand it to the lane column as a bonus at exactly the zoom where the hand is
323/// least expecting the bed to move.
324pub(crate) fn timeline_fixed_h(scroll: bool) -> f32 {
325 TIMELINE_FIXED_H + match scroll {
326 true => 8. + SCROLL_HIT,
327 false => 0.,
328 }
329}
330
331/// The most of a short window the timeline may take, sized so the seam's own
332/// floor still fits inside it ([`split_bounds`]): at the 640x360 floor that is
333/// 171 px of the 360 -- the chrome with the scrollbar strip in it, one whole
334/// lane, and the line saying the rest are below. Left smaller than the floor
335/// the floor would win the clamp anyway and this number would say the panel
336/// takes less of a short window than it does. The lanes scroll inside whatever
337/// is left, which leaves the picture a region rather than a letterbox stripe.
338pub(crate) const TIMELINE_SHARE: f32 = 171. / 360.;
339
340/// The edit toolbar directly above the timeline: one control's height in its
341/// own padding, fixed so nothing in it can push the timeline down.
342pub(crate) const TOOLBAR_H: f32 = CONTROL_H + 16.;
343
344/// The top bar: the project's name on the left, the two file actions on the
345/// right. Fixed for the reason [`HEADER_H`] is.
346pub(crate) const TOPBAR_H: f32 = 36.;
347
348/// The transport strip under the picture -- play, timecode, volume -- where a
349/// player's own controls live in every consumer editor.
350pub(crate) const TRANSPORT_H: f32 = CONTROL_H + 12.;
351
352/// One press of a zoom key, or one notch of ctrl+wheel.
353pub(crate) const ZOOM_STEP: f32 = 1.25;
354
355/// How far one notch of a bare wheel slides the view along, as a share of what
356/// is on the bed. A *share* rather than a number of pixels or of seconds: one
357/// gesture then moves the same fraction of what is being looked at whether the
358/// bed is showing five seconds or five hours, which is the only way a wheel is
359/// usable at both ends of the zoom.
360pub(crate) const SCROLL_NOTCH_SHARE: f32 = 0.1;
361
362/// How few frames the bed may be narrowed down to. Past this there is nothing
363/// left to aim at -- a single frame across a whole window is a wall of colour,
364/// not an edit surface.
365pub(crate) const ZOOM_MIN_FRAMES: f64 = 8.;
366
367/// How thin a second of timeline may be drawn on a bed that is already showing
368/// all of it: the far stop for a *short* project, which has no length of its own
369/// worth widening to, so a five second import can still be zoomed out of.
370pub(crate) const PPS_MIN: f64 = 1.;
371
372/// How much bed the far stop leaves past the last frame, as a multiple of the
373/// timeline's own length -- so a timeline zoomed all the way out ends a sliver
374/// short of the window's edge rather than glued to it.
375pub(crate) const ZOOM_OUT_MARGIN: f64 = 1.05;
376
377/// How wide a second of timeline is drawn before anyone zooms: a five second
378/// import is 200 px of a bed several times that, so a short clip reads as
379/// short -- the thing a bed scaled to the content's own length cannot say.
380/// [`View::fit`] is the one way back to "the whole timeline across the bed".
381pub(crate) const PPS_DEFAULT: f64 = 40.;
382
383// -- the seams between the regions, and where a hand has dragged them ---------
384
385/// Which divider a hand has hold of. The three seams the main layout has --
386/// library|picture, picture|inspector and the timeline's top edge -- and so the
387/// only three sizes in this window a person sets rather than is given.
388#[derive(Clone, Copy, PartialEq, Eq, Debug)]
389pub(crate) enum Split {
390 Library,
391 Inspector,
392 Timeline,
393}
394
395/// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands
396/// in for: a seam nobody can put a pointer on is a seam nobody can drag, which
397/// is why every editor that ships this draws a strip rather than the hairline
398/// it looks like.
399pub(crate) const SPLIT_W: f32 = 6.;
400
401/// The most of the window one side column may be dragged to. A third each, so
402/// the picture keeps the middle at every size -- the rule [`library_w`] and
403/// [`inspector_w`] already lay an untouched window out by, kept once the hand
404/// takes over.
405pub(crate) const SIDE_MAX_FRAC: f32 = 1. / 3.;
406
407/// The most of the window the timeline may be dragged to. Past
408/// [`TIMELINE_SHARE`], which is what it is *given*: a hand asking for a tall
409/// timeline is asking on purpose, and the picture still keeps most of a third.
410pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7;
411
412/// What a hand has done to the three seams: the size it dragged each panel to,
413/// or `None` where nobody has touched one and the window's own share still
414/// answers. Held in the model and not recomputed, so a size outlives the
415/// release -- and read through [`split_size`], so it cannot outlive the window
416/// it was set in.
417#[derive(Clone, Copy, Default)]
418pub(crate) struct Splits {
419 library: Option<f32>,
420 inspector: Option<f32>,
421 timeline: Option<f32>,
422}
423
424impl Splits {
425 pub(crate) fn get(&self, split: Split) -> Option<f32> {
426 match split {
427 Split::Library => self.library,
428 Split::Inspector => self.inspector,
429 Split::Timeline => self.timeline,
430 }
431 }
432
433 pub(crate) fn set(&mut self, split: Split, size: f32) {
434 *match split {
435 Split::Library => &mut self.library,
436 Split::Inspector => &mut self.inspector,
437 Split::Timeline => &mut self.timeline,
438 } = Some(size);
439 }
440}
441
442/// How small a panel may be dragged and how large: the floor is the size it
443/// still shows something at, the ceiling is what its neighbour needs to stay a
444/// region rather than a sliver. Neither end is passable -- a panel dragged to
445/// nothing is a panel nobody can get back, and a picture squeezed out by two
446/// side columns is the same loss on the other side of the window.
447pub(crate) fn split_bounds(
448 split: Split,
449 lanes: usize,
450 window: Size<Pixels>,
451 scroll: bool,
452) -> (f32, f32) {
453 let (w, h) = (f32::from(window.width), f32::from(window.height));
454 match split {
455 Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC),
456 Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),
457 // One whole lane under the chrome, the scrollbar strip's row included
458 // while there is one to draw ([`timeline_fixed_h`]): a timeline
459 // shorter than that is a ruler with nothing beneath it. A second
460 // track pays for the line that says the rest are below the fold as
461 // well -- at this height only one row fits, so that line is *always*
462 // drawn there, and it is drawn inside the region
463 // ([`Player::timeline`]). Left out of the floor it comes off the
464 // lane's own pixels, and the one lane the floor promises is a header
465 // cut in half.
466 Split::Timeline => (
467 // `LANE_H` even though the first lane could be a thinner caption
468 // one: a floor is a *minimum*, so the only failure mode of
469 // reading it off the tallest kind is a seam that refuses to go
470 // quite as small as it technically could -- never a lane clipped
471 // short of its own row. corner-cut: exact per-kind floor would
472 // read `session.lanes()[0].kind`, which `split_bounds` is not
473 // handed; ceiling is one drawn-too-tall pixel at the very floor
474 // of a caption-only project, upgrade is threading the real lane
475 // list through here the way [`lanes_h_mixed`] already takes it.
476 timeline_fixed_h(scroll)
477 + LANE_H
478 + match lanes > 1 {
479 true => LABEL_H + 8.,
480 false => 0.,
481 },
482 h * TIMELINE_MAX_SHARE,
483 ),
484 }
485}
486
487pub(crate) fn split_size(
488 split: Split,
489 set: Option<f32>,
490 lanes: usize,
491 window: Size<Pixels>,
492 scroll: bool,
493) -> f32 {
494 let (w, h) = (f32::from(window.width), f32::from(window.height));
495 let (min, max) = split_bounds(split, lanes, window, scroll);
496 let default = match split {
497 Split::Library => library_w(w),
498 Split::Inspector => inspector_w(w),
499 Split::Timeline => timeline_h(lanes, scroll).min(h * TIMELINE_SHARE),
500 };
501 // The floor wins a window too small to honour both ends: a panel at its
502 // floor is still a panel, and `clamp` panics outright on a ceiling under
503 // its floor.
504 set.unwrap_or(default).clamp(min, max.max(min))
505}
506
507/// Where a divider drag puts the panel it belongs to: the pointer's position
508/// turned into that panel's size. Half a strip is taken off each answer because
509/// the strip is grabbed by its middle -- without it the panel jumps a strip's
510/// width on the press and then trails the pointer for the rest of the gesture.
511pub(crate) fn split_drag_size(split: Split, at: Point<Pixels>, window: Size<Pixels>) -> f32 {
512 let (x, y) = (f32::from(at.x), f32::from(at.y));
513 let (w, h) = (f32::from(window.width), f32::from(window.height));
514 match split {
515 Split::Library => x - SPLIT_W / 2.,
516 Split::Inspector => w - x - SPLIT_W / 2.,
517 // This seam sits above the edit toolbar, which is a fixed height: what
518 // is under the pointer is the toolbar and the timeline together.
519 Split::Timeline => h - y - TOOLBAR_H - SPLIT_W / 2.,
520 }
521}
522
523impl Player {
524 /// How big the panel on this seam is this frame -- the one door every
525 /// region measures itself through, so a dragged size and a drawn one cannot
526 /// disagree.
527 pub(crate) fn split_px(&self, split: Split, window: Size<Pixels>) -> f32 {
528 // The pair a fresh project starts with where there is no session yet,
529 // which is what the timeline itself draws (`Player::timeline`).
530 let lanes = self
531 .session
532 .as_ref()
533 .map_or(2, |session| session.lanes().len());
534 // Whether the time axis has anywhere to go: the scrollbar strip is
535 // drawn only while it does, and the region's furniture -- and its
536 // floor -- carry the strip's row only while it is. One door
537 // ([`timeline_fixed_h`]) answers the region, the fold and the floor
538 // together, so the three cannot disagree about whether the strip is
539 // there.
540 let view = self.view();
541 let scroll = view.duration > view.span();
542 split_size(split, self.splits.get(split), lanes, window, scroll)
543 }
544}