forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBfbc29d1Tahinli2 months ago972 commits

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