forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBf2bee6bTahinli2 months ago781 commits

layout.rs606 lines, 30.0 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/// The label row inside a clip; a waveform paints under it, never through it.
25pub(crate) const LABEL_H: f32 = 15.;
26/// Peak buckets per second of source. Fixed and modest on purpose: `peaks`
27/// allocates one bucket per window, so a rate taken from anything the user can
28/// influence is an allocation bomb -- and 40 is already finer than the pixels a
29/// clip is ever given.
30///
31/// corner-cut: "finer than the pixels" stops being true once the timeline is
32/// zoomed -- past ~25 ms per bucket the envelope reads as steps rather than as
33/// a shape. Ceiling: [`View::max_zoom`]'s 8 frames across the bed. The upgrade
34/// is a second, finer pass over the visible span only, cached like `waves` is.
35pub(crate) const WAVE_BPS: u32 = 40;
36/// How many stand-ins may be in flight at once -- the engine's own number, not
37/// a second one that happens to agree: the proxy cache sweeps with room left
38/// for exactly this many encodes ([`engine::proxy::reserve`]), so a front-end
39/// that started more would put the disk past the cap by whatever it added.
40pub(crate) const PROXIES_AT_ONCE: usize = engine::proxy::AT_ONCE;
41/// Pixels per envelope column. Coarser than a pixel: the eye reads the shape,
42/// and a path with a point per pixel is a path per repaint.
43pub(crate) const WAVE_COL: f32 = 2.;
44/// The most columns one envelope is ever built from. A waveform is drawn into
45/// the slice of its box that is on the bed ([`visible_slice`]), and a bed is a
46/// screen wide, so nothing on screen ever reaches this -- it is the backstop for
47/// a box laid out wider than any screen, whose path would otherwise cost a point
48/// per two pixels of a width nobody can see and stall the repaint that was
49/// meant to draw the wave.
50pub(crate) const WAVE_COLS_MAX: usize = 4096;
51/// WCAG 2.5.8: nothing clickable is smaller than this. The scrub bar stays 6 px
52/// to look at -- `RULER_HIT_H` is the strip that has to be hit.
53pub(crate) const HIT_MIN: f32 = 24.;
54/// The media library's column: a share of the window rather than a fixed width,
55/// so it yields on a narrow one, and never more than a third of it -- the
56/// picture is what this program is for and keeps the majority at every size.
57/// The floor is what a file name and a timecode need to be readable at all.
58pub(crate) const LIBRARY_FRAC: f32 = 0.2;
59pub(crate) const LIBRARY_MIN_W: f32 = 120.;
60pub(crate) const LIBRARY_MAX_W: f32 = 220.;
61pub(crate) const CONTROL_H: f32 = 28.;
62/// The volume slider beside its button: a hundred steps across it, so a pixel
63/// is finer than a step and the drag reads as continuous.
64pub(crate) const VOLUME_W: f32 = 110.;
65pub(crate) const RULER_HIT_H: f32 = HIT_MIN;
66/// The keybindings card: a row per action, a title and a status line, inside a
67/// 360 px tall window. The rows are click targets, so `HIT_MIN` binds them too.
68/// Wider than the export card, and for the same reason that one is wider than
69/// this used to be: at 320 the longest labels ("Remove the last video track (it
70/// must be empty)") ran straight over the stroke printed at the other end of
71/// their row. Every label in the registry fits beside its stroke here, and the
72/// one that cannot -- a row waiting for a key to be pressed -- truncates rather
73/// than overprinting. Still inside the 640 px floor.
74pub(crate) const KEYS_W: f32 = 480.;
75pub(crate) const KEYS_ROW_H: f32 = HIT_MIN;
76/// The export card is wider than the keybindings one: its rows carry a key, a
77/// name *and* what the choice means, and the two summary lines under them state
78/// the whole file. At `KEYS_W` every one of those wrapped to two lines, which is
79/// the card the user called unfriendly. Still inside the 640 px floor with the
80/// scrim showing either side of it.
81pub(crate) const EXPORT_W: f32 = 420.;
82/// The column the key of a row is printed in, wide enough for `0–9`: every row
83/// in the export card says what picks it, so the card is drivable by keyboard
84/// without a legend to memorise.
85pub(crate) const EXPORT_KEY_W: f32 = 26.;
86/// The menu a right-click on a clip opens: wide enough for the longest label
87/// beside the stroke that does the same thing, with the click targets `HIT_MIN`
88/// binds like every other list here.
89pub(crate) const MENU_W: f32 = 260.;
90pub(crate) const MENU_ROW_H: f32 = HIT_MIN;
91pub(crate) const MENU_PAD: f32 = 6.;
92
93/// A cue's text, and the line it sits on. Fixed rather than a share of the
94/// picture: the video region is 108 px tall at the 640x360 floor and a
95/// proportional size there would be unreadable at exactly the size where it has
96/// to be read.
97pub(crate) const SUB_TEXT: f32 = 14.;
98pub(crate) const SUB_LINE_H: f32 = 18.;
99/// How far off the bottom of the picture the plate sits.
100pub(crate) const SUB_BOTTOM: f32 = 8.;
101/// The same, once the transient bars that hang off that bottom edge (import,
102/// seek, notice) are `bars_h` tall: the cue steps up over them and comes back
103/// down the frame they leave, which is what a player does with its OSD -- the
104/// alternative, a notice drawn over the line being read, loses both of them.
105///
106/// `bars_h` is *measured* ([`height_probe`]) and never counted: a notice wraps
107/// to as many lines as the window is narrow, and any constant here would be
108/// right at one width. Nothing hanging there means nothing to step over, so the
109/// no-notice position is [`SUB_BOTTOM`] exactly, to the pixel.
110pub(crate) fn sub_bottom(bars_h: f32) -> f32 {
111 // A box that was never painted measures zero, and a negative is not a
112 // height -- either way there is nothing to clear.
113 SUB_BOTTOM + bars_h.max(0.)
114}
115/// A mark narrower than this is still drawn this wide: a one-frame cue on a
116/// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says
117/// the track is empty. The silence preview's marks are floored by it too -- they
118/// are the same kind of thing, a picture of where something is and no target.
119pub(crate) const SUB_CUE_MIN_W: f32 = 2.;
120/// Roughly how wide one character of an 11 px list row is. Generous on purpose:
121/// the element truncates for real, and a budget that overshoots would have the
122/// element cut the tail off after [`clip_middle`] had already kept it.
123pub(crate) const LIST_CHAR_W: f32 = 6.;
124/// How long the export card's Subtitles line may get before it counts tracks
125/// instead of naming them ([`subtitle_plan`]). Three lines of that row's value
126/// box, at [`LIST_CHAR_W`] to a character: [`EXPORT_W`] less the row's padding
127/// and gap, its tick and [`EXPORT_KEY_W`] key column, and the word "Subtitles"
128/// in front of the value. Not a track count -- what walks the Destination row
129/// off the bottom of the card is the *wrapping*, and thirty-five one-word
130/// labels wrap less than three long ones.
131pub(crate) const SUB_PLAN_CHARS: usize = (3.
132 * (EXPORT_W - 12. - 12. - (10. + 8. + EXPORT_KEY_W + 8. + 9. * LIST_CHAR_W))
133 / LIST_CHAR_W) as usize;
134
135/// The one key name this file still spells out, and gpui's spelling of it: it
136/// is the way out of a capture and out of the overlay, and both have to work
137/// while the keymap itself is what is being changed -- so neither can go
138/// through the keymap to find it.
139pub(crate) const ESCAPE: &str = "escape";
140
141/// How tall a column of `lanes` rows is, gaps included -- the panel's own gap
142/// between them, since the rows sit in it.
143pub(crate) fn lanes_h(lanes: usize) -> f32 {
144 match lanes {
145 0 => 0.,
146 n => n as f32 * LANE_H + (n - 1) as f32 * 8.,
147 }
148}
149
150/// The same question for a column whose rows are not one height -- the
151/// inspector's sections -- answered in pixels off what the scroll itself
152/// reports: how far it may still be taken (`max_offset`) less how far it has
153/// been (`offset`, which gpui keeps negative going down).
154pub(crate) fn px_below(max_offset_h: f32, offset_y: f32) -> f32 {
155 (max_offset_h + offset_y).max(0.)
156}
157
158/// How tall the panel is with `lanes` tracks in it: [`PANEL_H`] is sized for the
159/// two a project starts with, and every further one adds its own row -- up to
160/// [`LANES_MAX`], past which the lane column scrolls instead and the panel stops
161/// growing. Only the guards ask, so it sits with them.
162#[cfg(test)]
163pub(crate) fn panel_h(lanes: usize) -> f32 {
164 PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2)
165}
166
167/// How tall the timeline region is: its own padding, the timecode line, the
168/// ruler, the scrollbar strip under the lanes when there is one to draw, and
169/// the gaps between them, plus a row per lane. Measured from its parts rather
170/// than taken off `PANEL_H` -- the button row moved out of it
171/// ([`Player::toolbar`]), and a height still carrying that row's pixels is a
172/// height that cuts the last lane off the bottom of the window.
173pub(crate) fn timeline_h(lanes: usize, scroll: bool) -> f32 {
174 timeline_fixed_h(scroll) + lanes_h(lanes.clamp(2, LANES_MAX))
175}
176
177/// 8+8 padding, the timecode line, the 24 px ruler strip and the two 8 px gaps
178/// between the three rows, with a couple of px of slack so a taller text line
179/// cannot push a lane off the bottom. The scrollbar strip's row is *not* here:
180/// the strip comes and goes with the zoom, so its pixels are carried by
181/// [`timeline_fixed_h`] alone, where every derivation that must agree with
182/// what is drawn reads them together.
183pub(crate) const TIMELINE_FIXED_H: f32 = 16. + 18. + 8. + RULER_HIT_H + 8. + 4.;
184
185/// The panel's fixed furniture with its scrollbar strip while the timeline has
186/// somewhere to scroll to. With nowhere to go the strip is not drawn -- a bar
187/// for a view that cannot move is a bar teaching nothing -- and its row goes
188/// with it, out of every budget at once: a height still carrying the row would
189/// hand it to the lane column as a bonus at exactly the zoom where the hand is
190/// least expecting the bed to move.
191pub(crate) fn timeline_fixed_h(scroll: bool) -> f32 {
192 TIMELINE_FIXED_H
193 + match scroll {
194 true => 8. + SCROLL_HIT,
195 false => 0.,
196 }
197}
198
199/// The most of a short window the timeline may take, sized so the seam's own
200/// floor still fits inside it ([`split_bounds`]): at the 640x360 floor that is
201/// 171 px of the 360 -- the chrome with the scrollbar strip in it, one whole
202/// lane, and the line saying the rest are below. Left smaller than the floor
203/// the floor would win the clamp anyway and this number would say the panel
204/// takes less of a short window than it does. The lanes scroll inside whatever
205/// is left, which leaves the picture a region rather than a letterbox stripe.
206pub(crate) const TIMELINE_SHARE: f32 = 171. / 360.;
207
208/// The edit toolbar directly above the timeline: one control's height in its
209/// own padding, fixed so nothing in it can push the timeline down.
210pub(crate) const TOOLBAR_H: f32 = CONTROL_H + 16.;
211
212/// One press of a zoom key, or one notch of ctrl+wheel.
213pub(crate) const ZOOM_STEP: f32 = 1.25;
214
215/// How far one notch of a bare wheel slides the view along, as a share of what
216/// is on the bed. A *share* rather than a number of pixels or of seconds: one
217/// gesture then moves the same fraction of what is being looked at whether the
218/// bed is showing five seconds or five hours, which is the only way a wheel is
219/// usable at both ends of the zoom.
220pub(crate) const SCROLL_NOTCH_SHARE: f32 = 0.1;
221
222/// How few frames the bed may be narrowed down to. Past this there is nothing
223/// left to aim at -- a single frame across a whole window is a wall of colour,
224/// not an edit surface.
225pub(crate) const ZOOM_MIN_FRAMES: f64 = 8.;
226
227/// How thin a second of timeline may be drawn on a bed that is already showing
228/// all of it: the far stop for a *short* project, which has no length of its own
229/// worth widening to, so a five second import can still be zoomed out of.
230pub(crate) const PPS_MIN: f64 = 1.;
231
232/// How much bed the far stop leaves past the last frame, as a multiple of the
233/// timeline's own length -- so a timeline zoomed all the way out ends a sliver
234/// short of the window's edge rather than glued to it.
235pub(crate) const ZOOM_OUT_MARGIN: f64 = 1.05;
236
237/// How wide a second of timeline is drawn before anyone zooms: a five second
238/// import is 200 px of a bed several times that, so a short clip reads as
239/// short -- the thing a bed scaled to the content's own length cannot say.
240/// [`View::fit`] is the one way back to "the whole timeline across the bed".
241pub(crate) const PPS_DEFAULT: f64 = 40.;
242
243// -- the seams between the regions, and where a hand has dragged them ---------
244
245/// Which divider a hand has hold of. The legacy tree's three seams --
246/// library|picture, picture|inspector and the timeline's top edge -- plus the
247/// darkroom's own two, dock|centre and time-band|bench: `stance.rs`'s own
248/// `BENCH_H`/`DOCK_W` doc comments named this exact fold as the fix for
249/// "fields are not stretchable" before this diff existed.
250#[derive(Clone, Copy, PartialEq, Eq, Debug)]
251pub(crate) enum Split {
252 Library,
253 Inspector,
254 Timeline,
255 Dock,
256 Bench,
257}
258
259impl Split {
260 /// Every seam that survives a restart -- all five regions, the file
261 /// itself the only store (view state stays out of `.edith`, the
262 /// settled convention). Read by [`load_stance_splits`] and
263 /// [`save_stance_splits`] together so the set can never learn a
264 /// different set of keys from each other, the gap a sixth region
265 /// would otherwise fall through silently.
266 pub(crate) const PERSISTED: [Split; 5] = [
267 Split::Library,
268 Split::Inspector,
269 Split::Timeline,
270 Split::Dock,
271 Split::Bench,
272 ];
273
274 fn key(self) -> &'static str {
275 match self {
276 Split::Library => "library",
277 Split::Inspector => "inspector",
278 Split::Timeline => "timeline",
279 Split::Dock => "dock",
280 Split::Bench => "bench",
281 }
282 }
283}
284
285/// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands
286/// in for: a seam nobody can put a pointer on is a seam nobody can drag, which
287/// is why every editor that ships this draws a strip rather than the hairline
288/// it looks like.
289pub(crate) const SPLIT_W: f32 = 6.;
290
291/// How wide the same seam is *aimed at*. The strip above is what the layout
292/// spends and the hairline is what the eye is given; this is the band the hand
293/// gets, centred on the strip and overlaid on the two panels it parts, so
294/// growing it moves nothing. 6 px asked the hand for precision it does not
295/// have -- the lead's own press one row into the bench missed the seam by 5 px
296/// and focused the bench instead ("panes should be enlargable and shrinkable",
297/// of panes that already resized). 12 px is the ±6 px of aim every editor's
298/// dividers allow, and it is hung one row above the strip rather than centred
299/// on it: what a hand aims at is the line it can see (the panel's own edge at
300/// the strip's far side), not the six transparent pixels in front of it.
301pub(crate) const GRAB_W: f32 = 14.;
302
303/// The most of the window one side column may be dragged to. A third each, so
304/// the picture keeps the middle at every size -- the rule [`library_w`] and
305/// [`inspector_w`] already lay an untouched window out by, kept once the hand
306/// takes over.
307pub(crate) const SIDE_MAX_FRAC: f32 = 1. / 3.;
308
309/// The most of the window the timeline may be dragged to. Past
310/// [`TIMELINE_SHARE`], which is what it is *given*: a hand asking for a tall
311/// timeline is asking on purpose, and the picture still keeps most of a third.
312pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7;
313
314/// The room the ledger's own top border (`ui::stance::ledger`'s
315/// `.border_t_1()`) needs kept clear below the bench's own last content
316/// pixel. The ledger sits at a *fixed* distance from the window's own foot
317/// (`ui::stance::LEDGER_H`), not from wherever the bench's content happens
318/// to end, so if the bench's last lane row reaches exactly as far as the
319/// ledger's own top row, the ledger's border -- later in the same flex
320/// column, so it paints over whatever is already there -- wins the shared
321/// pixel rather than sitting cleanly below it. Driven, at [`BENCH_MIN_H`]'s
322/// own third clip: `bench=95` (the stack's exact content need, no spare row)
323/// still lost A1's status dot's last row to the rule; `bench=96` (one row of
324/// clearance) drew it whole. The 95-vs-96 tension is this term, not a
325/// rounding accident -- a bench exactly as tall as its content still shares
326/// its last row with the ledger's border.
327const LEDGER_SEAM_CLEARANCE: f32 = 1.;
328
329/// The least the darkroom's bench may be dragged to: derived, not measured,
330/// from the same stack `ui::stance::bench` and `ui::bench_stance::render`
331/// actually build, top to bottom --
332/// [`crate::ui::stance::BENCH_CHROME_H`] (the "bench" section head's real
333/// line box, plus the bench div's own top border and top padding -- see its
334/// own doc comment) + [`crate::ui::bench_stance::RULER_H`] (the pinned
335/// ruler) + [`crate::ui::bench_stance::ROW_GAP`] (the gap `bench-content`'s
336/// flex column puts between the ruler and the lane column) + two lane rows
337/// at [`crate::ui::bench_stance::LANE_MIN_H`] each (the darkroom's own floor
338/// of two lanes -- V1, A1, `bench_stance::render`'s own no-session
339/// fallback) + one more `ROW_GAP` between those two rows (`bench-lanes`'s
340/// own flex gap) + [`LEDGER_SEAM_CLEARANCE`] (the row the ledger's own
341/// border needs kept clear, see its own doc comment). Below this the
342/// `bench-lanes` column asks for more height than `bench-content`'s flex_1
343/// gives it, and since that column scrolls rather than clips visibly, the
344/// shortfall comes off the bottom row's own pixels unscrolled -- A1's
345/// clip-bar border and status dot, first. `LANE_MIN_H` itself is derived
346/// from what a lane head actually draws (its own doc comment), not a number
347/// copied from nowhere: an earlier floor of `82.` used a `LANE_MIN_H` of
348/// `18.` that fit only the lane label and let every lane's status dot
349/// overflow into the row beneath it, invisible everywhere but the last
350/// lane, which has no next row to spill into and clipped straight into the
351/// ledger instead.
352///
353/// With the 18/15/14-13/12/10px type scale, the same derivation uses a 24px
354/// chrome block and two 27px lane floors:
355/// `24 + 22 + 2 + 54 + 2 + 1` = `105.`.
356pub(crate) const BENCH_MIN_H: f32 = crate::ui::stance::BENCH_CHROME_H
357 + crate::ui::bench_stance::RULER_H
358 + crate::ui::bench_stance::ROW_GAP
359 + 2. * crate::ui::bench_stance::LANE_MIN_H
360 + crate::ui::bench_stance::ROW_GAP
361 + LEDGER_SEAM_CLEARANCE;
362
363/// What a hand has done to the three seams: the size it dragged each panel to,
364/// or `None` where nobody has touched one and the window's own share still
365/// answers. Held in the model and not recomputed, so a size outlives the
366/// release -- and read through [`split_size`], so it cannot outlive the window
367/// it was set in.
368#[derive(Clone, Copy, Default)]
369pub(crate) struct Splits {
370 library: Option<f32>,
371 inspector: Option<f32>,
372 timeline: Option<f32>,
373 dock: Option<f32>,
374 bench: Option<f32>,
375}
376
377impl Splits {
378 pub(crate) fn get(&self, split: Split) -> Option<f32> {
379 match split {
380 Split::Library => self.library,
381 Split::Inspector => self.inspector,
382 Split::Timeline => self.timeline,
383 Split::Dock => self.dock,
384 Split::Bench => self.bench,
385 }
386 }
387
388 /// Forgets a seam's dragged size, which is exactly what
389 /// [`split_size`] reads as "the window's own share answers again" --
390 /// the double-click reset, one field rather than a second table of
391 /// defaults that could disagree with the one already there.
392 pub(crate) fn clear(&mut self, split: Split) {
393 *self.slot(split) = None;
394 }
395
396 pub(crate) fn set(&mut self, split: Split, size: f32) {
397 *self.slot(split) = Some(size);
398 }
399
400 fn slot(&mut self, split: Split) -> &mut Option<f32> {
401 match split {
402 Split::Library => &mut self.library,
403 Split::Inspector => &mut self.inspector,
404 Split::Timeline => &mut self.timeline,
405 Split::Dock => &mut self.dock,
406 Split::Bench => &mut self.bench,
407 }
408 }
409}
410
411/// Where every seam's dragged size lives. Same small, silent round trip as
412/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves a seam
413/// `None`, which [`split_size`] already reads as "give it the window's own
414/// share".
415pub(crate) fn stance_splits_config_path() -> std::path::PathBuf {
416 crate::keymap::Keymap::config_path().with_file_name("stance-splits")
417}
418
419pub(crate) fn load_stance_splits(window: Size<Pixels>) -> Splits {
420 load_stance_splits_from(&stance_splits_config_path(), window)
421}
422
423/// One `split=pixels` line per touched seam, read from `path` -- factored out
424/// of [`load_stance_splits`] so a test can round-trip a scratch file instead
425/// of the real config. `window` is the size the layout is about to be drawn
426/// at -- a file written by a wider or taller window can hold a seam past
427/// this one's own ceiling, so each value is clamped to it here, before it
428/// ever reaches [`Splits`]. [`split_size`] still re-clamps every frame on
429/// top of this, but that clamp needs a lane count and a scroll state
430/// nothing here has yet; this one runs on the three bounds that do not --
431/// [`SIDE_MAX_FRAC`], [`TIMELINE_MAX_SHARE`] and [`BENCH_MIN_H`] -- so a
432/// value this open never reaches even the first frame.
433pub(crate) fn load_stance_splits_from(path: &std::path::Path, window: Size<Pixels>) -> Splits {
434 let (w, h) = (f32::from(window.width), f32::from(window.height));
435 let mut splits = Splits::default();
436 if let Ok(text) = std::fs::read_to_string(path) {
437 for line in text.lines() {
438 let Some((key, value)) = line.split_once('=') else {
439 continue;
440 };
441 let Ok(px) = value.trim().parse::<f32>() else {
442 continue;
443 };
444 let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else {
445 continue;
446 };
447 let px = match split {
448 Split::Library | Split::Inspector | Split::Dock => px.min(w * SIDE_MAX_FRAC),
449 Split::Timeline => px.min(h * TIMELINE_MAX_SHARE),
450 Split::Bench => px.max(BENCH_MIN_H),
451 };
452 splits.set(split, px);
453 }
454 }
455 splits
456}
457
458/// Writes the sizes a hand has actually dragged, one line per seam a hand
459/// has touched. Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field,
460/// so a region added there needs no second, separately-maintained list here.
461pub(crate) fn save_stance_splits(splits: &Splits) {
462 save_stance_splits_to(splits, &stance_splits_config_path());
463}
464
465pub(crate) fn save_stance_splits_to(splits: &Splits, path: &std::path::Path) {
466 let text: String = Split::PERSISTED
467 .into_iter()
468 .filter_map(|split| {
469 splits
470 .get(split)
471 .map(|px| format!("{}={px}\n", split.key()))
472 })
473 .collect();
474 if let Some(dir) = path.parent() {
475 let _ = std::fs::create_dir_all(dir);
476 }
477 let _ = std::fs::write(path, text);
478}
479
480/// How small a panel may be dragged and how large: the floor is the size it
481/// still shows something at, the ceiling is what its neighbour needs to stay a
482/// region rather than a sliver. Neither end is passable -- a panel dragged to
483/// nothing is a panel nobody can get back, and a picture squeezed out by two
484/// side columns is the same loss on the other side of the window.
485pub(crate) fn split_bounds(
486 split: Split,
487 lanes: usize,
488 window: Size<Pixels>,
489 scroll: bool,
490) -> (f32, f32) {
491 let (w, h) = (f32::from(window.width), f32::from(window.height));
492 match split {
493 Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC),
494 Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),
495 // The dock is the darkroom's one side column -- same shape as the
496 // legacy inspector's, so it takes the legacy inspector's own floor
497 // and ceiling rather than a second pair that would only ever agree.
498 Split::Dock => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),
499 // The bench is the darkroom's own timeline, but its ceiling is not
500 // [`Split::Timeline`]'s window-share one: a bench that swallows
501 // `TIMELINE_MAX_SHARE` of a 720p window leaves the screen and its
502 // scale plate only 100px, which is not a picture any more. The
503 // ceiling instead leaves the screen and time band their own fixed
504 // 160px -- room for the scale plate, the picture and a sliver of
505 // letterbox -- and `BENCH_MIN_H` still wins the clamp on anything
506 // shorter than that.
507 Split::Bench => (
508 BENCH_MIN_H,
509 (h - crate::ui::stance::TIME_BAND_H - crate::ui::stance::LEDGER_H - 160.)
510 .max(BENCH_MIN_H),
511 ),
512 // One whole lane under the chrome, the scrollbar strip's row included
513 // while there is one to draw ([`timeline_fixed_h`]): a timeline
514 // shorter than that is a ruler with nothing beneath it. A second
515 // track pays for the line that says the rest are below the fold as
516 // well -- at this height only one row fits, so that line is *always*
517 // drawn there, and it is drawn inside the region
518 // ([`Player::timeline`]). Left out of the floor it comes off the
519 // lane's own pixels, and the one lane the floor promises is a header
520 // cut in half.
521 Split::Timeline => (
522 // `LANE_H` even though the first lane could be a thinner caption
523 // one: a floor is a *minimum*, so the only failure mode of
524 // reading it off the tallest kind is a seam that refuses to go
525 // quite as small as it technically could -- never a lane clipped
526 // short of its own row. corner-cut: exact per-kind floor would
527 // read `session.lanes()[0].kind`, which `split_bounds` is not
528 // handed; ceiling is one drawn-too-tall pixel at the very floor
529 // of a caption-only project, upgrade is threading the real lane
530 // list through here the way [`lanes_h_mixed`] already takes it.
531 timeline_fixed_h(scroll)
532 + LANE_H
533 + match lanes > 1 {
534 true => LABEL_H + 8.,
535 false => 0.,
536 },
537 h * TIMELINE_MAX_SHARE,
538 ),
539 }
540}
541
542pub(crate) fn split_size(
543 split: Split,
544 set: Option<f32>,
545 lanes: usize,
546 window: Size<Pixels>,
547 scroll: bool,
548) -> f32 {
549 let (w, h) = (f32::from(window.width), f32::from(window.height));
550 let (min, max) = split_bounds(split, lanes, window, scroll);
551 let default = match split {
552 Split::Library => library_w(w),
553 Split::Inspector => inspector_w(w),
554 Split::Timeline => timeline_h(lanes, scroll).min(h * TIMELINE_SHARE),
555 Split::Dock => crate::ui::stance::DOCK_W,
556 Split::Bench => crate::ui::stance::BENCH_H,
557 };
558 // The floor wins a window too small to honour both ends: a panel at its
559 // floor is still a panel, and `clamp` panics outright on a ceiling under
560 // its floor.
561 set.unwrap_or(default).clamp(min, max.max(min))
562}
563
564/// Where a divider drag puts the panel it belongs to: the pointer's position
565/// turned into that panel's size. Half a strip is taken off each answer because
566/// the strip is grabbed by its middle -- without it the panel jumps a strip's
567/// width on the press and then trails the pointer for the rest of the gesture.
568pub(crate) fn split_drag_size(split: Split, at: Point<Pixels>, window: Size<Pixels>) -> f32 {
569 let (x, y) = (f32::from(at.x), f32::from(at.y));
570 let (w, h) = (f32::from(window.width), f32::from(window.height));
571 match split {
572 Split::Library => x - SPLIT_W / 2.,
573 Split::Inspector => w - x - SPLIT_W / 2.,
574 // This seam sits above the edit toolbar, which is a fixed height: what
575 // is under the pointer is the toolbar and the timeline together.
576 Split::Timeline => h - y - TOOLBAR_H - SPLIT_W / 2.,
577 // The dock sits on the same right edge the inspector does.
578 Split::Dock => w - x - SPLIT_W / 2.,
579 // The bench sits above the fixed ledger strip, the bench's own
580 // reason the timeline's formula reads the toolbar.
581 Split::Bench => h - y - crate::ui::stance::LEDGER_H - SPLIT_W / 2.,
582 }
583}
584
585impl Player {
586 /// How big the panel on this seam is this frame -- the one door every
587 /// region measures itself through, so a dragged size and a drawn one cannot
588 /// disagree.
589 pub(crate) fn split_px(&self, split: Split, window: Size<Pixels>) -> f32 {
590 // The pair a fresh project starts with where there is no session yet,
591 // which is what the timeline itself draws (`Player::timeline`).
592 let lanes = self
593 .session
594 .as_ref()
595 .map_or(2, |session| session.lanes().len());
596 // Whether the time axis has anywhere to go: the scrollbar strip is
597 // drawn only while it does, and the region's furniture -- and its
598 // floor -- carry the strip's row only while it is. One door
599 // ([`timeline_fixed_h`]) answers the region, the fold and the floor
600 // together, so the three cannot disagree about whether the strip is
601 // there.
602 let view = self.view();
603 let scroll = view.duration > view.span();
604 split_size(split, self.splits.get(split), lanes, window, scroll)
605 }
606}