forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB0563cbfTahinli2 months ago824 commits

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