diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index f2eadc2..ca95803 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -34,6 +34,9 @@ pub(crate) use menus::*; // The tests' door to the escape rule; render.rs calls it by its own name. #[cfg(test)] pub(crate) use render::escape_leaves_player_fullscreen; +// The Contain letterbox, shared with the subtitle picture overlay +// (ui/preview.rs) so both draw the same fitted rect the same way. +pub(crate) use render::letterboxed_image; pub(crate) use notices::*; pub(crate) use oracle::*; pub(crate) use subs::*; @@ -67,11 +70,12 @@ use engine::tonemap::Preset; use engine::transform::TransformParams; use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; use gpui::{ - AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, - FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, - PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollHandle, ScrollWheelEvent, - SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, - canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size, + AnyElement, App, Application, Bounds, ClickEvent, Context, Corners, CursorStyle, Div, + DragMoveEvent, FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent, + MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta, + ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions, + Window, WindowBounds, WindowOptions, canvas, div, point, prelude::*, px, relative, rgb, rgba, + size, }; struct Player { diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index c3cea8d..5935a12 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -13,6 +13,58 @@ pub(crate) fn escape_leaves_player_fullscreen(key: &str, ctrl: bool, player_full key == ESCAPE && !ctrl && player_fullscreen } +/// The frame `image`, letterboxed/pillarboxed into whatever box it is given, +/// filling that box on its own axis and leaving the other bare -- the bare +/// strip is the box's own background (`BG_CANVAS`), never painted here, which +/// is why every caller sits this on a div already carrying that colour. +/// +/// `Img::object_fit(Contain)` reads right (verified by hand against +/// `ObjectFit::Contain::get_bounds`) but only when taffy has already given the +/// element a real size to fit *into* -- and for a plain `img()` with both axes +/// `Auto` (`size_full()`/`max_w_full().max_h_full()` both resolve that way in +/// this pin), it resolves to the image's own native size first and object-fit +/// never gets a box smaller than the frame to shrink into, so the frame reads +/// through un-fitted. A `canvas()` element carries no such precompute -- its +/// `request_layout` is a plain `Style` read, so it is sized by its parent +/// exactly as a `div()` would be -- and its `paint` callback is handed the +/// real resolved `bounds`, which is all `Contain::get_bounds` needs. +/// +/// `.absolute()` with all four insets zero, not `.size_full()` in flex flow: +/// a flex item under `justify_center()`/`items_center()` (see `picture_area` +/// below) never resolves a percentage cross-axis size for a plain-`Style` +/// element like `canvas()`, which is a taffy circularity and not this +/// element's own bug (confirmed live: bounds handed to `paint` came back +/// `944px x 0px`, main axis right, cross axis collapsed). An absolutely +/// positioned box is sized against its containing block directly instead -- +/// the nearest `.relative()` ancestor, which every caller here already sits +/// this on -- so it never asks taffy's flex algorithm for a cross-axis size +/// at all. +/// +/// That containing block still has to have a real size of its own, though: +/// gpui's default `display` is `Block` (`Style::default()`), not `Flex`, and +/// a `Block` box with height `auto` is sized by its *normal-flow* children -- +/// an `.absolute()` one, this, takes no part in that (confirmed live: with +/// the box lacking its own `.flex()`, this canvas's own bounds came back +/// `944px x 0px` even though its containing block, measured independently, +/// was a real `944px x 335px`). Every `.relative()` ancestor this sits on +/// must also be `.flex()` (see `ui::stance::screen`'s `stance-picture`) for +/// exactly this reason. +pub(crate) fn letterboxed_image(image: Arc) -> impl IntoElement + Styled { + canvas( + |_, _, _| (), + move |bounds, _, window, _| { + let fitted = gpui::ObjectFit::Contain.get_bounds(bounds, image.size(0)); + let _ = window.paint_image(fitted, Corners::default(), image, 0, false); + }, + ) + .absolute() + .top_0() + .bottom_0() + .left_0() + .right_0() + .size_full() +} + impl Player { /// The picture region alone: the image, the subtitle cue plate, the /// preview badge and the three transient bars over its bottom edge. @@ -41,12 +93,7 @@ impl Player { .children( self.image .clone() - .map(|i| { - img(i) - .size_full() - .object_fit(gpui::ObjectFit::Contain) - .into_any_element() - }) + .map(|i| letterboxed_image(i).into_any_element()) // With no file open the letterbox is the whole region, // and a black rectangle says only that something is // broken -- so it says what it wants instead. The window diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index fc1816a..d86904c 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1802,3 +1802,38 @@ fn the_stance_renders_its_six_regions_in_the_documented_order() { "EDITH_DARKROOM never reaches ui::stance::render" ); } + +/// The picture is letterboxed, never stretched: both the picture region and +/// the subtitle picture overlay paint through [`letterboxed_image`] (the +/// `canvas()` element that hands `ObjectFit::Contain::get_bounds` a real +/// resolved size) rather than a plain `img().object_fit(...)`, which reads +/// right by hand but never gets a fitted box from taffy in this pin -- see +/// `render.rs`'s own doc comment on the function for the measured dead end. +/// A regression back to `img(...).object_fit(` in either caller is the +/// stretch-to-fill bug returning silently. +#[test] +fn the_picture_letterboxes_through_a_canvas_never_a_plain_img_object_fit() { + let render_rs = src_text("render.rs"); + assert!( + render_rs.contains("pub(crate) fn letterboxed_image"), + "the letterbox helper moved or was renamed" + ); + assert!( + render_rs.contains("ObjectFit::Contain.get_bounds(bounds, image.size(0))"), + "letterboxed_image no longer computes the Contain rect by hand" + ); + for (file, needle) in [ + ("render.rs", "letterboxed_image(i)"), + ("ui/preview.rs", "letterboxed_image(image)"), + ] { + let text = src_text(file); + assert!( + text.contains(needle), + "{file} no longer paints through letterboxed_image" + ); + assert!( + !text.contains(".object_fit(gpui::ObjectFit::Contain)"), + "{file} reintroduced the stretched img().object_fit(Contain) dead end" + ); + } +} diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index 36bc8e4..78ee9e9 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -225,7 +225,7 @@ impl Player { .left_0() .right_0() .flex() - .child(img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain)), + .child(letterboxed_image(image)), ); } Some( @@ -332,41 +332,55 @@ impl Player { /// neighbour's edge frame ([`engine::PlaybackSession::video_source_frame_at`] /// is the same lookup [`Player::live_decode`] already makes) in place of /// the plate's text. + /// + /// Always the same fixed-height markup while the darkroom is up, at rest + /// on a cut or not -- `.invisible()` (`Visibility::Hidden`, confirmed in + /// `gpui_macros::styles::visibility_style_methods`: painting is skipped, + /// the layout box is not) keeps the strip's room reserved instead of + /// collapsing it, which is what let the picture's own `flex_1` above it + /// resize on every cut walk (404px resting on a cut, 335px a frame off + /// one, springing back on the very next). Only `!self.darkroom` still + /// returns `None`: the legacy tree never reserved this room and does not + /// start now. pub(crate) fn two_up(&self) -> Option { if !self.darkroom { return None; } - let (lane, idx) = self.selected.anchor()?; - let session = self.session.as_ref()?; - let clips = session.lane_clips(lane); - let clip = clips.get(idx)?; - let now = frame_at(session.now(), self.fps); - let name_of = |source: usize| { - session - .sources() - .get(source) - .map_or_else(|| "?".to_string(), |s| file_name(&s.path)) - }; - // Which edge, if either, the playhead is resting on -- the one - // question "at rest on a cut" is. - let (out_label, in_label) = if now == clip.start { - let out = idx - .checked_sub(1) - .and_then(|i| clips.get(i)) - .map_or("— nothing before it".to_string(), |c| { - format!("{} @{}", name_of(c.source), c.end()) - }); - (out, format!("{} @{}", name_of(clip.source), clip.start)) - } else if now == clip.end() { - let inn = clips - .get(idx + 1) - .map_or("— nothing after it".to_string(), |c| { - format!("{} @{}", name_of(c.source), c.start) - }); - (format!("{} @{}", name_of(clip.source), clip.end()), inn) - } else { - return None; - }; + let resting = (|| { + let (lane, idx) = self.selected.anchor()?; + let session = self.session.as_ref()?; + let clips = session.lane_clips(lane); + let clip = clips.get(idx)?; + let now = frame_at(session.now(), self.fps); + let name_of = |source: usize| { + session + .sources() + .get(source) + .map_or_else(|| "?".to_string(), |s| file_name(&s.path)) + }; + // Which edge, if either, the playhead is resting on -- the one + // question "at rest on a cut" is. + if now == clip.start { + let out = idx + .checked_sub(1) + .and_then(|i| clips.get(i)) + .map_or("— nothing before it".to_string(), |c| { + format!("{} @{}", name_of(c.source), c.end()) + }); + Some((out, format!("{} @{}", name_of(clip.source), clip.start))) + } else if now == clip.end() { + let inn = clips + .get(idx + 1) + .map_or("— nothing after it".to_string(), |c| { + format!("{} @{}", name_of(c.source), c.start) + }); + Some((format!("{} @{}", name_of(clip.source), clip.end()), inn)) + } else { + None + } + })(); + let on_cut = resting.is_some(); + let (out_label, in_label) = resting.unwrap_or_default(); let plate = |label: &str, text: String| { div() .flex_1() @@ -400,6 +414,7 @@ impl Player { .flex() .gap(px(1.)) .p(px(8.)) + .when(!on_cut, |d| d.invisible()) .child(plate("OUT", out_label)) .child(plate("IN", in_label)), ) diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index b89eee1..89a1846 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -214,6 +214,7 @@ fn screen(player: &mut Player, position: f64, window: &mut Window, cx: &mut Cont .id("stance-picture") .flex_1() .min_h(px(0.)) + .flex() .relative() .child(player.picture_area(position, window, cx)), )