The cue steps over the bar hanging off the picture
Browse files at this commit0c26d06073cbf06949da39e8411582e70316782dParent: db032d5- fix
- the cue steps over the bar hanging off the picture
7 changed files +96 -6
- crates/app/src/layout.rs +14 -0
- crates/app/src/main.rs +6 -0
- crates/app/src/render.rs +10 -1
- crates/app/src/tests/media.rs +23 -0
- crates/app/src/tests/mod.rs +1 -1
- crates/app/src/timeline_math.rs +21 -0
- crates/app/src/ui/preview.rs +21 -4
crates/app/src/layout.rsmodified+14 -0
| @@ -128,6 +128,20 @@ pub(crate) const SUB_TEXT: f32 = 14.; | |||
| 128 | pub(crate) const SUB_LINE_H: f32 = 18.; | 128 | pub(crate) const SUB_LINE_H: f32 = 18.; |
| 129 | /// How far off the bottom of the picture the plate sits. | 129 | /// How far off the bottom of the picture the plate sits. |
| 130 | pub(crate) const SUB_BOTTOM: f32 = 8.; | 130 | 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 | +} | ||
| 131 | /// The subtitle strip under the lanes: thin, because it is a picture of where | 145 | /// The subtitle strip under the lanes: thin, because it is a picture of where |
| 132 | /// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and | 146 | /// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and |
| 133 | /// this row has none. | 147 | /// this row has none. |
crates/app/src/main.rsmodified+6 -0
| @@ -492,6 +492,11 @@ struct Player { | |||
| 492 | /// -- any key retires it, so does a click on it -- the bar says how many are | 492 | /// -- any key retires it, so does a click on it -- the bar says how many are |
| 493 | /// behind it, and answering it brings the next one up. | 493 | /// behind it, and answering it brings the next one up. |
| 494 | notices: std::collections::VecDeque<SharedString>, | 494 | 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>>, | ||
| 495 | /// What the last finished export wrote, so the notice can be the way to it. | 500 | /// What the last finished export wrote, so the notice can be the way to it. |
| 496 | /// Only the [`EXPORT_DONE`] line reads it -- any later notice has replaced | 501 | /// Only the [`EXPORT_DONE`] line reads it -- any later notice has replaced |
| 497 | /// that text -- so a click never opens a file the bar is not naming. | 502 | /// that text -- so a click never opens a file the bar is not naming. |
| @@ -594,6 +599,7 @@ fn main() { | |||
| 594 | sub_image: None, | 599 | sub_image: None, |
| 595 | held: None, | 600 | held: None, |
| 596 | ruler: Rc::default(), | 601 | ruler: Rc::default(), |
| 602 | + notice_h: Rc::default(), | ||
| 597 | // A second is [`PPS_DEFAULT`] pixels wide until someone | 603 | // A second is [`PPS_DEFAULT`] pixels wide until someone |
| 598 | // zooms or asks for the fit: a project opens at a scale, not | 604 | // zooms or asks for the fit: a project opens at a scale, not |
| 599 | // at whatever its first import happens to be long. | 605 | // at whatever its first import happens to be long. |
crates/app/src/render.rsmodified+10 -1
| @@ -600,7 +600,16 @@ impl Render for Player { | |||
| 600 | .gap(px(2.)) | 600 | .gap(px(2.)) |
| 601 | .children(self.import_bar(cx)) | 601 | .children(self.import_bar(cx)) |
| 602 | .children(self.seek_bar()) | 602 | .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())), | ||
| 604 | ), | 613 | ), |
| 605 | ) | 614 | ) |
| 606 | .child(self.transport_bar( | 615 | .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() { | |||
| 772 | assert!(at(-1.).is_empty()); | 772 | assert!(at(-1.).is_empty()); |
| 773 | } | 773 | } |
| 774 | 774 | ||
| 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 | + | ||
| 775 | /// The two places a subtitle is drawn -- the plate over the picture and the | 798 | /// The two places a subtitle is drawn -- the plate over the picture and the |
| 776 | /// strip under the lanes -- inside the 640x360 floor the rest of this window | 799 | /// strip under the lanes -- inside the 640x360 floor the rest of this window |
| 777 | /// is sized for, and the plate readable on whatever the film is showing. | 800 | /// 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::{ | |||
| 54 | 54 | ||
| 55 | use super::{ | 55 | use super::{ |
| 56 | SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, | 56 | 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, |
| 58 | carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit, | 58 | carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit, |
| 59 | Subs, subtitle_detail, subtitle_notice, subtitle_tail, | 59 | Subs, subtitle_detail, subtitle_notice, subtitle_tail, |
| 60 | sub_pick_name, subtitle_rows, subtitle_strip_h, walk_subtitles, | 60 | 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 { | |||
| 232 | .size_full() | 232 | .size_full() |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 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 | + | ||
| 235 | /// Where along an element a click landed, 0..1. An element that was never | 256 | /// Where along an element a click landed, 0..1. An element that was never |
| 236 | /// painted has no width, and reads as its start rather than as NaN. | 257 | /// painted has no width, and reads as its start rather than as NaN. |
| 237 | pub(crate) fn frac_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 { | 258 | 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 { | |||
| 56 | // A picture is fitted onto the whole region and a plate hangs off the | 56 | // A picture is fitted onto the whole region and a plate hangs off the |
| 57 | // bottom of it, and a track is one or the other -- so they are two | 57 | // bottom of it, and a track is one or the other -- so they are two |
| 58 | // shapes and not one with the parts switched off. | 58 | // 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()); | ||
| 59 | if let Some(image) = picture { | 62 | if let Some(image) = picture { |
| 60 | // A *flex* box with the canvas as its one growing item: a percentage | 63 | // A *flex* box with the canvas as its one growing item: a percentage |
| 61 | // size (`size_full`) inside an absolutely placed box has nothing to | 64 | // size (`size_full`) inside an absolutely placed box has nothing to |
| @@ -63,16 +66,30 @@ impl Player { | |||
| 63 | // flex item is sized by the box itself. Fitted the way the picture | 66 | // flex item is sized by the box itself. Fitted the way the picture |
| 64 | // above it is -- `Contain` over the same box -- so a canvas of the | 67 | // above it is -- `Contain` over the same box -- so a canvas of the |
| 65 | // picture's own shape lands exactly on it. | 68 | // picture's own shape lands exactly on it. |
| 66 | - return Some(div().absolute().inset_0().flex().child( | 69 | + // Slid up by the bars' height and not *shrunk* by it: the top and |
| 67 | - img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain), | 70 | + // bottom insets cancel, so the box keeps the region's height and the |
| 68 | - )); | 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 | + ); | ||
| 69 | } | 86 | } |
| 70 | Some( | 87 | Some( |
| 71 | div() | 88 | div() |
| 72 | .absolute() | 89 | .absolute() |
| 73 | .left_0() | 90 | .left_0() |
| 74 | .right_0() | 91 | .right_0() |
| 75 | - .bottom(px(SUB_BOTTOM)) | 92 | + .bottom(px(sub_bottom(bars))) |
| 76 | .flex() | 93 | .flex() |
| 77 | .flex_col() | 94 | .flex_col() |
| 78 | .items_center() | 95 | .items_center() |