Remove now redundant Overlay::is_over
The `mouse_interaction` method can be properly used now to encode hover status with the `None` and `Idle` variants.
This commit is contained in:
parent
a01beefa84
commit
9e934fe2a7
15 changed files with 92 additions and 256 deletions
|
|
@ -10,7 +10,7 @@ use crate::mouse;
|
|||
use crate::renderer;
|
||||
use crate::widget;
|
||||
use crate::widget::Tree;
|
||||
use crate::{Clipboard, Event, Layout, Point, Rectangle, Shell, Size, Vector};
|
||||
use crate::{Clipboard, Event, Layout, Rectangle, Shell, Size, Vector};
|
||||
|
||||
/// An interactive component that can be displayed on top of other widgets.
|
||||
pub trait Overlay<Message, Theme, Renderer>
|
||||
|
|
@ -69,30 +69,16 @@ where
|
|||
|
||||
/// Returns the current [`mouse::Interaction`] of the [`Overlay`].
|
||||
///
|
||||
/// By default, it returns [`mouse::Interaction::Idle`].
|
||||
/// By default, it returns [`mouse::Interaction::None`].
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
_layout: Layout<'_>,
|
||||
_cursor: mouse::Cursor,
|
||||
_viewport: &Rectangle,
|
||||
_renderer: &Renderer,
|
||||
) -> mouse::Interaction {
|
||||
mouse::Interaction::None
|
||||
}
|
||||
|
||||
/// Returns true if the cursor is over the [`Overlay`].
|
||||
///
|
||||
/// By default, it returns true if the bounds of the `layout` contain
|
||||
/// the `cursor_position`.
|
||||
fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
layout.bounds().contains(cursor_position)
|
||||
}
|
||||
|
||||
/// Returns the nested overlay of the [`Overlay`], if there is any.
|
||||
fn overlay<'a>(
|
||||
&'a mut self,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::layout;
|
|||
use crate::mouse;
|
||||
use crate::renderer;
|
||||
use crate::widget;
|
||||
use crate::{Clipboard, Event, Layout, Point, Rectangle, Shell, Size};
|
||||
use crate::{Clipboard, Event, Layout, Shell, Size};
|
||||
|
||||
/// A generic [`Overlay`].
|
||||
#[allow(missing_debug_implementations)]
|
||||
|
|
@ -112,11 +112,9 @@ where
|
|||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
viewport: &Rectangle,
|
||||
renderer: &Renderer,
|
||||
) -> mouse::Interaction {
|
||||
self.content
|
||||
.mouse_interaction(layout, cursor, viewport, renderer)
|
||||
self.content.mouse_interaction(layout, cursor, renderer)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -130,15 +128,6 @@ where
|
|||
self.content.draw(renderer, theme, style, layout, cursor);
|
||||
}
|
||||
|
||||
fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.content.is_over(layout, renderer, cursor_position)
|
||||
}
|
||||
|
||||
fn overlay<'a>(
|
||||
&'a mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::mouse;
|
|||
use crate::overlay;
|
||||
use crate::renderer;
|
||||
use crate::widget;
|
||||
use crate::{Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size};
|
||||
use crate::{Clipboard, Event, Layout, Overlay, Shell, Size};
|
||||
|
||||
/// An [`Overlay`] container that displays multiple overlay [`overlay::Element`]
|
||||
/// children.
|
||||
|
|
@ -107,7 +107,6 @@ where
|
|||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor: mouse::Cursor,
|
||||
viewport: &Rectangle,
|
||||
renderer: &Renderer,
|
||||
) -> mouse::Interaction {
|
||||
self.children
|
||||
|
|
@ -116,7 +115,7 @@ where
|
|||
.map(|(child, layout)| {
|
||||
child
|
||||
.as_overlay()
|
||||
.mouse_interaction(layout, cursor, viewport, renderer)
|
||||
.mouse_interaction(layout, cursor, renderer)
|
||||
})
|
||||
.max()
|
||||
.unwrap_or_default()
|
||||
|
|
@ -137,22 +136,6 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.children
|
||||
.iter()
|
||||
.zip(layout.children())
|
||||
.any(|(child, layout)| {
|
||||
child
|
||||
.as_overlay()
|
||||
.is_over(layout, renderer, cursor_position)
|
||||
})
|
||||
}
|
||||
|
||||
fn overlay<'a>(
|
||||
&'a mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue