Add WindowBuilder::with_cursor() (#3319)
This commit is contained in:
parent
f5c691467b
commit
ba654bb61e
7 changed files with 26 additions and 1 deletions
|
|
@ -13,7 +13,7 @@ Unreleased` header.
|
||||||
|
|
||||||
- On Windows, macOS, X11, Wayland and Web, implement setting images as cursors. See the `custom_cursors.rs` example.
|
- On Windows, macOS, X11, Wayland and Web, implement setting images as cursors. See the `custom_cursors.rs` example.
|
||||||
- **Breaking:** Remove `Window::set_cursor_icon`
|
- **Breaking:** Remove `Window::set_cursor_icon`
|
||||||
- Add `Window::set_cursor` which takes a `CursorIcon` or `CustomCursor`
|
- Add `WindowBuilder::with_cursor` and `Window::set_cursor` which takes a `CursorIcon` or `CustomCursor`
|
||||||
- Add `CustomCursor`
|
- Add `CustomCursor`
|
||||||
- Add `CustomCursor::from_rgba` to allow creating cursor images from RGBA data.
|
- Add `CustomCursor::from_rgba` to allow creating cursor images from RGBA data.
|
||||||
- Add `CustomCursorExtWebSys::from_url` to allow loading cursor images from URLs.
|
- Add `CustomCursorExtWebSys::from_url` to allow loading cursor images from URLs.
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,11 @@ impl Window {
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
match attributes.cursor {
|
||||||
|
Cursor::Icon(icon) => window_state.set_cursor(icon),
|
||||||
|
Cursor::Custom(cursor) => window_state.set_custom_cursor(&cursor.inner.0),
|
||||||
|
}
|
||||||
|
|
||||||
// Activate the window when the token is passed.
|
// Activate the window when the token is passed.
|
||||||
if let (Some(xdg_activation), Some(token)) = (
|
if let (Some(xdg_activation), Some(token)) = (
|
||||||
xdg_activation.as_ref(),
|
xdg_activation.as_ref(),
|
||||||
|
|
|
||||||
|
|
@ -575,6 +575,8 @@ impl UnownedWindow {
|
||||||
leap!(window.set_window_level_inner(window_attrs.window_level)).ignore_error();
|
leap!(window.set_window_level_inner(window_attrs.window_level)).ignore_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.set_cursor(window_attrs.cursor);
|
||||||
|
|
||||||
// Remove the startup notification if we have one.
|
// Remove the startup notification if we have one.
|
||||||
if let Some(startup) = pl_attribs.activation_token.as_ref() {
|
if let Some(startup) = pl_attribs.activation_token.as_ref() {
|
||||||
leap!(xconn.remove_activation_token(xwindow, &startup._token));
|
leap!(xconn.remove_activation_token(xwindow, &startup._token));
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,8 @@ impl WinitWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.set_cursor(attrs.cursor);
|
||||||
|
|
||||||
let delegate = WinitWindowDelegate::new(&this, attrs.fullscreen.0.is_some());
|
let delegate = WinitWindowDelegate::new(&this, attrs.fullscreen.0.is_some());
|
||||||
|
|
||||||
// XXX Send `Focused(false)` right after creating the window delegate, so we won't
|
// XXX Send `Focused(false)` right after creating the window delegate, so we won't
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ impl Window {
|
||||||
inner.set_maximized(attr.maximized);
|
inner.set_maximized(attr.maximized);
|
||||||
inner.set_visible(attr.visible);
|
inner.set_visible(attr.visible);
|
||||||
inner.set_window_icon(attr.window_icon);
|
inner.set_window_icon(attr.window_icon);
|
||||||
|
inner.set_cursor(attr.cursor);
|
||||||
|
|
||||||
let canvas = Rc::downgrade(&inner.canvas);
|
let canvas = Rc::downgrade(&inner.canvas);
|
||||||
let (dispatcher, runner) = Dispatcher::new(target.runner.main_thread(), inner).unwrap();
|
let (dispatcher, runner) = Dispatcher::new(target.runner.main_thread(), inner).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -1225,6 +1225,8 @@ impl<'a, T: 'static> InitData<'a, T> {
|
||||||
win.set_content_protected(true);
|
win.set_content_protected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
win.set_cursor(attributes.cursor);
|
||||||
|
|
||||||
// Set visible before setting the size to ensure the
|
// Set visible before setting the size to ensure the
|
||||||
// attribute is correctly applied.
|
// attribute is correctly applied.
|
||||||
win.set_visible(attributes.visible);
|
win.set_visible(attributes.visible);
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ pub struct WindowAttributes {
|
||||||
pub content_protected: bool,
|
pub content_protected: bool,
|
||||||
pub window_level: WindowLevel,
|
pub window_level: WindowLevel,
|
||||||
pub active: bool,
|
pub active: bool,
|
||||||
|
pub cursor: Cursor,
|
||||||
#[cfg(feature = "rwh_06")]
|
#[cfg(feature = "rwh_06")]
|
||||||
pub(crate) parent_window: SendSyncWrapper<Option<rwh_06::RawWindowHandle>>,
|
pub(crate) parent_window: SendSyncWrapper<Option<rwh_06::RawWindowHandle>>,
|
||||||
pub(crate) fullscreen: SendSyncWrapper<Option<Fullscreen>>,
|
pub(crate) fullscreen: SendSyncWrapper<Option<Fullscreen>>,
|
||||||
|
|
@ -182,6 +183,7 @@ impl Default for WindowAttributes {
|
||||||
preferred_theme: None,
|
preferred_theme: None,
|
||||||
resize_increments: None,
|
resize_increments: None,
|
||||||
content_protected: false,
|
content_protected: false,
|
||||||
|
cursor: Cursor::default(),
|
||||||
#[cfg(feature = "rwh_06")]
|
#[cfg(feature = "rwh_06")]
|
||||||
parent_window: SendSyncWrapper(None),
|
parent_window: SendSyncWrapper(None),
|
||||||
active: true,
|
active: true,
|
||||||
|
|
@ -474,6 +476,17 @@ impl WindowBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Modifies the cursor icon of the window.
|
||||||
|
///
|
||||||
|
/// The default is [`CursorIcon::Default`].
|
||||||
|
///
|
||||||
|
/// See [`Window::set_cursor()`] for more details.
|
||||||
|
#[inline]
|
||||||
|
pub fn with_cursor(mut self, cursor: impl Into<Cursor>) -> Self {
|
||||||
|
self.window.cursor = cursor.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Build window with parent window.
|
/// Build window with parent window.
|
||||||
///
|
///
|
||||||
/// The default is `None`.
|
/// The default is `None`.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue