forge
Explore
Log in

Don't you dare go Hollow

The cue steps over the bar hanging off the picture

Browse files at this commit

0c26d06073cbf06949da39e8411582e70316782dAhmet Kaan GümüşParent: db032d5
  • fix
    • the cue steps over the bar hanging off the picture
Show full message
🐛 fix(app): the cue steps over the bar hanging off the picture

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.rsmodified+14 -0
@@ -128,6 +128,20 @@ pub(crate) const SUB_TEXT: f32 = 14.;
128128 pub(crate) const SUB_LINE_H: f32 = 18.;
129129 /// How far off the bottom of the picture the plate sits.
130130 pub(crate) const SUB_BOTTOM: f32 = 8.;
131+/// The same, once the transient bars that hang off that bottom edge (import,
132+/// seek, notice) are `bars_h` tall: the cue steps up over them and comes back
133+/// down the frame they leave, which is what a player does with its OSD -- the
134+/// alternative, a notice drawn over the line being read, loses both of them.
135+///
136+/// `bars_h` is *measured* ([`height_probe`]) and never counted: a notice wraps
137+/// to as many lines as the window is narrow, and any constant here would be
138+/// right at one width. Nothing hanging there means nothing to step over, so the
139+/// no-notice position is [`SUB_BOTTOM`] exactly, to the pixel.
140+pub(crate) fn sub_bottom(bars_h: f32) -> f32 {
141+ // A box that was never painted measures zero, and a negative is not a
142+ // height -- either way there is nothing to clear.
143+ SUB_BOTTOM + bars_h.max(0.)
144+}
131145 /// The subtitle strip under the lanes: thin, because it is a picture of where
132146 /// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and
133147 /// this row has none.
crates/app/src/main.rsmodified+6 -0
@@ -492,6 +492,11 @@ struct Player {
492492 /// -- any key retires it, so does a click on it -- the bar says how many are
493493 /// behind it, and answering it brings the next one up.
494494 notices: std::collections::VecDeque<SharedString>,
495+ /// How tall the transient bars hanging off the bottom of the picture (the
496+ /// import line, the seek line, the notice) came out at prepaint, so the cue
497+ /// plate can sit clear of them ([`sub_bottom`]). Measured and not counted:
498+ /// a notice wraps to as many lines as the window is narrow.
499+ notice_h: Rc<Cell<Pixels>>,
495500 /// What the last finished export wrote, so the notice can be the way to it.
496501 /// Only the [`EXPORT_DONE`] line reads it -- any later notice has replaced
497502 /// that text -- so a click never opens a file the bar is not naming.
@@ -594,6 +599,7 @@ fn main() {
594599 sub_image: None,
595600 held: None,
596601 ruler: Rc::default(),
602+ notice_h: Rc::default(),
597603 // A second is [`PPS_DEFAULT`] pixels wide until someone
598604 // zooms or asks for the fit: a project opens at a scale, not
599605 // at whatever its first import happens to be long.
crates/app/src/render.rsmodified+10 -1
@@ -600,7 +600,16 @@ impl Render for Player {
600600 .gap(px(2.))
601601 .children(self.import_bar(cx))
602602 .children(self.seek_bar())
603- .children(self.notice_bar(cx)),
603+ .children(self.notice_bar(cx))
604+ // How tall the lot came out, for the
605+ // cue plate above to step over
606+ // ([`sub_bottom`]) -- the bars are
607+ // over the picture, and a message
608+ // drawn across the line being read
609+ // loses both of them. Zero with no
610+ // bar up, since this box is then
611+ // empty.
612+ .child(height_probe(self.notice_h.clone())),
604613 ),
605614 )
606615 .child(self.transport_bar(
crates/app/src/tests/media.rsmodified+23 -0
@@ -772,6 +772,29 @@ fn a_cue_is_on_screen_from_its_start_until_the_moment_it_ends() {
772772 assert!(at(-1.).is_empty());
773773 }
774774
775+/// The cue plate and the transient bars share the bottom edge of the picture,
776+/// and the plate is the one that moves: a notice drawn across the line being
777+/// read costs the reader both of them.
778+#[test]
779+fn a_cue_steps_over_whatever_bar_is_hanging_off_the_picture() {
780+ // Nothing hanging there, nothing moved: people know where the line sits,
781+ // and the no-notice position is the one they know, to the pixel.
782+ assert_eq!(sub_bottom(0.), SUB_BOTTOM);
783+ // A bar of any height is a bar the plate is clear of: its bottom edge is
784+ // above the bar's top edge, with the plate's own gap still under it.
785+ for bars in [1., 26., 48., 96., 300.] {
786+ assert!(
787+ sub_bottom(bars) >= bars + SUB_BOTTOM,
788+ "a {bars} px bar reaches the plate"
789+ );
790+ }
791+ // A taller bar never lowers the plate, and a box that was never painted
792+ // (or measured as nothing) reads as no bar at all rather than as a plate
793+ // pulled off the bottom of the window.
794+ assert!(sub_bottom(48.) > sub_bottom(26.));
795+ assert_eq!(sub_bottom(-10.), SUB_BOTTOM);
796+}
797+
775798 /// The two places a subtitle is drawn -- the plate over the picture and the
776799 /// strip under the lanes -- inside the 640x360 floor the rest of this window
777800 /// is sized for, and the plate readable on whatever the film is showing.
crates/app/src/tests/mod.rsmodified+1 -1
@@ -54,7 +54,7 @@ use super::{
5454
5555 use super::{
5656 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H,
57- SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box,
57+ SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,
5858 carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,
5959 Subs, subtitle_detail, subtitle_notice, subtitle_tail,
6060 sub_pick_name, subtitle_rows, subtitle_strip_h, walk_subtitles,
crates/app/src/timeline_math.rsmodified+21 -0
@@ -232,6 +232,27 @@ pub(crate) fn bounds_probe(into: Rc<Cell<Bounds<Pixels>>>) -> impl IntoElement {
232232 .size_full()
233233 }
234234
235+/// [`bounds_probe`] for a box something *else* is laid out against: it also asks
236+/// for one more frame whenever the height changed.
237+///
238+/// A measurement is read by the frame after the one that took it, and a notice
239+/// arriving over a paused picture repaints exactly once -- so without this the
240+/// cue would sit under that notice until something else happened to draw, which
241+/// on a paused window can be never.
242+pub(crate) fn height_probe(into: Rc<Cell<Pixels>>) -> impl IntoElement {
243+ canvas(
244+ move |bounds, window, _| {
245+ // Only on a change: an unconditional request is a repaint loop.
246+ if into.replace(bounds.size.height) != bounds.size.height {
247+ window.request_animation_frame();
248+ }
249+ },
250+ |_, _, _, _| (),
251+ )
252+ .absolute()
253+ .size_full()
254+}
255+
235256 /// Where along an element a click landed, 0..1. An element that was never
236257 /// painted has no width, and reads as its start rather than as NaN.
237258 pub(crate) fn frac_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 {
crates/app/src/ui/preview.rsmodified+21 -4
@@ -56,6 +56,9 @@ impl Player {
5656 // A picture is fitted onto the whole region and a plate hangs off the
5757 // bottom of it, and a track is one or the other -- so they are two
5858 // shapes and not one with the parts switched off.
59+ // What the transient bars along the bottom edge are taking up right now:
60+ // both shapes step up over it rather than be drawn under it.
61+ let bars = f32::from(self.notice_h.get());
5962 if let Some(image) = picture {
6063 // A *flex* box with the canvas as its one growing item: a percentage
6164 // size (`size_full`) inside an absolutely placed box has nothing to
@@ -63,16 +66,30 @@ impl Player {
6366 // flex item is sized by the box itself. Fitted the way the picture
6467 // above it is -- `Contain` over the same box -- so a canvas of the
6568 // picture's own shape lands exactly on it.
66- return Some(div().absolute().inset_0().flex().child(
67- img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain),
68- ));
69+ // Slid up by the bars' height and not *shrunk* by it: the top and
70+ // bottom insets cancel, so the box keeps the region's height and the
71+ // canvas keeps the fit (and so the scale) it had with nothing
72+ // hanging there -- a shorter box would refit the disc's canvas and
73+ // move every cue on it, not just the one over the bar. The picture
74+ // region clips (`overflow_hidden`), and what leaves the top of a
75+ // subtitle canvas is transparent.
76+ return Some(
77+ div()
78+ .absolute()
79+ .top(px(-bars))
80+ .bottom(px(bars))
81+ .left_0()
82+ .right_0()
83+ .flex()
84+ .child(img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain)),
85+ );
6986 }
7087 Some(
7188 div()
7289 .absolute()
7390 .left_0()
7491 .right_0()
75- .bottom(px(SUB_BOTTOM))
92+ .bottom(px(sub_bottom(bars)))
7693 .flex()
7794 .flex_col()
7895 .items_center()