From 0c26d06073cbf06949da39e8411582e70316782d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 05:18:36 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(app):=20the=20cue=20steps=20?= =?UTF-8?q?over=20the=20bar=20hanging=20off=20the=20picture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A notice, the import line and the seek line hang off the bottom edge of the picture region, and the cue plate sat at a fixed 8 px off that same edge -- so every message was drawn across the line being read, and cost the reader both of them. The plate now sits above whatever those bars measured (`height_probe` -> `sub_bottom`) and comes straight back down the frame they leave: the no-notice position is unchanged to the pixel, which is the position people are used to. A picture cue (PGS) is slid up by the same measurement with cancelling top/bottom insets, so the disc's canvas keeps the height -- and so the fit -- it had with nothing hanging there, rather than being refitted into a shorter box. Measured and not counted: a notice wraps to as many lines as the window is narrow (31 px on one line, 43 on two), and any constant here would be right at exactly one width. The probe asks for one more frame when that height changes, because the window a notice arrives on may be paused and never draw again by itself. --- crates/app/src/layout.rs | 14 ++++++++++++++ crates/app/src/main.rs | 6 ++++++ crates/app/src/render.rs | 11 ++++++++++- crates/app/src/tests/media.rs | 23 +++++++++++++++++++++++ crates/app/src/tests/mod.rs | 2 +- crates/app/src/timeline_math.rs | 21 +++++++++++++++++++++ crates/app/src/ui/preview.rs | 25 +++++++++++++++++++++---- 7 files changed, 96 insertions(+), 6 deletions(-) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index d921b0a..bb044be 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -128,6 +128,20 @@ pub(crate) const SUB_TEXT: f32 = 14.; pub(crate) const SUB_LINE_H: f32 = 18.; /// How far off the bottom of the picture the plate sits. pub(crate) const SUB_BOTTOM: f32 = 8.; +/// The same, once the transient bars that hang off that bottom edge (import, +/// seek, notice) are `bars_h` tall: the cue steps up over them and comes back +/// down the frame they leave, which is what a player does with its OSD -- the +/// alternative, a notice drawn over the line being read, loses both of them. +/// +/// `bars_h` is *measured* ([`height_probe`]) and never counted: a notice wraps +/// to as many lines as the window is narrow, and any constant here would be +/// right at one width. Nothing hanging there means nothing to step over, so the +/// no-notice position is [`SUB_BOTTOM`] exactly, to the pixel. +pub(crate) fn sub_bottom(bars_h: f32) -> f32 { + // A box that was never painted measures zero, and a negative is not a + // height -- either way there is nothing to clear. + SUB_BOTTOM + bars_h.max(0.) +} /// The subtitle strip under the lanes: thin, because it is a picture of where /// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and /// this row has none. diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index afd0d8b..22752b5 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -492,6 +492,11 @@ struct Player { /// -- any key retires it, so does a click on it -- the bar says how many are /// behind it, and answering it brings the next one up. notices: std::collections::VecDeque, + /// How tall the transient bars hanging off the bottom of the picture (the + /// import line, the seek line, the notice) came out at prepaint, so the cue + /// plate can sit clear of them ([`sub_bottom`]). Measured and not counted: + /// a notice wraps to as many lines as the window is narrow. + notice_h: Rc>, /// What the last finished export wrote, so the notice can be the way to it. /// Only the [`EXPORT_DONE`] line reads it -- any later notice has replaced /// that text -- so a click never opens a file the bar is not naming. @@ -594,6 +599,7 @@ fn main() { sub_image: None, held: None, ruler: Rc::default(), + notice_h: Rc::default(), // A second is [`PPS_DEFAULT`] pixels wide until someone // zooms or asks for the fit: a project opens at a scale, not // at whatever its first import happens to be long. diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index f73fd24..6187a76 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -600,7 +600,16 @@ impl Render for Player { .gap(px(2.)) .children(self.import_bar(cx)) .children(self.seek_bar()) - .children(self.notice_bar(cx)), + .children(self.notice_bar(cx)) + // How tall the lot came out, for the + // cue plate above to step over + // ([`sub_bottom`]) -- the bars are + // over the picture, and a message + // drawn across the line being read + // loses both of them. Zero with no + // bar up, since this box is then + // empty. + .child(height_probe(self.notice_h.clone())), ), ) .child(self.transport_bar( diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index 0643730..cb898fc 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -772,6 +772,29 @@ fn a_cue_is_on_screen_from_its_start_until_the_moment_it_ends() { assert!(at(-1.).is_empty()); } +/// The cue plate and the transient bars share the bottom edge of the picture, +/// and the plate is the one that moves: a notice drawn across the line being +/// read costs the reader both of them. +#[test] +fn a_cue_steps_over_whatever_bar_is_hanging_off_the_picture() { + // Nothing hanging there, nothing moved: people know where the line sits, + // and the no-notice position is the one they know, to the pixel. + assert_eq!(sub_bottom(0.), SUB_BOTTOM); + // A bar of any height is a bar the plate is clear of: its bottom edge is + // above the bar's top edge, with the plate's own gap still under it. + for bars in [1., 26., 48., 96., 300.] { + assert!( + sub_bottom(bars) >= bars + SUB_BOTTOM, + "a {bars} px bar reaches the plate" + ); + } + // A taller bar never lowers the plate, and a box that was never painted + // (or measured as nothing) reads as no bar at all rather than as a plate + // pulled off the bottom of the window. + assert!(sub_bottom(48.) > sub_bottom(26.)); + assert_eq!(sub_bottom(-10.), SUB_BOTTOM); +} + /// The two places a subtitle is drawn -- the plate over the picture and the /// strip under the lanes -- inside the 640x360 floor the rest of this window /// is sized for, and the plate readable on whatever the film is showing. diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 268a0aa..18f6d56 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -54,7 +54,7 @@ use super::{ use super::{ SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, - SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, + SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom, carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit, Subs, subtitle_detail, subtitle_notice, subtitle_tail, sub_pick_name, subtitle_rows, subtitle_strip_h, walk_subtitles, diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 467ca0d..05f6796 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -232,6 +232,27 @@ pub(crate) fn bounds_probe(into: Rc>>) -> impl IntoElement { .size_full() } +/// [`bounds_probe`] for a box something *else* is laid out against: it also asks +/// for one more frame whenever the height changed. +/// +/// A measurement is read by the frame after the one that took it, and a notice +/// arriving over a paused picture repaints exactly once -- so without this the +/// cue would sit under that notice until something else happened to draw, which +/// on a paused window can be never. +pub(crate) fn height_probe(into: Rc>) -> impl IntoElement { + canvas( + move |bounds, window, _| { + // Only on a change: an unconditional request is a repaint loop. + if into.replace(bounds.size.height) != bounds.size.height { + window.request_animation_frame(); + } + }, + |_, _, _, _| (), + ) + .absolute() + .size_full() +} + /// Where along an element a click landed, 0..1. An element that was never /// painted has no width, and reads as its start rather than as NaN. pub(crate) fn frac_along(x: Pixels, bounds: Bounds) -> f32 { diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index fa74478..001c870 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -56,6 +56,9 @@ impl Player { // A picture is fitted onto the whole region and a plate hangs off the // bottom of it, and a track is one or the other -- so they are two // shapes and not one with the parts switched off. + // What the transient bars along the bottom edge are taking up right now: + // both shapes step up over it rather than be drawn under it. + let bars = f32::from(self.notice_h.get()); if let Some(image) = picture { // A *flex* box with the canvas as its one growing item: a percentage // size (`size_full`) inside an absolutely placed box has nothing to @@ -63,16 +66,30 @@ impl Player { // flex item is sized by the box itself. Fitted the way the picture // above it is -- `Contain` over the same box -- so a canvas of the // picture's own shape lands exactly on it. - return Some(div().absolute().inset_0().flex().child( - img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain), - )); + // Slid up by the bars' height and not *shrunk* by it: the top and + // bottom insets cancel, so the box keeps the region's height and the + // canvas keeps the fit (and so the scale) it had with nothing + // hanging there -- a shorter box would refit the disc's canvas and + // move every cue on it, not just the one over the bar. The picture + // region clips (`overflow_hidden`), and what leaves the top of a + // subtitle canvas is transparent. + return Some( + div() + .absolute() + .top(px(-bars)) + .bottom(px(bars)) + .left_0() + .right_0() + .flex() + .child(img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain)), + ); } Some( div() .absolute() .left_0() .right_0() - .bottom(px(SUB_BOTTOM)) + .bottom(px(sub_bottom(bars))) .flex() .flex_col() .items_center()