Fix bounds calculations

This commit is contained in:
Nathan Sobo 2023-09-08 06:45:23 -06:00
parent 7738867639
commit 713d72942d
3 changed files with 3 additions and 5 deletions

View File

@ -118,7 +118,6 @@ impl<V: 'static> Div<V> {
})
}
let bounds = layout.bounds;
let pressed = Cell::new(hovered && cx.is_mouse_down(MouseButton::Left));
cx.on_event(layout.order, move |_, event: &MouseButtonEvent, _| {
if bounds.contains_point(event.position) {

View File

@ -63,15 +63,14 @@ impl<V: 'static, E: Element<V> + Styleable> Element<V> for Hoverable<E> {
) where
Self: Sized,
{
self.hovered
.set(layout.bounds.contains_point(cx.mouse_position()));
let bounds = layout.bounds + parent_origin;
self.hovered.set(bounds.contains_point(cx.mouse_position()));
let slot = self.cascade_slot;
let style = self.hovered.get().then_some(self.hovered_style.clone());
self.style_cascade().set(slot, style);
let hovered = self.hovered.clone();
let bounds = layout.bounds;
cx.on_event(layout.order, move |_view, _: &MouseMovedEvent, cx| {
cx.bubble_event();
if bounds.contains_point(cx.mouse_position()) != hovered.get() {

View File

@ -68,7 +68,7 @@ impl<V: 'static, E: Element<V> + Styleable> Element<V> for Pressable<E> {
self.style_cascade().set(slot, style);
let pressed = self.pressed.clone();
let bounds = layout.bounds;
let bounds = layout.bounds + parent_origin;
cx.on_event(layout.order, move |_view, event: &MouseButtonEvent, cx| {
if event.is_down {
if bounds.contains_point(event.position) {