Skip to content

Commit

Permalink
fix(core): 🐛 the hit test for the TransformWidget on wrong position
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Nov 14, 2024
1 parent bdd1ce9 commit 8c99ac6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

### Fixed

- **core**: The size of the `Root` container is too small, which could lead to potential missed hits. (#pr @M-Adoo)
- **core**: The size of the `Root` container is too small, which could lead to potential missed hits. (#654 @M-Adoo)
- **core**: The hit test for the `TransformWidget` is not applied at the correct position. (#654 @M-Adoo)


## [0.4.0-alpha.15] - 2024-11-13
Expand Down
4 changes: 3 additions & 1 deletion core/src/builtin_widgets/transform_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ impl WrapRender for TransformWidget {

fn hit_test(&self, host: &dyn Render, ctx: &HitTestCtx, pos: Point) -> HitTest {
if let Some(t) = self.transform.inverse() {
let pos = t.transform_point(pos);
let lt = ctx.box_pos().unwrap();
let pos = (pos - lt).to_point();
let pos = t.transform_point(pos) + lt.to_vector();
host.hit_test(ctx, pos)
} else {
HitTest { hit: false, can_hit_child: false }
Expand Down
24 changes: 23 additions & 1 deletion core/src/events/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ mod tests {
}

#[test]
fn fix_align_test() {
fn fix_align_hit_test() {
reset_test_env!();
let (expect_hit, w_hit) = split_value(None);
let mut wnd = TestWindow::new_with_size(
Expand All @@ -697,4 +697,26 @@ mod tests {
assert!(expect_hit.read().is_some());
assert_eq!(dispatcher.hit_widget(), *expect_hit.read());
}

#[test]
fn fix_transform_hit() {
reset_test_env!();
let (expect_hit, w_hit) = split_value(None);
let mut wnd = TestWindow::new_with_size(
fn_widget! {
@MockBox {
anchor: Point::new(50., 50.),
transform: Transform::rotation(Angle::degrees(45.)),
size: Size::new(100., 100.),
on_mounted: move |ctx| *$w_hit.write() = Some(ctx.id),
}
},
Size::new(500., 500.),
);
wnd.draw_frame();
let mut dispatcher = wnd.dispatcher.borrow_mut();
dispatcher.info.cursor_pos = Point::new(51., 51.);
assert!(expect_hit.read().is_some());
assert_eq!(dispatcher.hit_widget(), *expect_hit.read());
}
}

0 comments on commit 8c99ac6

Please sign in to comment.