forge
Explore
Log in

Don't you dare go Hollow

A card's sliders follow the hand, not only the press

Browse files at this commit

2ed6fe78f87560178df4ea2beef627d9f3e7b120Ahmet Kaan GümüşParent: dc279aa
  • fix
    • a card's sliders follow the hand, not only the press
Show full message
🐛 fix(ui): a card's sliders follow the hand, not only the press

Every drag in this window is tracked from the root, because each starts
on a strip a few pixels wide that the pointer leaves at once. A card
puts an occluding scrim over that root, and occluding is where gpui's
hit test stops (`Hitbox::is_hovered`) -- so the root heard nothing while
a card was up and the equalizer handle, the colour bars and the speed
bar were set by the press and then frozen there, release included.

The two listeners are methods now, and the scrim of every card that
holds a slider registers them as well: the drag tracks under the card,
a drag that leaves it is picked up by the root's copy without a seam,
and the release still writes exactly one undo step.
crates/app/src/main.rsmodified+152 -115
@@ -550,6 +550,25 @@ fn scrim() -> Div {
550550 div().absolute().inset_0().occlude()
551551 }
552552
553+/// The sheet a card with a *slider* in it takes instead: the same scrim, with
554+/// the window's own drag listeners on it as well.
555+///
556+/// A scrim occludes, and occluding is where gpui's hit test stops
557+/// (`Hitbox::is_hovered`, window.rs:788) -- so while a card is up the root is
558+/// not hovered anywhere behind it and its `on_mouse_move`/`on_mouse_up` hear
559+/// nothing at all. Every drag in this window is tracked from the root, because
560+/// each of them starts on a strip a few pixels wide that the pointer leaves at
561+/// once ([`Player::drag_move`]), so a card's handles were set by the press and
562+/// then frozen: the value never followed the hand and the release never wrote.
563+/// The scrim is the one surface above the occluder that covers the whole card,
564+/// so the same two listeners go here, and a drag that leaves the card is picked
565+/// up by the root's copy of them without a seam.
566+fn drag_scrim(cx: &mut Context<Player>) -> Div {
567+ scrim()
568+ .on_mouse_move(cx.listener(Player::drag_move))
569+ .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release))
570+}
571+
553572 /// A press that stops here. What every card's body hands its scrim: the scrim
554573 /// closes the card on a press, and the card is painted after it, so this listener
555574 /// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant
@@ -5097,6 +5116,137 @@ impl Player {
50975116 self.set_volume(|volume| volume.set_along(along), cx);
50985117 }
50995118
5119+ /// One sample of whatever drag is in the hand: the equalizer's handle, a
5120+ /// clip's edge, a colour bar, the speed bar, the volume slider or the
5121+ /// playhead. Each of those starts on a strip a few pixels wide that the
5122+ /// pointer leaves immediately, so none of them can be tracked from the
5123+ /// element it started on -- the gesture is followed here instead, on a
5124+ /// hitbox that covers everything the hand can reach.
5125+ ///
5126+ /// Registered on the root *and* on the scrim of every card that holds a
5127+ /// slider ([`Player::drag_scrim`]). An occluding sheet ends gpui's hit test
5128+ /// where it sits (`Hitbox::is_hovered`, window.rs:788), so while a card is
5129+ /// up the root is not hovered anywhere under it and hears none of this: the
5130+ /// press set a value and the drag then froze on it.
5131+ fn drag_move(&mut self, event: &MouseMoveEvent, _: &mut Window, cx: &mut Context<Self>) {
5132+ // A handle is 10 px across and the pointer leaves it at once, so
5133+ // the equalizer drag is tracked here for the ruler's reason.
5134+ if self.eq_dragging {
5135+ if event.pressed_button == Some(MouseButton::Left) {
5136+ self.drag_band(event.position, cx);
5137+ } else {
5138+ // Released outside the window: the up below never came,
5139+ // so this is where the gesture ends -- and it still owes
5140+ // the one write the whole drag is worth.
5141+ self.eq_dragging = false;
5142+ self.commit_eq(cx);
5143+ }
5144+ return;
5145+ }
5146+ // A clip edge is 6 px wide and the pointer leaves it on the
5147+ // first drag, so the gesture is tracked here for the same
5148+ // reason -- and it ends here too when the button came up
5149+ // outside the window, still owing its one edit.
5150+ if self.trim.is_some() {
5151+ match event.pressed_button {
5152+ Some(MouseButton::Left) => self.trim_to(event.position.x, cx),
5153+ _ => self.commit_trim(cx),
5154+ }
5155+ return;
5156+ }
5157+ // A colour slider is 4 px tall and the pointer leaves it just as
5158+ // fast; every sample is live, so the release owes no write of
5159+ // its own -- what the last sample set is what the clip carries.
5160+ if self.color_dragging {
5161+ if event.pressed_button == Some(MouseButton::Left) {
5162+ self.drag_color(event.position.x, false, cx);
5163+ } else {
5164+ // The release happened outside the window, so this is
5165+ // where the gesture ends -- and it may not end on a
5166+ // sample the worker was too busy to take.
5167+ self.color_dragging = false;
5168+ self.flush_drag(cx);
5169+ }
5170+ return;
5171+ }
5172+ // The speed bar, the same 4 px and the same live writes: the
5173+ // press took the undo step and every sample since is live.
5174+ if self.speed_dragging {
5175+ if event.pressed_button == Some(MouseButton::Left) {
5176+ self.drag_speed(event.position.x, false, cx);
5177+ } else {
5178+ self.speed_dragging = false;
5179+ self.flush_drag(cx);
5180+ }
5181+ return;
5182+ }
5183+ // The volume slider, the same live writes: what the hand is on
5184+ // is what the speakers are doing, and there is nothing to undo.
5185+ if self.volume_dragging {
5186+ if event.pressed_button == Some(MouseButton::Left) {
5187+ self.drag_volume(event.position.x, cx);
5188+ } else {
5189+ self.volume_dragging = false;
5190+ }
5191+ return;
5192+ }
5193+ if !self.scrubbing {
5194+ return;
5195+ }
5196+ if event.pressed_button == Some(MouseButton::Left) {
5197+ self.scrub_to(event.position.x, false, cx);
5198+ } else {
5199+ // A release outside the window never reaches the handler
5200+ // below, so the first button-up move is when we learn the
5201+ // drag is over. Without this the next hover would scrub.
5202+ self.scrubbing = false;
5203+ }
5204+ }
5205+
5206+ /// Where a drag ends: the release lands exactly, and whatever the gesture
5207+ /// owes -- one undo step for the equalizer and the trim, a flush for the
5208+ /// live-writing bars -- is paid here. On the root and on a card's scrim
5209+ /// both, for [`Player::drag_move`]'s reason: a release over an open card
5210+ /// never reaches the root.
5211+ fn drag_release(&mut self, event: &MouseUpEvent, _: &mut Window, cx: &mut Context<Self>) {
5212+ if std::mem::take(&mut self.eq_dragging) {
5213+ // The release lands exactly, then the gesture is written
5214+ // once -- the append-only table's whole reason.
5215+ self.drag_band(event.position, cx);
5216+ self.commit_eq(cx);
5217+ return;
5218+ }
5219+ if self.trim.is_some() {
5220+ // The release lands exactly, then the gesture is
5221+ // written once -- one edit, one undo step.
5222+ self.trim_to(event.position.x, cx);
5223+ self.commit_trim(cx);
5224+ return;
5225+ }
5226+ if std::mem::take(&mut self.color_dragging) {
5227+ // The release lands exactly where the hand let go, and
5228+ // it is a live write like every other sample: the undo
5229+ // step the gesture rolls back to was the press's. The
5230+ // flush is what makes "exactly" true while the worker is
5231+ // still busy -- the sample above would only be held.
5232+ self.drag_color(event.position.x, false, cx);
5233+ self.flush_drag(cx);
5234+ return;
5235+ }
5236+ if std::mem::take(&mut self.speed_dragging) {
5237+ self.drag_speed(event.position.x, false, cx);
5238+ self.flush_drag(cx);
5239+ return;
5240+ }
5241+ if std::mem::take(&mut self.volume_dragging) {
5242+ self.drag_volume(event.position.x, cx);
5243+ return;
5244+ }
5245+ if std::mem::take(&mut self.scrubbing) {
5246+ self.scrub_to(event.position.x, true, cx);
5247+ }
5248+ }
5249+
51005250 fn toggle_or_restart(&mut self, cx: &mut Context<Self>) {
51015251 if self.exporting().is_some() {
51025252 return;
@@ -5894,121 +6044,8 @@ impl Render for Player {
58946044 // Scrubbing is tracked on the root because the pointer leaves the
58956045 // 6 px ruler on the first drag and its own listeners then stop
58966046 // firing; the root's hitbox is the whole window.
5897- .on_mouse_move(cx.listener(|this, event: &MouseMoveEvent, _, cx| {
5898- // A handle is 10 px across and the pointer leaves it at once, so
5899- // the equalizer drag is tracked here for the ruler's reason.
5900- if this.eq_dragging {
5901- if event.pressed_button == Some(MouseButton::Left) {
5902- this.drag_band(event.position, cx);
5903- } else {
5904- // Released outside the window: the up below never came,
5905- // so this is where the gesture ends -- and it still owes
5906- // the one write the whole drag is worth.
5907- this.eq_dragging = false;
5908- this.commit_eq(cx);
5909- }
5910- return;
5911- }
5912- // A clip edge is 6 px wide and the pointer leaves it on the
5913- // first drag, so the gesture is tracked here for the same
5914- // reason -- and it ends here too when the button came up
5915- // outside the window, still owing its one edit.
5916- if this.trim.is_some() {
5917- match event.pressed_button {
5918- Some(MouseButton::Left) => this.trim_to(event.position.x, cx),
5919- _ => this.commit_trim(cx),
5920- }
5921- return;
5922- }
5923- // A colour slider is 4 px tall and the pointer leaves it just as
5924- // fast; every sample is live, so the release owes no write of
5925- // its own -- what the last sample set is what the clip carries.
5926- if this.color_dragging {
5927- if event.pressed_button == Some(MouseButton::Left) {
5928- this.drag_color(event.position.x, false, cx);
5929- } else {
5930- // The release happened outside the window, so this is
5931- // where the gesture ends -- and it may not end on a
5932- // sample the worker was too busy to take.
5933- this.color_dragging = false;
5934- this.flush_drag(cx);
5935- }
5936- return;
5937- }
5938- // The speed bar, the same 4 px and the same live writes: the
5939- // press took the undo step and every sample since is live.
5940- if this.speed_dragging {
5941- if event.pressed_button == Some(MouseButton::Left) {
5942- this.drag_speed(event.position.x, false, cx);
5943- } else {
5944- this.speed_dragging = false;
5945- this.flush_drag(cx);
5946- }
5947- return;
5948- }
5949- // The volume slider, the same live writes: what the hand is on
5950- // is what the speakers are doing, and there is nothing to undo.
5951- if this.volume_dragging {
5952- if event.pressed_button == Some(MouseButton::Left) {
5953- this.drag_volume(event.position.x, cx);
5954- } else {
5955- this.volume_dragging = false;
5956- }
5957- return;
5958- }
5959- if !this.scrubbing {
5960- return;
5961- }
5962- if event.pressed_button == Some(MouseButton::Left) {
5963- this.scrub_to(event.position.x, false, cx);
5964- } else {
5965- // A release outside the window never reaches the handler
5966- // below, so the first button-up move is when we learn the
5967- // drag is over. Without this the next hover would scrub.
5968- this.scrubbing = false;
5969- }
5970- }))
5971- .on_mouse_up(
5972- MouseButton::Left,
5973- cx.listener(|this, event: &MouseUpEvent, _, cx| {
5974- if std::mem::take(&mut this.eq_dragging) {
5975- // The release lands exactly, then the gesture is written
5976- // once -- the append-only table's whole reason.
5977- this.drag_band(event.position, cx);
5978- this.commit_eq(cx);
5979- return;
5980- }
5981- if this.trim.is_some() {
5982- // The release lands exactly, then the gesture is
5983- // written once -- one edit, one undo step.
5984- this.trim_to(event.position.x, cx);
5985- this.commit_trim(cx);
5986- return;
5987- }
5988- if std::mem::take(&mut this.color_dragging) {
5989- // The release lands exactly where the hand let go, and
5990- // it is a live write like every other sample: the undo
5991- // step the gesture rolls back to was the press's. The
5992- // flush is what makes "exactly" true while the worker is
5993- // still busy -- the sample above would only be held.
5994- this.drag_color(event.position.x, false, cx);
5995- this.flush_drag(cx);
5996- return;
5997- }
5998- if std::mem::take(&mut this.speed_dragging) {
5999- this.drag_speed(event.position.x, false, cx);
6000- this.flush_drag(cx);
6001- return;
6002- }
6003- if std::mem::take(&mut this.volume_dragging) {
6004- this.drag_volume(event.position.x, cx);
6005- return;
6006- }
6007- if std::mem::take(&mut this.scrubbing) {
6008- this.scrub_to(event.position.x, true, cx);
6009- }
6010- }),
6011- )
6047+ .on_mouse_move(cx.listener(Self::drag_move))
6048+ .on_mouse_up(MouseButton::Left, cx.listener(Self::drag_release))
60126049 .size_full()
60136050 .flex()
60146051 .flex_col()
crates/app/src/ui/cards.rsmodified+3 -3
@@ -747,7 +747,7 @@ impl Player {
747747 // corner as the 20 Hz tick, and the two lines above it (+6 and -6)
748748 // already say what the box is worth per pixel.
749749 Some(
750- scrim()
750+ drag_scrim(cx)
751751 .flex()
752752 .justify_center()
753753 .items_center()
@@ -1085,7 +1085,7 @@ impl Player {
10851085 })
10861086 .collect();
10871087 Some(
1088- scrim()
1088+ drag_scrim(cx)
10891089 .flex()
10901090 .justify_center()
10911091 .items_center()
@@ -1202,7 +1202,7 @@ impl Player {
12021202 })
12031203 .collect();
12041204 Some(
1205- scrim()
1205+ drag_scrim(cx)
12061206 .flex()
12071207 .justify_center()
12081208 .items_center()