pub struct MouseRegion {
pub key: Option<KeyRef>,
pub on_enter: Option<PointerEnterEventListener>,
pub on_hover: Option<PointerHoverEventListener>,
pub on_exit: Option<PointerExitEventListener>,
pub cursor: MouseCursorRef,
pub opaque: bool,
pub hit_test_behavior: Option<HitTestBehavior>,
pub child: Option<WidgetRef>,
}Expand description
A widget that tracks the movement of mice.
MouseRegion is used
when it is needed to compare the list of objects that a mouse pointer is
hovering over between this frame and the last frame. This means entering
events, exiting events, and mouse cursors.
To listen to general pointer events, use Listener, or more preferably,
GestureDetector.
§Layout behavior
See BoxConstraints for an introduction to box layout models.
If it has a child, this widget defers to the child for sizing behavior. If it does not have a child, it grows to fit the parent instead.
See also:
Listener, a similar widget that tracks pointer events when the pointer has buttons pressed.
By default, all callbacks are empty, cursor is MouseCursor.defer, and
opaque is true.
Fields§
§key: Option<KeyRef>§on_enter: Option<PointerEnterEventListener>Triggered when a mouse pointer has entered this widget.
This callback is triggered when the pointer, with or without buttons pressed, has started to be contained by the region of this widget. More specifically, the callback is triggered by the following cases:
- This widget has appeared under a pointer.
- This widget has moved to under a pointer.
- A new pointer has been added to somewhere within this widget.
- An existing pointer has moved into this widget.
This callback is not always matched by an on_exit. If the
MouseRegion is unmounted while being hovered by a pointer, the
on_exit of the widget callback will never called. For more details,
see on_exit.
The time that this callback is triggered is always between frames: either during the post-frame callbacks, or during the callback of a pointer event.
See also:
on_exit, which is triggered when a mouse pointer exits the region.MouseTrackerAnnotation.onEnter, which is how this callback is internally implemented.
on_hover: Option<PointerHoverEventListener>Triggered when a pointer moves into a position within this widget without buttons pressed.
Usually this is only fired for pointers which report their location when not down (e.g. mouse pointers). Certain devices also fire this event on single taps in accessibility mode.
This callback is not triggered by the movement of the widget.
The time that this callback is triggered is during the callback of a pointer event, which is always between frames.
See also:
Listener::on_pointer_hover, which does the same job. Prefer usingListener::on_pointer_hover, since hover events are similar to other regular events.
on_exit: Option<PointerExitEventListener>Triggered when a mouse pointer has exited this widget when the widget is still mounted.
This callback is triggered when the pointer, with or without buttons pressed, has stopped being contained by the region of this widget, except when the exit is caused by the disappearance of this widget. More specifically, this callback is triggered by the following cases:
- A pointer that is hovering this widget has moved away.
- A pointer that is hovering this widget has been removed.
- This widget, which is being hovered by a pointer, has moved away.
And is not triggered by the following case:
- This widget, which is being hovered by a pointer, has disappeared.
This means that a MouseRegion::on_exit might not be matched by a
MouseRegion::on_enter.
This restriction aims to prevent a common misuse: if State::set_state is
called during MouseRegion::on_exit without checking whether the widget is
still mounted, an exception will occur. This is because the callback is
triggered during the post-frame phase, at which point the widget has been
unmounted. Since State::set_state is exclusive to widgets, the restriction
is specific to MouseRegion, and does not apply to its lower-level
counterparts, RenderMouseRegion and MouseTrackerAnnotation.
There are a few ways to mitigate this restriction:
- If the hover state is completely contained within a widget that
unconditionally creates this
MouseRegion, then this will not be a concern, since after theMouseRegionis unmounted the state is no longer used. - Otherwise, the outer widget very likely has access to the variable that
controls whether this
MouseRegionis present. If so, callon_exitat the event that turns the condition from true to false. - In cases where the solutions above won’t work, you can always
override
State::disposeand callon_exit, or create your own widget usingRenderMouseRegion.
See also:
on_enter, which is triggered when a mouse pointer enters the region.RenderMouseRegionandMouseTrackerAnnotation.onExit, which are how this callback is internally implemented, but without the restriction.
cursor: MouseCursorRefThe mouse cursor for mouse pointers that are hovering over the region.
When a mouse enters the region, its cursor will be changed to the
cursor. When the mouse leaves the region, the cursor will be decided
by the region found at the new location.
The cursor defaults to MouseCursor.defer, deferring the choice of
cursor to the next region behind it in hit-test order.
opaque: boolWhether this widget should prevent other MouseRegions visually behind it
from detecting the pointer.
This changes the list of regions that a pointer hovers, thus affecting how
their on_hover, on_enter,
on_exit, and cursor behave.
If opaque is true, this widget will absorb the mouse pointer and
prevent this widget’s siblings (or any other widgets that are not
ancestors or descendants of this widget) from detecting the mouse
pointer even when the pointer is within their areas.
If opaque is false, this object will not affect how MouseRegions
behind it behave, which will detect the mouse pointer as long as the
pointer is within their areas.
This defaults to true.
hit_test_behavior: Option<HitTestBehavior>How to behave during hit testing.
This defaults to HitTestBehavior::Opaque if None.
child: Option<WidgetRef>Implementations§
Source§impl MouseRegion
impl MouseRegion
Sourcepub fn new() -> MouseRegion
pub fn new() -> MouseRegion
Creates a MouseRegion; Dart’s named arguments are the setters.
Sourcepub fn key(self, key: KeyRef) -> MouseRegion
pub fn key(self, key: KeyRef) -> MouseRegion
Dart MouseRegion(key:).
Sourcepub fn on_enter(self, on_enter: PointerEnterEventListener) -> MouseRegion
pub fn on_enter(self, on_enter: PointerEnterEventListener) -> MouseRegion
Dart MouseRegion(on_enter:).
Sourcepub fn on_hover(self, on_hover: PointerHoverEventListener) -> MouseRegion
pub fn on_hover(self, on_hover: PointerHoverEventListener) -> MouseRegion
Dart MouseRegion(on_hover:).
Sourcepub fn on_exit(self, on_exit: PointerExitEventListener) -> MouseRegion
pub fn on_exit(self, on_exit: PointerExitEventListener) -> MouseRegion
Dart MouseRegion(on_exit:).
Sourcepub fn cursor(self, cursor: MouseCursorRef) -> MouseRegion
pub fn cursor(self, cursor: MouseCursorRef) -> MouseRegion
Dart MouseRegion(cursor:).
Sourcepub fn opaque(self, opaque: bool) -> MouseRegion
pub fn opaque(self, opaque: bool) -> MouseRegion
Dart MouseRegion(opaque:).
Sourcepub fn hit_test_behavior(
self,
hit_test_behavior: HitTestBehavior,
) -> MouseRegion
pub fn hit_test_behavior( self, hit_test_behavior: HitTestBehavior, ) -> MouseRegion
Dart MouseRegion(hit_test_behavior:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> MouseRegion
pub fn child<K>(self, child: impl IntoWidget<K>) -> MouseRegion
Dart MouseRegion(child:).
Trait Implementations§
Source§impl Debug for MouseRegion
impl Debug for MouseRegion
Source§impl Default for MouseRegion
impl Default for MouseRegion
Source§fn default() -> MouseRegion
fn default() -> MouseRegion
Source§impl RenderObjectWidget for MouseRegion
impl RenderObjectWidget for MouseRegion
Source§type RenderObject = RenderMouseRegion
type RenderObject = RenderMouseRegion
covariant RenderObject parameter type.Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_render_object(
&self,
app: &mut App,
_context: BuildContext,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, _context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
_context: BuildContext,
render_object: RenderHandle<RenderMouseRegion>,
)
fn update_render_object( &self, app: &mut App, _context: BuildContext, render_object: RenderHandle<RenderMouseRegion>, )
create_render_object. Read moreSource§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
debugVisitOnstageChildren of the element this widget makes, for a widget whose
Dart element subclass overrides it only to hide children (_OffstageElement,
_IndexedStackElement): calls visitor for each of children, in order, that is
onstage. Waft’s generic single- and multi-child elements stand in for those subclasses
and ask their widget here; an element of a widget’s own overrides
Element::debug_visit_onstage_children instead.Source§fn did_unmount_render_object(
&self,
app: &mut App,
render_object: RenderHandle<Self::RenderObject>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.Auto Trait Implementations§
impl !RefUnwindSafe for MouseRegion
impl !Send for MouseRegion
impl !Sync for MouseRegion
impl !UnwindSafe for MouseRegion
impl Forget for MouseRegion
impl Freeze for MouseRegionwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Fn(&mut App, PointerEnterEvent)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, PointerEnterEvent)>>: Freeze,
*const RcInner<dyn Fn(&mut App, PointerHoverEvent)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, PointerHoverEvent)>>: Freeze,
*const RcInner<dyn Fn(&mut App, PointerExitEvent)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, PointerExitEvent)>>: Freeze,
*const RcInner<dyn MouseCursor> is !null: Freeze,
PhantomData<RcInner<dyn MouseCursor>>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for MouseRegion
impl Unpin for MouseRegion
impl UnsafeUnpin for MouseRegionwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, PointerEnterEvent)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, PointerEnterEvent)>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, PointerHoverEvent)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, PointerHoverEvent)>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, PointerExitEvent)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, PointerExitEvent)>>: UnsafeUnpin,
*const RcInner<dyn MouseCursor> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.