forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBf2bee6bTahinli2 months ago781 commits

render.rs230 lines, 11.6 KiBHistoryRawDownload
1//! What the window looks like this frame: the one `render` the whole
2//! interface hangs off, root to overlays.
3
4use crate::*;
5
6/// The frame `image`, letterboxed/pillarboxed into whatever box it is given,
7/// filling that box on its own axis and leaving the other bare -- the bare
8/// strip is the box's own background (`BG_CANVAS`), never painted here, which
9/// is why every caller sits this on a div already carrying that colour.
10///
11/// `Img::object_fit(Contain)` reads right (verified by hand against
12/// `ObjectFit::Contain::get_bounds`) but only when taffy has already given the
13/// element a real size to fit *into* -- and for a plain `img()` with both axes
14/// `Auto` (`size_full()`/`max_w_full().max_h_full()` both resolve that way in
15/// this pin), it resolves to the image's own native size first and object-fit
16/// never gets a box smaller than the frame to shrink into, so the frame reads
17/// through un-fitted. A `canvas()` element carries no such precompute -- its
18/// `request_layout` is a plain `Style` read, so it is sized by its parent
19/// exactly as a `div()` would be -- and its `paint` callback is handed the
20/// real resolved `bounds`, which is all `Contain::get_bounds` needs.
21///
22/// `.absolute()` with all four insets zero, not `.size_full()` in flex flow:
23/// a flex item under `justify_center()`/`items_center()` (see `picture_area`
24/// below) never resolves a percentage cross-axis size for a plain-`Style`
25/// element like `canvas()`, which is a taffy circularity and not this
26/// element's own bug (confirmed live: bounds handed to `paint` came back
27/// `944px x 0px`, main axis right, cross axis collapsed). An absolutely
28/// positioned box is sized against its containing block directly instead --
29/// the nearest `.relative()` ancestor, which every caller here already sits
30/// this on -- so it never asks taffy's flex algorithm for a cross-axis size
31/// at all.
32///
33/// That containing block still has to have a real size of its own, though:
34/// gpui's default `display` is `Block` (`Style::default()`), not `Flex`, and
35/// a `Block` box with height `auto` is sized by its *normal-flow* children --
36/// an `.absolute()` one, this, takes no part in that (confirmed live: with
37/// the box lacking its own `.flex()`, this canvas's own bounds came back
38/// `944px x 0px` even though its containing block, measured independently,
39/// was a real `944px x 335px`). Every `.relative()` ancestor this sits on
40/// must also be `.flex()` (see `ui::stance::screen`'s `stance-picture`) for
41/// exactly this reason.
42pub(crate) fn letterboxed_image(image: Arc<RenderImage>) -> impl IntoElement + Styled {
43 canvas(
44 |_, _, _| (),
45 move |bounds, _, window, _| {
46 let fitted = gpui::ObjectFit::Contain.get_bounds(bounds, image.size(0));
47 let _ = window.paint_image(fitted, Corners::default(), image, 0, false);
48 },
49 )
50 .absolute()
51 .top_0()
52 .bottom_0()
53 .left_0()
54 .right_0()
55 .size_full()
56}
57
58impl Player {
59 /// The picture region alone: the image, the subtitle cue plate, the
60 /// preview badge and the three transient bars over its bottom edge.
61 /// Its own method so player fullscreen ([`Player::act`]) can stand it up
62 /// as the window's only child without a second copy of what it draws --
63 /// and so the darkroom's own screen region (DESIGN.md §5,
64 /// `ui::stance::screen`) draws the same picture rather than a second one.
65 pub(crate) fn picture_area(
66 &mut self,
67 position: f64,
68 window: &mut Window,
69 cx: &mut Context<Self>,
70 ) -> impl IntoElement {
71 div()
72 .flex_1()
73 .min_h(px(0.))
74 .overflow_hidden()
75 // The bed the cue plate is placed against: it hangs off the
76 // bottom of the picture region, which is the one box that is the
77 // picture and nothing else.
78 .relative()
79 .flex()
80 .justify_center()
81 .items_center()
82 .bg(rgb(BG_CANVAS()))
83 .children(
84 self.image
85 .clone()
86 .map(|i| letterboxed_image(i).into_any_element())
87 // With no file open the letterbox is the whole region,
88 // and a black rectangle says only that something is
89 // broken -- so it says what it wants instead. The window
90 // is already the drop target.
91 .or_else(|| {
92 (self.active_session().is_none()).then(|| empty_hint().into_any_element())
93 }),
94 )
95 // After the picture, so the plate is drawn over it rather than
96 // under.
97 .children(self.subtitle_overlay(position, window))
98 // The three transient lines hang off the bottom of the picture
99 // rather than taking a row of the column: a notice that arrives
100 // must not push the transport, the toolbar and the timeline down
101 // by its own height -- which is a control moving with state, on
102 // every control below it at once.
103 .child(
104 div()
105 .absolute()
106 .bottom_0()
107 .left_0()
108 .right_0()
109 .flex()
110 .flex_col()
111 .gap(px(2.))
112 .children(self.import_bar(cx))
113 .children(self.seek_bar())
114 // How tall the lot came out, for the cue plate above to
115 // step over ([`sub_bottom`]) -- the bars are over the
116 // picture, and a message drawn across the line being
117 // read loses both of them. Zero with no bar up, since
118 // this box is then empty.
119 .child(height_probe(self.notice_h.clone())),
120 )
121 // The preview's scrub bar, drawn LAST: the notice box above shares
122 // its bottom edge, and a bar under the "PREVIEWING ..." plate was
123 // invisible for exactly the moment it matters.
124 .children(self.preview_scrub_bar(cx))
125 }
126}
127
128impl Render for Player {
129 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
130 // A file that has just been opened sits on its first frame with the
131 // clock stopped: opening is not playing, whichever way the file
132 // arrived. The play binding and the transport button start it.
133 if let Some(session) = self.active_session_mut() {
134 session.tick();
135 }
136 self.pump(window);
137 // What every hover label asks before it paints: a card or a menu is
138 // drawn over whatever the pointer is resting on.
139 OVERLAID.store(self.overlaid(), Ordering::Relaxed);
140 // A cleared seek is a frame delivered, which is the one readiness signal
141 // there is: whatever a slider drag held back is written here.
142 if self.seek_since.is_none() {
143 self.flush_drag(cx);
144 }
145 self.poll_export();
146 self.poll_import(cx);
147 self.poll_silence();
148 self.poll_proxies(cx);
149 // Every way a source can arrive -- argv, an import, a project load --
150 // has been through a repaint by the time its clips are drawn, so this
151 // is the one place that has to notice a new one.
152 self.cache_media(cx);
153 self.cache_export_seat(cx);
154 self.cache_hw_caps(cx);
155 // What the compositor calls this window. Pushed only when it changes:
156 // it is a protocol round trip and this runs at vsync.
157 let title = window_title(&self.name);
158 if title != self.titled {
159 window.set_window_title(&title);
160 self.titled = title;
161 }
162 // A compositor keybind (the window manager's own fullscreen, not
163 // ours) can drop `window.is_fullscreen()` without ever going through
164 // [`Player::act`] -- the picture-only layout below must not survive
165 // that on its own, or the chrome never comes back. Only the *leaving*
166 // direction is reconciled here: the platform going fullscreen behind
167 // our back is not this editor asking for the picture-only layout, so
168 // it is left alone rather than guessed at.
169 if self.player_fullscreen && !window.is_fullscreen() {
170 self.player_fullscreen = false;
171 }
172 // No shadow flag: the session is the only truth about play state, and
173 // [`Player::transport`] is the one place it is read.
174 let state = self.transport();
175 // A paused timeline has nothing to animate; the toggle handlers notify,
176 // which is what starts the loop again. A paused seek keeps the loop
177 // running by itself until `pump` has the frame it asked for. An export
178 // pauses playback and still needs the loop: its progress only reaches
179 // the screen on a repaint. A notice does not: it waits to be dismissed
180 // rather than for a clock, so keeping the loop alive for it would spin
181 // the GPU until someone answered it.
182 // An import does too, and for the same reason: its clock and its sweep
183 // only reach the screen on a repaint, and a still line is the very
184 // thing it exists to disprove.
185 if state.is_playing()
186 || self.seek_since.is_some()
187 || self.export.is_some()
188 || self.importing.is_some()
189 // A silence scan too: its progress and its two clocks only reach
190 // the screen on a repaint, and a still line is the very thing this
191 // card was rewritten to disprove.
192 || self.silence_scan.is_some()
193 // ...and a stand-in being made: its percentage on the library row
194 // only reaches the screen on a repaint, and a bar that never moves
195 // is exactly what a person reads as a hung encode.
196 || self.making_proxies()
197 {
198 window.request_animation_frame();
199 }
200
201 // Read per render, never cached: a delete shortens the timeline and the
202 // timecode, the ruler and the clamp below all have to follow it -- and
203 // so does the room a tail being dragged needs to grow into.
204 let duration = self.drawn_duration();
205 let position = self.playhead(duration);
206 // Re-settled every frame against the duration this one is drawing: an
207 // edit that shortens the timeline moves the far end of the view, and a
208 // playhead that has run off the bed pulls the view after it -- which is
209 // what makes a zoomed-in timeline scroll while it plays.
210 // ...but only a playhead that is *going* somewhere pulls it: following
211 // is what a moving one does, during playback and through a seek. A view
212 // yanked back to a playhead nobody moved is a hand's own scroll undone
213 // by the very next frame, which is what made the wheel look dead.
214 // ...and a hand that scrolled the view away from the head keeps it
215 // ([`Player::panned`]): a follow that centres the head again would undo
216 // the notch before it was seen, which is what made the wheel look dead
217 // while playing. It is given straight back below, the moment the head
218 // is on the bed a person chose to look at -- so the scroll wins now and
219 // the follow resumes by itself, with nothing to press.
220 self.scale = match (state.is_playing() || self.seek_since.is_some()) && !self.panned {
221 true => self.view().following(position),
222 false => self.view().settled(),
223 };
224 if self.panned && self.view().shows(position) {
225 self.panned = false;
226 }
227
228 ui::stance::render(self, window, cx)
229 }
230}