mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Add Response::contains_pointer (#3859)
* Part of https://github.com/emilk/egui/issues/3841
This commit is contained in:
@@ -212,7 +212,9 @@ impl Response {
|
||||
|
||||
/// The pointer is hovering above this widget or the widget was clicked/tapped this frame.
|
||||
///
|
||||
/// Note that this is slightly different from checking `response.rect.contains(pointer_pos)`.
|
||||
/// This will be `false` whenever some other widget is being dragged.
|
||||
///
|
||||
/// Note that this is slightly different from [`Self::contains_pointer`].
|
||||
/// For one, the hover rectangle is slightly larger, by half of the current item spacing
|
||||
/// (to make it easier to click things). But `hovered` also checks that no other area
|
||||
/// is covering this response rectangle.
|
||||
@@ -221,6 +223,17 @@ impl Response {
|
||||
self.hovered
|
||||
}
|
||||
|
||||
/// Returns true if the pointer is contained by the response rect.
|
||||
///
|
||||
/// In contrast to [`Self::hovered`], this can be `true` even if some other widget is being dragged.
|
||||
/// This means it is useful for styling things like drag-and-drop targets.
|
||||
///
|
||||
/// In contrast to [`Self::hovered`], this is true even when dragging some other widget
|
||||
/// onto this one.
|
||||
pub fn contains_pointer(&self) -> bool {
|
||||
self.ctx.rect_contains_pointer(self.layer_id, self.rect)
|
||||
}
|
||||
|
||||
/// The widget is highlighted via a call to [`Self::highlight`] or [`Context::highlight_widget`].
|
||||
#[doc(hidden)]
|
||||
pub fn highlighted(&self) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user