fn update_mouse_state(&mut self, is_mouse_button_changed: bool, is_mouse_moved: bool) -> bool {
        let mut new_cursor = self.mouse_cursor;

        // Determine the display object the mouse is hovering over.
        // Search through levels from top-to-bottom, returning the first display object that is under the mouse.
        let needs_render = self.mutate_with_update_context(|context| {
            let new_over_object =
                context
                    .stage
                    .iter_depth_list()
                    .rev()
                    .find_map(|(_depth, level)| {
                        level
                            .as_interactive()
                            .and_then(|l| l.mouse_pick(context, *context.mouse_position, true))
                    });

            let mut events: smallvec::SmallVec<[(InteractiveObject<'_>, ClipEvent); 2]> =
                Default::default();

            if is_mouse_moved {
                events.push((
                    new_over_object.unwrap_or_else(|| context.stage.into()),
                    ClipEvent::MouseMoveInside,
                ));
            }

            // Cancel hover if an object is removed from the stage.
            if let Some(hovered) = context.mouse_over_object {
                if hovered.as_displayobject().removed() {
                    context.mouse_over_object = None;
                }
            }
            if let Some(pressed) = context.mouse_down_object {
                if pressed.as_displayobject().removed() {
                    context.mouse_down_object = None;
                }
            }

            let cur_over_object = context.mouse_over_object;
            // Check if a new object has been hovered over.
            if !InteractiveObject::option_ptr_eq(cur_over_object, new_over_object) {
                // If the mouse button is down, the object the user clicked on grabs the focus
                // and fires "drag" events. Other objects are ignroed.
                if context.input.is_mouse_down() {
                    context.mouse_over_object = new_over_object;
                    if let Some(down_object) = context.mouse_down_object {
                        if InteractiveObject::option_ptr_eq(
                            context.mouse_down_object,
                            cur_over_object,
                        ) {
                            // Dragged from outside the clicked object to the inside.
                            events.push((
                                down_object,
                                ClipEvent::DragOut {
                                    to: new_over_object,
                                },
                            ));
                        } else if InteractiveObject::option_ptr_eq(
                            context.mouse_down_object,
                            new_over_object,
                        ) {
                            // Dragged from inside the clicked object to the outside.
                            events.push((
                                down_object,
                                ClipEvent::DragOver {
                                    from: cur_over_object,
                                },
                            ));
                        }
                    }
                } else {
                    // The mouse button is up, so fire rollover states for the object we are hovering over.
                    // Rolled out of the previous object.
                    if let Some(cur_over_object) = cur_over_object {
                        events.push((
                            cur_over_object,
                            ClipEvent::RollOut {
                                to: new_over_object,
                            },
                        ));
                    }
                    // Rolled over the new object.
                    if let Some(new_over_object) = new_over_object {
                        new_cursor = new_over_object.mouse_cursor(context);
                        events.push((
                            new_over_object,
                            ClipEvent::RollOver {
                                from: cur_over_object,
                            },
                        ));
                    } else {
                        new_cursor = MouseCursor::Arrow;
                    }
                }
            }
            context.mouse_over_object = new_over_object;

            // Handle presses and releases.
            if is_mouse_button_changed {
                if context.input.is_mouse_down() {
                    // Pressed on a hovered object.
                    if let Some(over_object) = context.mouse_over_object {
                        events.push((over_object, ClipEvent::Press));
                        context.mouse_down_object = context.mouse_over_object;
                    } else {
                        events.push((context.stage.into(), ClipEvent::Press));
                    }
                } else {
                    if let Some(over_object) = context.mouse_over_object {
                        events.push((over_object, ClipEvent::MouseUpInside));
                    } else {
                        events.push((context.stage.into(), ClipEvent::MouseUpInside));
                    }

                    let released_inside = InteractiveObject::option_ptr_eq(
                        context.mouse_down_object,
                        context.mouse_over_object,
                    );
                    if released_inside {
                        // Released inside the clicked object.
                        if let Some(down_object) = context.mouse_down_object {
                            events.push((down_object, ClipEvent::Release));
                        } else {
                            events.push((context.stage.into(), ClipEvent::Release));
                        }
                    } else {
                        // Released outside the clicked object.
                        if let Some(down_object) = context.mouse_down_object {
                            events.push((down_object, ClipEvent::ReleaseOutside));
                        } else {
                            events.push((context.stage.into(), ClipEvent::ReleaseOutside));
                        }
                        // The new object is rolled over immediately.
                        if let Some(over_object) = context.mouse_over_object {
                            new_cursor = over_object.mouse_cursor(context);
                            events.push((
                                over_object,
                                ClipEvent::RollOver {
                                    from: cur_over_object,
                                },
                            ));
                        } else {
                            new_cursor = MouseCursor::Arrow;
                        }
                    }
                    context.mouse_down_object = None;
                }
            }

            // Fire any pending mouse events.
            let needs_render = if events.is_empty() {
                false
            } else {
                for (object, event) in events {
                    if !object.as_displayobject().removed() {
                        object.handle_clip_event(context, event);
                    }
                }
                true
            };
            Self::run_actions(context);
            needs_render
        });

        // Update mouse cursor if it has changed.
        if new_cursor != self.mouse_cursor {
            self.mouse_cursor = new_cursor;
            self.ui.set_mouse_cursor(new_cursor)
        }

        needs_render
    }
/// Updates the hover state of buttons.
Updates the hover state of buttons.
Updates the hover state of buttons .
fn update_mouse_state(&mut self, is_mouse_button_changed: bool, is_mouse_moved: bool) -> bool {
        let mut new_cursor = self.mouse_cursor;
        // Determine the display object the mouse is hovering over.
        // Search through levels from top-to-bottom, returning the first display object that is under the mouse.
        let needs_render = self.mutate_with_update_context(|context| {
            let new_over_object =
                context
                    .stage
                    .iter_depth_list()
                    .rev()
                    .find_map(|(_depth, level)| {
                        level
                            .as_interactive()
                            .and_then(|l| l.mouse_pick(context, *context.mouse_position, true))
                    });
            let mut events: smallvec::SmallVec<[(InteractiveObject<'_>, ClipEvent); 2]> =
                Default::default();
            if is_mouse_moved {
                events.push((
                    new_over_object.unwrap_or_else(|| context.stage.into()),
                    ClipEvent::MouseMoveInside,
                ));
            }
            // Cancel hover if an object is removed from the stage.
            if let Some(hovered) = context.mouse_over_object {
                if hovered.as_displayobject().removed() {
                    context.mouse_over_object = None;
                }
            }
            if let Some(pressed) = context.mouse_down_object {
                if pressed.as_displayobject().removed() {
                    context.mouse_down_object = None;
                }
            }
            let cur_over_object = context.mouse_over_object;
            // Check if a new object has been hovered over.
            if !InteractiveObject::option_ptr_eq(cur_over_object, new_over_object) {
                // If the mouse button is down, the object the user clicked on grabs the focus
                // and fires "drag" events. Other objects are ignroed.
                if context.input.is_mouse_down() {
                    context.mouse_over_object = new_over_object;
                    if let Some(down_object) = context.mouse_down_object {
                        if InteractiveObject::option_ptr_eq(
                            context.mouse_down_object,
                            cur_over_object,
                        ) {
                            // Dragged from outside the clicked object to the inside.
                            events.push((
                                down_object,
                                ClipEvent::DragOut {
                                    to: new_over_object,
                                },
                            ));
                        } else if InteractiveObject::option_ptr_eq(
                            context.mouse_down_object,
                            new_over_object,
                        ) {
                            // Dragged from inside the clicked object to the outside.
                            events.push((
                                down_object,
                                ClipEvent::DragOver {
                                    from: cur_over_object,
                                },
                            ));
                        }
                    }
                } else {
                    // The mouse button is up, so fire rollover states for the object we are hovering over.
                    // Rolled out of the previous object.
                    if let Some(cur_over_object) = cur_over_object {
                        events.push((
                            cur_over_object,
                            ClipEvent::RollOut {
                                to: new_over_object,
                            },
                        ));
                    }
                    // Rolled over the new object.
                    if let Some(new_over_object) = new_over_object {
                        new_cursor = new_over_object.mouse_cursor(context);
                        events.push((
                            new_over_object,
                            ClipEvent::RollOver {
                                from: cur_over_object,
                            },
                        ));
                    } else {
                        new_cursor = MouseCursor::Arrow;
                    }
                }
            }
            context.mouse_over_object = new_over_object;
            // Handle presses and releases.
            if is_mouse_button_changed {
                if context.input.is_mouse_down() {
                    // Pressed on a hovered object.
                    if let Some(over_object) = context.mouse_over_object {
                        events.push((over_object, ClipEvent::Press));
                        context.mouse_down_object = context.mouse_over_object;
                    } else {
                        events.push((context.stage.into(), ClipEvent::Press));
                    }
                } else {
                    if let Some(over_object) = context.mouse_over_object {
                        events.push((over_object, ClipEvent::MouseUpInside));
                    } else {
                        events.push((context.stage.into(), ClipEvent::MouseUpInside));
                    }
                    let released_inside = InteractiveObject::option_ptr_eq(
                        context.mouse_down_object,
                        context.mouse_over_object,
                    );
                    if released_inside {
                        // Released inside the clicked object.
                        if let Some(down_object) = context.mouse_down_object {
                            events.push((down_object, ClipEvent::Release));
                        } else {
                            events.push((context.stage.into(), ClipEvent::Release));
                        }
                    } else {
                        // Released outside the clicked object.
                        if let Some(down_object) = context.mouse_down_object {
                            events.push((down_object, ClipEvent::ReleaseOutside));
                        } else {
                            events.push((context.stage.into(), ClipEvent::ReleaseOutside));
                        }
                        // The new object is rolled over immediately.
                        if let Some(over_object) = context.mouse_over_object {
                            new_cursor = over_object.mouse_cursor(context);
                            events.push((
                                over_object,
                                ClipEvent::RollOver {
                                    from: cur_over_object,
                                },
                            ));
                        } else {
                            new_cursor = MouseCursor::Arrow;
                        }
                    }
                    context.mouse_down_object = None;
                }
            }
            // Fire any pending mouse events.
            let needs_render = if events.is_empty() {
                false
            } else {
                for (object, event) in events {
                    if !object.as_displayobject().removed() {
                        object.handle_clip_event(context, event);
                    }
                }
                true
            };
            Self::run_actions(context);
            needs_render
        });
        // Update mouse cursor if it has changed.
        if new_cursor != self.mouse_cursor {
            self.mouse_cursor = new_cursor;
            self.ui.set_mouse_cursor(new_cursor)
        }
        needs_render
    }
fn update_mouse_state ( & mut self , is_mouse_button_changed : bool , is_mouse_moved : bool ) -> bool { let mut new_cursor = self . mouse_cursor ; // Determine the display object the mouse is hovering over. // Search through levels from top-to-bottom, returning the first display object that is under the mouse. let needs_render = self . mutate_with_update_context ( | context | { let new_over_object = context . stage . iter_depth_list ( ) . rev ( ) . find_map ( | ( _depth , level ) | { level . as_interactive ( ) . and_then ( | l | l . mouse_pick ( context , * context . mouse_position , true ) ) } ) ; let mut events : smallvec :: SmallVec < [ ( InteractiveObject < ' _ > , ClipEvent ) ; 2 ] > = Default :: default ( ) ; if is_mouse_moved { events . push ( ( new_over_object . unwrap_or_else ( | | context . stage . into ( ) ) , ClipEvent :: MouseMoveInside , ) ) ; } // Cancel hover if an object is removed from the stage. if let Some ( hovered ) = context . mouse_over_object { if hovered . as_displayobject ( ) . removed ( ) { context . mouse_over_object = None ; } } if let Some ( pressed ) = context . mouse_down_object { if pressed . as_displayobject ( ) . removed ( ) { context . mouse_down_object = None ; } } let cur_over_object = context . mouse_over_object ; // Check if a new object has been hovered over. if ! InteractiveObject :: option_ptr_eq ( cur_over_object , new_over_object ) { // If the mouse button is down, the object the user clicked on grabs the focus // and fires "drag" events. Other objects are ignroed. if context . input . is_mouse_down ( ) { context . mouse_over_object = new_over_object ; if let Some ( down_object ) = context . mouse_down_object { if InteractiveObject :: option_ptr_eq ( context . mouse_down_object , cur_over_object , ) { // Dragged from outside the clicked object to the inside. events . push ( ( down_object , ClipEvent :: DragOut { to : new_over_object , } , ) ) ; } else if InteractiveObject :: option_ptr_eq ( context . mouse_down_object , new_over_object , ) { // Dragged from inside the clicked object to the outside. events . push ( ( down_object , ClipEvent :: DragOver { from : cur_over_object , } , ) ) ; } } } else { // The mouse button is up, so fire rollover states for the object we are hovering over. // Rolled out of the previous object. if let Some ( cur_over_object ) = cur_over_object { events . push ( ( cur_over_object , ClipEvent :: RollOut { to : new_over_object , } , ) ) ; } // Rolled over the new object. if let Some ( new_over_object ) = new_over_object { new_cursor = new_over_object . mouse_cursor ( context ) ; events . push ( ( new_over_object , ClipEvent :: RollOver { from : cur_over_object , } , ) ) ; } else { new_cursor = MouseCursor :: Arrow ; } } } context . mouse_over_object = new_over_object ; // Handle presses and releases. if is_mouse_button_changed { if context . input . is_mouse_down ( ) { // Pressed on a hovered object. if let Some ( over_object ) = context . mouse_over_object { events . push ( ( over_object , ClipEvent :: Press ) ) ; context . mouse_down_object = context . mouse_over_object ; } else { events . push ( ( context . stage . into ( ) , ClipEvent :: Press ) ) ; } } else { if let Some ( over_object ) = context . mouse_over_object { events . push ( ( over_object , ClipEvent :: MouseUpInside ) ) ; } else { events . push ( ( context . stage . into ( ) , ClipEvent :: MouseUpInside ) ) ; } let released_inside = InteractiveObject :: option_ptr_eq ( context . mouse_down_object , context . mouse_over_object , ) ; if released_inside { // Released inside the clicked object. if let Some ( down_object ) = context . mouse_down_object { events . push ( ( down_object , ClipEvent :: Release ) ) ; } else { events . push ( ( context . stage . into ( ) , ClipEvent :: Release ) ) ; } } else { // Released outside the clicked object. if let Some ( down_object ) = context . mouse_down_object { events . push ( ( down_object , ClipEvent :: ReleaseOutside ) ) ; } else { events . push ( ( context . stage . into ( ) , ClipEvent :: ReleaseOutside ) ) ; } // The new object is rolled over immediately. if let Some ( over_object ) = context . mouse_over_object { new_cursor = over_object . mouse_cursor ( context ) ; events . push ( ( over_object , ClipEvent :: RollOver { from : cur_over_object , } , ) ) ; } else { new_cursor = MouseCursor :: Arrow ; } } context . mouse_down_object = None ; } } // Fire any pending mouse events. let needs_render = if events . is_empty ( ) { false } else { for ( object , event ) in events { if ! object . as_displayobject ( ) . removed ( ) { object . handle_clip_event ( context , event ) ; } } true } ; Self :: run_actions ( context ) ; needs_render } ) ; // Update mouse cursor if it has changed. if new_cursor != self . mouse_cursor { self . mouse_cursor = new_cursor ; self . ui . set_mouse_cursor ( new_cursor ) } needs_render }
Updates the hover state of buttons.
Updates the hover state of buttons .
&mut self
is_mouse_button_changed
bool
is_mouse_moved
bool
&mut self
is_mouse_button_changed
bool
is_mouse_moved
bool