forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

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