-
Notifications
You must be signed in to change notification settings - Fork 750
feat(api): expose MouseCursor and set_mouse_cursor in public API #9330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
eb0131c
067b9b8
79fa874
5928202
6f6401f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,76 +177,6 @@ macro_rules! for_each_enums { | |
Forward, | ||
} | ||
|
||
/// This enum represents different types of mouse cursors. It's a subset of the mouse cursors available in CSS. | ||
/// For details and pictograms see the [MDN Documentation for cursor](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#values). | ||
/// Depending on the backend and used OS unidirectional resize cursors may be replaced with bidirectional ones. | ||
enum MouseCursor { | ||
/// The systems default cursor. | ||
Default, | ||
/// No cursor is displayed. | ||
None, | ||
//context_menu, | ||
/// A cursor indicating help information. | ||
Help, | ||
/// A pointing hand indicating a link. | ||
Pointer, | ||
/// The program is busy but can still be interacted with. | ||
Progress, | ||
/// The program is busy. | ||
Wait, | ||
//cell, | ||
/// A crosshair. | ||
Crosshair, | ||
/// A cursor indicating selectable text. | ||
Text, | ||
//vertical_text, | ||
/// An alias or shortcut is being created. | ||
Alias, | ||
/// A copy is being created. | ||
Copy, | ||
/// Something is to be moved. | ||
Move, | ||
/// Something can't be dropped here. | ||
NoDrop, | ||
/// An action isn't allowed | ||
NotAllowed, | ||
/// Something is grabbable. | ||
Grab, | ||
/// Something is being grabbed. | ||
Grabbing, | ||
//all_scroll, | ||
/// Indicating that a column is resizable horizontally. | ||
ColResize, | ||
/// Indicating that a row is resizable vertically. | ||
RowResize, | ||
/// Unidirectional resize north. | ||
NResize, | ||
/// Unidirectional resize east. | ||
EResize, | ||
/// Unidirectional resize south. | ||
SResize, | ||
/// Unidirectional resize west. | ||
WResize, | ||
/// Unidirectional resize north-east. | ||
NeResize, | ||
/// Unidirectional resize north-west. | ||
NwResize, | ||
/// Unidirectional resize south-east. | ||
SeResize, | ||
/// Unidirectional resize south-west. | ||
SwResize, | ||
/// Bidirectional resize east-west. | ||
EwResize, | ||
/// Bidirectional resize north-south. | ||
NsResize, | ||
/// Bidirectional resize north-east-south-west. | ||
NeswResize, | ||
/// Bidirectional resize north-west-south-east. | ||
NwseResize, | ||
//zoom_in, | ||
//zoom_out, | ||
} | ||
|
||
/// This enum defines how the source image shall fit into an `Image` element. | ||
enum ImageFit { | ||
/// Scales and stretches the source image to fit the width and height of the `Image` element. | ||
|
@@ -491,6 +421,71 @@ macro_rules! for_each_enums { | |
/// This variant is reported when the operating system is none of the above. | ||
Other, | ||
} | ||
|
||
/// This enum represents different types of mouse cursors. It's a subset of the mouse cursors available in CSS. | ||
/// For details and pictograms see the [MDN Documentation for cursor](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#values). | ||
/// Depending on the backend and used OS unidirectional resize cursors may be replaced with bidirectional ones. | ||
#[non_exhaustive] | ||
enum MouseCursor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enum needs to be |
||
/// The system's default cursor. | ||
Default, | ||
/// No cursor is displayed. | ||
None, | ||
/// A cursor indicating help information. | ||
Help, | ||
/// A pointing hand indicating a link. | ||
Pointer, | ||
/// The program is busy but can still be interacted with. | ||
Progress, | ||
/// The program is busy. | ||
Wait, | ||
/// A crosshair. | ||
Crosshair, | ||
/// A cursor indicating selectable text. | ||
Text, | ||
/// An alias or shortcut is being created. | ||
Alias, | ||
/// A copy is being created. | ||
Copy, | ||
/// Something is to be moved. | ||
Move, | ||
/// Something can't be dropped here. | ||
NoDrop, | ||
/// An action isn't allowed. | ||
NotAllowed, | ||
/// Something is grabbable. | ||
Grab, | ||
/// Something is being grabbed. | ||
Grabbing, | ||
/// Indicating that a column is resizable horizontally. | ||
ColResize, | ||
/// Indicating that a row is resizable vertically. | ||
RowResize, | ||
/// Unidirectional resize north. | ||
NResize, | ||
/// Unidirectional resize east. | ||
EResize, | ||
/// Unidirectional resize south. | ||
SResize, | ||
/// Unidirectional resize west. | ||
WResize, | ||
/// Unidirectional resize north-east. | ||
NeResize, | ||
/// Unidirectional resize north-west. | ||
NwResize, | ||
/// Unidirectional resize south-east. | ||
SeResize, | ||
/// Unidirectional resize south-west. | ||
SwResize, | ||
/// Bidirectional resize east-west. | ||
EwResize, | ||
/// Bidirectional resize north-south. | ||
NsResize, | ||
/// Bidirectional resize north-east-south-west. | ||
NeswResize, | ||
/// Bidirectional resize north-west-south-east. | ||
NwseResize, | ||
} | ||
]; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ This module contains types that are public and re-exported in the slint-rs as we | |
pub use crate::future::*; | ||
use crate::graphics::{Rgba8Pixel, SharedPixelBuffer}; | ||
use crate::input::{KeyEventType, MouseEvent}; | ||
pub use crate::items::MouseCursor; | ||
use crate::window::{WindowAdapter, WindowInner}; | ||
use alloc::boxed::Box; | ||
use alloc::string::String; | ||
|
@@ -706,6 +707,11 @@ impl Window { | |
pub fn take_snapshot(&self) -> Result<SharedPixelBuffer<Rgba8Pixel>, PlatformError> { | ||
self.0.window_adapter().renderer().take_snapshot() | ||
} | ||
|
||
/// Sets the mouse cursor for this window. | ||
pub fn set_mouse_cursor(&self, cursor: crate::items::MouseCursor) { | ||
self.0.window_adapter().set_mouse_cursor(cursor); | ||
} | ||
Comment on lines
+711
to
+714
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API shouldn't need to be there. |
||
} | ||
|
||
pub use crate::SharedString; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
// Copyright © SixtyFPS GmbH <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 | ||
|
||
use super::{ | ||
DropEvent, Item, ItemConsts, ItemRc, MouseCursor, PointerEventButton, RenderingResult, | ||
}; | ||
use super::{DropEvent, Item, ItemConsts, ItemRc, PointerEventButton, RenderingResult}; | ||
use crate::input::{ | ||
FocusEvent, FocusEventResult, InputEventFilterResult, InputEventResult, KeyEvent, | ||
KeyEventResult, MouseEvent, | ||
}; | ||
use crate::item_rendering::{CachedRenderingData, ItemRenderer}; | ||
use crate::items::MouseCursor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (a bit inconsistent to have some import through |
||
use crate::layout::{LayoutInfo, Orientation}; | ||
use crate::lengths::{LogicalPoint, LogicalRect, LogicalSize}; | ||
#[cfg(feature = "rtti")] | ||
|
@@ -249,9 +248,7 @@ impl Item for DropArea { | |
let r = Self::FIELD_OFFSETS.can_drop.apply_pin(self).call(&(event.clone(),)); | ||
if r { | ||
self.contains_drag.set(true); | ||
if let Some(window_adapter) = window_adapter.internal(crate::InternalToken) { | ||
window_adapter.set_mouse_cursor(MouseCursor::Copy); | ||
} | ||
window_adapter.set_mouse_cursor(MouseCursor::Copy); | ||
InputEventResult::EventAccepted | ||
} else { | ||
self.contains_drag.set(false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This didn't need to be moved. Makes the patch harder to review.