Skip to content

Commit

Permalink
Replace EventLoopWindowTarget with ActiveEventLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 15, 2024
1 parent 16d8607 commit 56f0112
Show file tree
Hide file tree
Showing 34 changed files with 475 additions and 372 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Unreleased` header.

# Unreleased

- **Breaking:** Removed unnecessary generic parameter `T` from `EventLoopWindowTarget`.
- **Breaking:** Removed `EventLoopWindowTarget<T>`, and replaced it with `ActiveEventLoop<'app>`, which allows Winit to clearly define a boundary between what is possible when the application is not running, and when it is.
- Added `MaybeActiveEventLoop<'app>` trait to help be generic over `EventLoop<T>` and `ActiveEventLoop<'app>`.
- Added `ActiveEventLoopExtWayland` and `ActiveEventLoopExtX11` to mimic the similar traits on the `EventLoop`.
- On Windows, macOS, X11, Wayland and Web, implement setting images as cursors. See the `custom_cursors.rs` example.
- **Breaking:** Remove `Window::set_cursor_icon`
- Add `WindowBuilder::with_cursor` and `Window::set_cursor` which takes a `CursorIcon` or `CustomCursor`
Expand Down
4 changes: 2 additions & 2 deletions examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ fn main() -> Result<(), impl std::error::Error> {
use winit::{
dpi::{LogicalPosition, LogicalSize, Position},
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{EventLoop, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoop},
raw_window_handle::HasRawWindowHandle,
window::{Window, WindowBuilder, WindowId},
};

fn spawn_child_window(
parent: &Window,
event_loop: &EventLoopWindowTarget,
event_loop: ActiveEventLoop<'_>,
windows: &mut HashMap<WindowId, Window>,
) {
let parent = parent.raw_window_handle().unwrap();
Expand Down
7 changes: 3 additions & 4 deletions examples/custom_cursors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use simple_logger::SimpleLogger;
use winit::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{EventLoop, EventLoopWindowTarget},
event_loop::EventLoop,
keyboard::Key,
window::{CursorIcon, CustomCursor, WindowBuilder},
};
Expand All @@ -18,14 +18,13 @@ use {
#[cfg(web_platform)]
static COUNTER: AtomicU64 = AtomicU64::new(0);

fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomCursor {
fn decode_cursor(bytes: &[u8], event_loop: &EventLoop<()>) -> CustomCursor {
let img = image::load_from_memory(bytes).unwrap().to_rgba8();
let samples = img.into_flat_samples();
let (_, w, h) = samples.extents();
let (w, h) = (w as u16, h as u16);
let builder = CustomCursor::from_rgba(samples.samples, w, h, w / 2, h / 2).unwrap();

builder.build(window_target)
builder.build(event_loop)
}

#[cfg(not(web_platform))]
Expand Down
10 changes: 5 additions & 5 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{error::Error, hash::Hash};

use cursor_icon::CursorIcon;

use crate::event_loop::EventLoopWindowTarget;
use crate::event_loop::MaybeActiveEventLoop;
use crate::platform_impl::{self, PlatformCustomCursor, PlatformCustomCursorBuilder};

/// The maximum width and height for a cursor when using [`CustomCursor::from_rgba`].
Expand Down Expand Up @@ -111,9 +111,9 @@ pub struct CustomCursorBuilder {
}

impl CustomCursorBuilder {
pub fn build(self, window_target: &EventLoopWindowTarget) -> CustomCursor {
pub fn build<'a>(self, mut event_loop: impl MaybeActiveEventLoop<'a>) -> CustomCursor {
CustomCursor {
inner: PlatformCustomCursor::build(self.inner, &window_target.p),
inner: PlatformCustomCursor::build(self.inner, event_loop.__inner()),
}
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ impl Eq for OnlyCursorImage {}

#[allow(dead_code)]
impl OnlyCursorImage {
fn build(builder: OnlyCursorImageBuilder, _: &platform_impl::EventLoopWindowTarget) -> Self {
fn build(builder: OnlyCursorImageBuilder, _: platform_impl::ActiveEventLoop<'_>) -> Self {
Self(Arc::new(builder.0))
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl NoCustomCursor {
Ok(Self)
}

fn build(self, _: &platform_impl::EventLoopWindowTarget) -> NoCustomCursor {
fn build(self, _: platform_impl::ActiveEventLoop<'_>) -> NoCustomCursor {
self
}
}
Loading

0 comments on commit 56f0112

Please sign in to comment.