The film keeps its shape
Browse files at this commit156db78730e9b538b2c7d06d25876537d3841e30Parent: b333573- fix
- the film keeps its shape
5 changed files +145 -43
- crates/app/src/main.rs +9 -5
- crates/app/src/render.rs +53 -6
- crates/app/src/tests/layout.rs +35 -0
- crates/app/src/ui/preview.rs +47 -32
- crates/app/src/ui/stance.rs +1 -0
crates/app/src/main.rsmodified+9 -5
| @@ -34,6 +34,9 @@ pub(crate) use menus::*; | |||
| 34 | // The tests' door to the escape rule; render.rs calls it by its own name. | 34 | // The tests' door to the escape rule; render.rs calls it by its own name. |
| 35 | #[cfg(test)] | 35 | #[cfg(test)] |
| 36 | pub(crate) use render::escape_leaves_player_fullscreen; | 36 | pub(crate) use render::escape_leaves_player_fullscreen; |
| 37 | +// The Contain letterbox, shared with the subtitle picture overlay | ||
| 38 | +// (ui/preview.rs) so both draw the same fitted rect the same way. | ||
| 39 | +pub(crate) use render::letterboxed_image; | ||
| 37 | pub(crate) use notices::*; | 40 | pub(crate) use notices::*; |
| 38 | pub(crate) use oracle::*; | 41 | pub(crate) use oracle::*; |
| 39 | pub(crate) use subs::*; | 42 | pub(crate) use subs::*; |
| @@ -67,11 +70,12 @@ use engine::tonemap::Preset; | |||
| 67 | use engine::transform::TransformParams; | 70 | use engine::transform::TransformParams; |
| 68 | use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; | 71 | use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; |
| 69 | use gpui::{ | 72 | use gpui::{ |
| 70 | - AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, | 73 | + AnyElement, App, Application, Bounds, ClickEvent, Context, Corners, CursorStyle, Div, |
| 71 | - FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, | 74 | + DragMoveEvent, FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, |
| 72 | - PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollHandle, ScrollWheelEvent, | 75 | + MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, |
| 73 | - SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, | 76 | + ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions, |
| 74 | - canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size, | 77 | + Window, WindowBounds, WindowOptions, canvas, div, point, prelude::*, px, relative, rgb, rgba, |
| 78 | + size, | ||
| 75 | }; | 79 | }; |
| 76 | 80 | ||
| 77 | struct Player { | 81 | struct Player { |
crates/app/src/render.rsmodified+53 -6
| @@ -13,6 +13,58 @@ pub(crate) fn escape_leaves_player_fullscreen(key: &str, ctrl: bool, player_full | |||
| 13 | key == ESCAPE && !ctrl && player_fullscreen | 13 | key == ESCAPE && !ctrl && player_fullscreen |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | +/// The frame `image`, letterboxed/pillarboxed into whatever box it is given, | ||
| 17 | +/// filling that box on its own axis and leaving the other bare -- the bare | ||
| 18 | +/// strip is the box's own background (`BG_CANVAS`), never painted here, which | ||
| 19 | +/// is why every caller sits this on a div already carrying that colour. | ||
| 20 | +/// | ||
| 21 | +/// `Img::object_fit(Contain)` reads right (verified by hand against | ||
| 22 | +/// `ObjectFit::Contain::get_bounds`) but only when taffy has already given the | ||
| 23 | +/// element a real size to fit *into* -- and for a plain `img()` with both axes | ||
| 24 | +/// `Auto` (`size_full()`/`max_w_full().max_h_full()` both resolve that way in | ||
| 25 | +/// this pin), it resolves to the image's own native size first and object-fit | ||
| 26 | +/// never gets a box smaller than the frame to shrink into, so the frame reads | ||
| 27 | +/// through un-fitted. A `canvas()` element carries no such precompute -- its | ||
| 28 | +/// `request_layout` is a plain `Style` read, so it is sized by its parent | ||
| 29 | +/// exactly as a `div()` would be -- and its `paint` callback is handed the | ||
| 30 | +/// real resolved `bounds`, which is all `Contain::get_bounds` needs. | ||
| 31 | +/// | ||
| 32 | +/// `.absolute()` with all four insets zero, not `.size_full()` in flex flow: | ||
| 33 | +/// a flex item under `justify_center()`/`items_center()` (see `picture_area` | ||
| 34 | +/// below) never resolves a percentage cross-axis size for a plain-`Style` | ||
| 35 | +/// element like `canvas()`, which is a taffy circularity and not this | ||
| 36 | +/// element's own bug (confirmed live: bounds handed to `paint` came back | ||
| 37 | +/// `944px x 0px`, main axis right, cross axis collapsed). An absolutely | ||
| 38 | +/// positioned box is sized against its containing block directly instead -- | ||
| 39 | +/// the nearest `.relative()` ancestor, which every caller here already sits | ||
| 40 | +/// this on -- so it never asks taffy's flex algorithm for a cross-axis size | ||
| 41 | +/// at all. | ||
| 42 | +/// | ||
| 43 | +/// That containing block still has to have a real size of its own, though: | ||
| 44 | +/// gpui's default `display` is `Block` (`Style::default()`), not `Flex`, and | ||
| 45 | +/// a `Block` box with height `auto` is sized by its *normal-flow* children -- | ||
| 46 | +/// an `.absolute()` one, this, takes no part in that (confirmed live: with | ||
| 47 | +/// the box lacking its own `.flex()`, this canvas's own bounds came back | ||
| 48 | +/// `944px x 0px` even though its containing block, measured independently, | ||
| 49 | +/// was a real `944px x 335px`). Every `.relative()` ancestor this sits on | ||
| 50 | +/// must also be `.flex()` (see `ui::stance::screen`'s `stance-picture`) for | ||
| 51 | +/// exactly this reason. | ||
| 52 | +pub(crate) fn letterboxed_image(image: Arc<RenderImage>) -> impl IntoElement + Styled { | ||
| 53 | + canvas( | ||
| 54 | + |_, _, _| (), | ||
| 55 | + move |bounds, _, window, _| { | ||
| 56 | + let fitted = gpui::ObjectFit::Contain.get_bounds(bounds, image.size(0)); | ||
| 57 | + let _ = window.paint_image(fitted, Corners::default(), image, 0, false); | ||
| 58 | + }, | ||
| 59 | + ) | ||
| 60 | + .absolute() | ||
| 61 | + .top_0() | ||
| 62 | + .bottom_0() | ||
| 63 | + .left_0() | ||
| 64 | + .right_0() | ||
| 65 | + .size_full() | ||
| 66 | +} | ||
| 67 | + | ||
| 16 | impl Player { | 68 | impl Player { |
| 17 | /// The picture region alone: the image, the subtitle cue plate, the | 69 | /// The picture region alone: the image, the subtitle cue plate, the |
| 18 | /// preview badge and the three transient bars over its bottom edge. | 70 | /// preview badge and the three transient bars over its bottom edge. |
| @@ -41,12 +93,7 @@ impl Player { | |||
| 41 | .children( | 93 | .children( |
| 42 | self.image | 94 | self.image |
| 43 | .clone() | 95 | .clone() |
| 44 | - .map(|i| { | 96 | + .map(|i| letterboxed_image(i).into_any_element()) |
| 45 | - img(i) | ||
| 46 | - .size_full() | ||
| 47 | - .object_fit(gpui::ObjectFit::Contain) | ||
| 48 | - .into_any_element() | ||
| 49 | - }) | ||
| 50 | // With no file open the letterbox is the whole region, | 97 | // With no file open the letterbox is the whole region, |
| 51 | // and a black rectangle says only that something is | 98 | // and a black rectangle says only that something is |
| 52 | // broken -- so it says what it wants instead. The window | 99 | // broken -- so it says what it wants instead. The window |
crates/app/src/tests/layout.rsmodified+35 -0
| @@ -1802,3 +1802,38 @@ fn the_stance_renders_its_six_regions_in_the_documented_order() { | |||
| 1802 | "EDITH_DARKROOM never reaches ui::stance::render" | 1802 | "EDITH_DARKROOM never reaches ui::stance::render" |
| 1803 | ); | 1803 | ); |
| 1804 | } | 1804 | } |
| 1805 | + | ||
| 1806 | +/// The picture is letterboxed, never stretched: both the picture region and | ||
| 1807 | +/// the subtitle picture overlay paint through [`letterboxed_image`] (the | ||
| 1808 | +/// `canvas()` element that hands `ObjectFit::Contain::get_bounds` a real | ||
| 1809 | +/// resolved size) rather than a plain `img().object_fit(...)`, which reads | ||
| 1810 | +/// right by hand but never gets a fitted box from taffy in this pin -- see | ||
| 1811 | +/// `render.rs`'s own doc comment on the function for the measured dead end. | ||
| 1812 | +/// A regression back to `img(...).object_fit(` in either caller is the | ||
| 1813 | +/// stretch-to-fill bug returning silently. | ||
| 1814 | +#[test] | ||
| 1815 | +fn the_picture_letterboxes_through_a_canvas_never_a_plain_img_object_fit() { | ||
| 1816 | + let render_rs = src_text("render.rs"); | ||
| 1817 | + assert!( | ||
| 1818 | + render_rs.contains("pub(crate) fn letterboxed_image"), | ||
| 1819 | + "the letterbox helper moved or was renamed" | ||
| 1820 | + ); | ||
| 1821 | + assert!( | ||
| 1822 | + render_rs.contains("ObjectFit::Contain.get_bounds(bounds, image.size(0))"), | ||
| 1823 | + "letterboxed_image no longer computes the Contain rect by hand" | ||
| 1824 | + ); | ||
| 1825 | + for (file, needle) in [ | ||
| 1826 | + ("render.rs", "letterboxed_image(i)"), | ||
| 1827 | + ("ui/preview.rs", "letterboxed_image(image)"), | ||
| 1828 | + ] { | ||
| 1829 | + let text = src_text(file); | ||
| 1830 | + assert!( | ||
| 1831 | + text.contains(needle), | ||
| 1832 | + "{file} no longer paints through letterboxed_image" | ||
| 1833 | + ); | ||
| 1834 | + assert!( | ||
| 1835 | + !text.contains(".object_fit(gpui::ObjectFit::Contain)"), | ||
| 1836 | + "{file} reintroduced the stretched img().object_fit(Contain) dead end" | ||
| 1837 | + ); | ||
| 1838 | + } | ||
| 1839 | +} | ||
crates/app/src/ui/preview.rsmodified+47 -32
| @@ -225,7 +225,7 @@ impl Player { | |||
| 225 | .left_0() | 225 | .left_0() |
| 226 | .right_0() | 226 | .right_0() |
| 227 | .flex() | 227 | .flex() |
| 228 | - .child(img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain)), | 228 | + .child(letterboxed_image(image)), |
| 229 | ); | 229 | ); |
| 230 | } | 230 | } |
| 231 | Some( | 231 | Some( |
| @@ -332,41 +332,55 @@ impl Player { | |||
| 332 | /// neighbour's edge frame ([`engine::PlaybackSession::video_source_frame_at`] | 332 | /// neighbour's edge frame ([`engine::PlaybackSession::video_source_frame_at`] |
| 333 | /// is the same lookup [`Player::live_decode`] already makes) in place of | 333 | /// is the same lookup [`Player::live_decode`] already makes) in place of |
| 334 | /// the plate's text. | 334 | /// the plate's text. |
| 335 | + /// | ||
| 336 | + /// Always the same fixed-height markup while the darkroom is up, at rest | ||
| 337 | + /// on a cut or not -- `.invisible()` (`Visibility::Hidden`, confirmed in | ||
| 338 | + /// `gpui_macros::styles::visibility_style_methods`: painting is skipped, | ||
| 339 | + /// the layout box is not) keeps the strip's room reserved instead of | ||
| 340 | + /// collapsing it, which is what let the picture's own `flex_1` above it | ||
| 341 | + /// resize on every cut walk (404px resting on a cut, 335px a frame off | ||
| 342 | + /// one, springing back on the very next). Only `!self.darkroom` still | ||
| 343 | + /// returns `None`: the legacy tree never reserved this room and does not | ||
| 344 | + /// start now. | ||
| 335 | pub(crate) fn two_up(&self) -> Option<impl IntoElement> { | 345 | pub(crate) fn two_up(&self) -> Option<impl IntoElement> { |
| 336 | if !self.darkroom { | 346 | if !self.darkroom { |
| 337 | return None; | 347 | return None; |
| 338 | } | 348 | } |
| 339 | - let (lane, idx) = self.selected.anchor()?; | 349 | + let resting = (|| { |
| 340 | - let session = self.session.as_ref()?; | 350 | + let (lane, idx) = self.selected.anchor()?; |
| 341 | - let clips = session.lane_clips(lane); | 351 | + let session = self.session.as_ref()?; |
| 342 | - let clip = clips.get(idx)?; | 352 | + let clips = session.lane_clips(lane); |
| 343 | - let now = frame_at(session.now(), self.fps); | 353 | + let clip = clips.get(idx)?; |
| 344 | - let name_of = |source: usize| { | 354 | + let now = frame_at(session.now(), self.fps); |
| 345 | - session | 355 | + let name_of = |source: usize| { |
| 346 | - .sources() | 356 | + session |
| 347 | - .get(source) | 357 | + .sources() |
| 348 | - .map_or_else(|| "?".to_string(), |s| file_name(&s.path)) | 358 | + .get(source) |
| 349 | - }; | 359 | + .map_or_else(|| "?".to_string(), |s| file_name(&s.path)) |
| 350 | - // Which edge, if either, the playhead is resting on -- the one | 360 | + }; |
| 351 | - // question "at rest on a cut" is. | 361 | + // Which edge, if either, the playhead is resting on -- the one |
| 352 | - let (out_label, in_label) = if now == clip.start { | 362 | + // question "at rest on a cut" is. |
| 353 | - let out = idx | 363 | + if now == clip.start { |
| 354 | - .checked_sub(1) | 364 | + let out = idx |
| 355 | - .and_then(|i| clips.get(i)) | 365 | + .checked_sub(1) |
| 356 | - .map_or("— nothing before it".to_string(), |c| { | 366 | + .and_then(|i| clips.get(i)) |
| 357 | - format!("{} @{}", name_of(c.source), c.end()) | 367 | + .map_or("— nothing before it".to_string(), |c| { |
| 358 | - }); | 368 | + format!("{} @{}", name_of(c.source), c.end()) |
| 359 | - (out, format!("{} @{}", name_of(clip.source), clip.start)) | 369 | + }); |
| 360 | - } else if now == clip.end() { | 370 | + Some((out, format!("{} @{}", name_of(clip.source), clip.start))) |
| 361 | - let inn = clips | 371 | + } else if now == clip.end() { |
| 362 | - .get(idx + 1) | 372 | + let inn = clips |
| 363 | - .map_or("— nothing after it".to_string(), |c| { | 373 | + .get(idx + 1) |
| 364 | - format!("{} @{}", name_of(c.source), c.start) | 374 | + .map_or("— nothing after it".to_string(), |c| { |
| 365 | - }); | 375 | + format!("{} @{}", name_of(c.source), c.start) |
| 366 | - (format!("{} @{}", name_of(clip.source), clip.end()), inn) | 376 | + }); |
| 367 | - } else { | 377 | + Some((format!("{} @{}", name_of(clip.source), clip.end()), inn)) |
| 368 | - return None; | 378 | + } else { |
| 369 | - }; | 379 | + None |
| 380 | + } | ||
| 381 | + })(); | ||
| 382 | + let on_cut = resting.is_some(); | ||
| 383 | + let (out_label, in_label) = resting.unwrap_or_default(); | ||
| 370 | let plate = |label: &str, text: String| { | 384 | let plate = |label: &str, text: String| { |
| 371 | div() | 385 | div() |
| 372 | .flex_1() | 386 | .flex_1() |
| @@ -400,6 +414,7 @@ impl Player { | |||
| 400 | .flex() | 414 | .flex() |
| 401 | .gap(px(1.)) | 415 | .gap(px(1.)) |
| 402 | .p(px(8.)) | 416 | .p(px(8.)) |
| 417 | + .when(!on_cut, |d| d.invisible()) | ||
| 403 | .child(plate("OUT", out_label)) | 418 | .child(plate("OUT", out_label)) |
| 404 | .child(plate("IN", in_label)), | 419 | .child(plate("IN", in_label)), |
| 405 | ) | 420 | ) |
crates/app/src/ui/stance.rsmodified+1 -0
| @@ -214,6 +214,7 @@ fn screen(player: &mut Player, position: f64, window: &mut Window, cx: &mut Cont | |||
| 214 | .id("stance-picture") | 214 | .id("stance-picture") |
| 215 | .flex_1() | 215 | .flex_1() |
| 216 | .min_h(px(0.)) | 216 | .min_h(px(0.)) |
| 217 | + .flex() | ||
| 217 | .relative() | 218 | .relative() |
| 218 | .child(player.picture_area(position, window, cx)), | 219 | .child(player.picture_area(position, window, cx)), |
| 219 | ) | 220 | ) |