Merge branch 'master' into explore-input-method2
This commit is contained in:
commit
50eaef2844
5 changed files with 68 additions and 24 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
use crate::{Point, Rectangle, Transformation, Vector};
|
use crate::{Point, Rectangle, Transformation, Vector};
|
||||||
|
|
||||||
use std::ops::Mul;
|
|
||||||
|
|
||||||
/// The mouse cursor state.
|
/// The mouse cursor state.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||||
pub enum Cursor {
|
pub enum Cursor {
|
||||||
/// The cursor has a defined position.
|
/// The cursor has a defined position.
|
||||||
Available(Point),
|
Available(Point),
|
||||||
|
|
||||||
|
/// The cursor has a defined position, but it's levitating over a layer above.
|
||||||
|
Levitating(Point),
|
||||||
|
|
||||||
/// The cursor is currently unavailable (i.e. out of bounds or busy).
|
/// The cursor is currently unavailable (i.e. out of bounds or busy).
|
||||||
#[default]
|
#[default]
|
||||||
Unavailable,
|
Unavailable,
|
||||||
|
|
@ -18,7 +19,7 @@ impl Cursor {
|
||||||
pub fn position(self) -> Option<Point> {
|
pub fn position(self) -> Option<Point> {
|
||||||
match self {
|
match self {
|
||||||
Cursor::Available(position) => Some(position),
|
Cursor::Available(position) => Some(position),
|
||||||
Cursor::Unavailable => None,
|
Cursor::Levitating(_) | Cursor::Unavailable => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,17 +52,41 @@ impl Cursor {
|
||||||
pub fn is_over(self, bounds: Rectangle) -> bool {
|
pub fn is_over(self, bounds: Rectangle) -> bool {
|
||||||
self.position_over(bounds).is_some()
|
self.position_over(bounds).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the [`Cursor`] is levitating over a layer above.
|
||||||
|
pub fn is_levitating(self) -> bool {
|
||||||
|
matches!(self, Self::Levitating(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Makes the [`Cursor`] levitate over a layer above.
|
||||||
|
pub fn levitate(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Available(position) => Self::Levitating(position),
|
||||||
|
_ => self,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Brings the [`Cursor`] back to the current layer.
|
||||||
|
pub fn land(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Cursor::Levitating(position) => Cursor::Available(position),
|
||||||
|
_ => self,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mul<Transformation> for Cursor {
|
impl std::ops::Mul<Transformation> for Cursor {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, transformation: Transformation) -> Self {
|
fn mul(self, transformation: Transformation) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Cursor::Unavailable => Cursor::Unavailable,
|
Self::Available(position) => {
|
||||||
Cursor::Available(point) => {
|
Self::Available(position * transformation)
|
||||||
Cursor::Available(point * transformation)
|
|
||||||
}
|
}
|
||||||
|
Self::Levitating(position) => {
|
||||||
|
Self::Levitating(position * transformation)
|
||||||
|
}
|
||||||
|
Self::Unavailable => Self::Unavailable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,18 @@ impl<'a, Message> Shell<'a, Message> {
|
||||||
self.redraw_request
|
self.redraw_request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replaces the redraw request of the [`Shell`]; without conflict resolution.
|
||||||
|
///
|
||||||
|
/// This is useful if you want to overwrite the redraw request to a previous value.
|
||||||
|
/// Since it's a fairly advanced use case and should rarely be used, it is a static
|
||||||
|
/// method.
|
||||||
|
pub fn replace_redraw_request(
|
||||||
|
shell: &mut Self,
|
||||||
|
redraw_request: window::RedrawRequest,
|
||||||
|
) {
|
||||||
|
shell.redraw_request = redraw_request;
|
||||||
|
}
|
||||||
|
|
||||||
/// Requests the current [`InputMethod`] strategy.
|
/// Requests the current [`InputMethod`] strategy.
|
||||||
///
|
///
|
||||||
/// __Important__: This request will only be honored by the
|
/// __Important__: This request will only be honored by the
|
||||||
|
|
|
||||||
|
|
@ -871,16 +871,19 @@ where
|
||||||
shell.request_redraw();
|
shell.request_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let is_visible =
|
||||||
|
is_hovered || self.is_top_focused || self.is_top_overlay_active;
|
||||||
|
|
||||||
if matches!(
|
if matches!(
|
||||||
event,
|
event,
|
||||||
Event::Mouse(
|
Event::Mouse(
|
||||||
mouse::Event::CursorMoved { .. }
|
mouse::Event::CursorMoved { .. }
|
||||||
| mouse::Event::ButtonReleased(_)
|
| mouse::Event::ButtonReleased(_)
|
||||||
)
|
)
|
||||||
) || is_hovered
|
) || is_visible
|
||||||
|| self.is_top_focused
|
|
||||||
|| self.is_top_overlay_active
|
|
||||||
{
|
{
|
||||||
|
let redraw_request = shell.redraw_request();
|
||||||
|
|
||||||
self.top.as_widget_mut().update(
|
self.top.as_widget_mut().update(
|
||||||
top_tree,
|
top_tree,
|
||||||
event.clone(),
|
event.clone(),
|
||||||
|
|
@ -891,6 +894,11 @@ where
|
||||||
shell,
|
shell,
|
||||||
viewport,
|
viewport,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ignore redraw requests of invisible content
|
||||||
|
if !is_visible {
|
||||||
|
Shell::replace_redraw_request(shell, redraw_request);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if shell.is_event_captured() {
|
if shell.is_event_captured() {
|
||||||
|
|
|
||||||
|
|
@ -564,7 +564,8 @@ where
|
||||||
Event::Mouse(mouse::Event::CursorMoved { .. })
|
Event::Mouse(mouse::Event::CursorMoved { .. })
|
||||||
| Event::Touch(touch::Event::FingerMoved { .. }) => {
|
| Event::Touch(touch::Event::FingerMoved { .. }) => {
|
||||||
if let Some(scrollbar) = scrollbars.y {
|
if let Some(scrollbar) = scrollbars.y {
|
||||||
let Some(cursor_position) = cursor.position()
|
let Some(cursor_position) =
|
||||||
|
cursor.land().position()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -636,7 +637,8 @@ where
|
||||||
match event {
|
match event {
|
||||||
Event::Mouse(mouse::Event::CursorMoved { .. })
|
Event::Mouse(mouse::Event::CursorMoved { .. })
|
||||||
| Event::Touch(touch::Event::FingerMoved { .. }) => {
|
| Event::Touch(touch::Event::FingerMoved { .. }) => {
|
||||||
let Some(cursor_position) = cursor.position() else {
|
let Some(cursor_position) = cursor.land().position()
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,15 +216,15 @@ where
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
let is_over = cursor.is_over(layout.bounds());
|
let is_over = cursor.is_over(layout.bounds());
|
||||||
let is_mouse_movement =
|
let end = self.children.len() - 1;
|
||||||
matches!(event, Event::Mouse(mouse::Event::CursorMoved { .. }));
|
|
||||||
|
|
||||||
for ((child, state), layout) in self
|
for (i, ((child, state), layout)) in self
|
||||||
.children
|
.children
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.rev()
|
.rev()
|
||||||
.zip(tree.children.iter_mut().rev())
|
.zip(tree.children.iter_mut().rev())
|
||||||
.zip(layout.children().rev())
|
.zip(layout.children().rev())
|
||||||
|
.enumerate()
|
||||||
{
|
{
|
||||||
child.as_widget_mut().update(
|
child.as_widget_mut().update(
|
||||||
state,
|
state,
|
||||||
|
|
@ -237,22 +237,19 @@ where
|
||||||
viewport,
|
viewport,
|
||||||
);
|
);
|
||||||
|
|
||||||
if is_over
|
if shell.is_event_captured() {
|
||||||
&& !is_mouse_movement
|
return;
|
||||||
&& cursor != mouse::Cursor::Unavailable
|
}
|
||||||
{
|
|
||||||
|
if i < end && is_over && !cursor.is_levitating() {
|
||||||
let interaction = child.as_widget().mouse_interaction(
|
let interaction = child.as_widget().mouse_interaction(
|
||||||
state, layout, cursor, viewport, renderer,
|
state, layout, cursor, viewport, renderer,
|
||||||
);
|
);
|
||||||
|
|
||||||
if interaction != mouse::Interaction::None {
|
if interaction != mouse::Interaction::None {
|
||||||
cursor = mouse::Cursor::Unavailable;
|
cursor = cursor.levitate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if shell.is_event_captured() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue