mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-26 03:36:32 +11:00
Use consistent return types for available_monitors() (#1207)
* [#1111] Use consistent return types for available_monitors() Always use `impl Iterator<Item = MonitorHandle>` instead of `AvailableMonitorsIter`. Fix an example that used the Debug implementation of `AvailableMonitorsIter`. * [#1111] Update changelog * [#1111] Remove AvailableMonitorsIter type completely * [#1111] Remove doc references to AvailableMonitorsIter
This commit is contained in:
parent
4f6ca8792c
commit
55640a91ae
5 changed files with 15 additions and 50 deletions
|
@ -24,6 +24,7 @@
|
||||||
- On Wayland, fixed DeviceEvents for relative mouse movement is not always produced.
|
- On Wayland, fixed DeviceEvents for relative mouse movement is not always produced.
|
||||||
- Removed `derivative` crate dependency.
|
- Removed `derivative` crate dependency.
|
||||||
- On Wayland, add support for set_cursor_icon.
|
- On Wayland, add support for set_cursor_icon.
|
||||||
|
- Use `impl Iterator<Item = MonitorHandle>` instead of `AvailableMonitorsIter` consistently.
|
||||||
|
|
||||||
# 0.20.0 Alpha 3 (2019-08-14)
|
# 0.20.0 Alpha 3 (2019-08-14)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,6 @@ fn main() {
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||||
|
|
||||||
dbg!(window.available_monitors());
|
dbg!(window.available_monitors().collect::<Vec<_>>());
|
||||||
dbg!(window.primary_monitor());
|
dbg!(window.primary_monitor());
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,7 @@
|
||||||
//! [send_event]: ./struct.EventLoopProxy.html#method.send_event
|
//! [send_event]: ./struct.EventLoopProxy.html#method.send_event
|
||||||
use std::{error, fmt, ops::Deref, time::Instant};
|
use std::{error, fmt, ops::Deref, time::Instant};
|
||||||
|
|
||||||
use crate::{
|
use crate::{event::Event, monitor::MonitorHandle, platform_impl};
|
||||||
event::Event,
|
|
||||||
monitor::{AvailableMonitorsIter, MonitorHandle},
|
|
||||||
platform_impl,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Provides a way to retrieve events from the system and from the windows that were registered to
|
/// Provides a way to retrieve events from the system and from the windows that were registered to
|
||||||
/// the events loop.
|
/// the events loop.
|
||||||
|
@ -150,10 +146,10 @@ impl<T> EventLoop<T> {
|
||||||
/// Returns the list of all the monitors available on the system.
|
/// Returns the list of all the monitors available on the system.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
|
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
|
||||||
let data = self.event_loop.available_monitors();
|
self.event_loop
|
||||||
AvailableMonitorsIter {
|
.available_monitors()
|
||||||
data: data.into_iter(),
|
.into_iter()
|
||||||
}
|
.map(|inner| MonitorHandle { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the primary monitor of the system.
|
/// Returns the primary monitor of the system.
|
||||||
|
|
|
@ -1,51 +1,19 @@
|
||||||
//! Types useful for interacting with a user's monitors.
|
//! Types useful for interacting with a user's monitors.
|
||||||
//!
|
//!
|
||||||
//! If you want to get basic information about a monitor, you can use the [`MonitorHandle`][monitor_id]
|
//! If you want to get basic information about a monitor, you can use the [`MonitorHandle`][monitor_id]
|
||||||
//! type. This is retreived from an [`AvailableMonitorsIter`][monitor_iter], which can be acquired
|
//! type. This is retreived from one of the following methods, which return an iterator of
|
||||||
//! with:
|
//! [`MonitorHandle`][monitor_id]:
|
||||||
//! - [`EventLoop::available_monitors`][loop_get]
|
//! - [`EventLoop::available_monitors`][loop_get]
|
||||||
//! - [`Window::available_monitors`][window_get].
|
//! - [`Window::available_monitors`][window_get].
|
||||||
//!
|
//!
|
||||||
//! [monitor_id]: ./struct.MonitorHandle.html
|
//! [monitor_id]: ./struct.MonitorHandle.html
|
||||||
//! [monitor_iter]: ./struct.AvailableMonitorsIter.html
|
|
||||||
//! [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors
|
//! [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors
|
||||||
//! [window_get]: ../window/struct.Window.html#method.available_monitors
|
//! [window_get]: ../window/struct.Window.html#method.available_monitors
|
||||||
use std::collections::vec_deque::IntoIter as VecDequeIter;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dpi::{PhysicalPosition, PhysicalSize},
|
dpi::{PhysicalPosition, PhysicalSize},
|
||||||
platform_impl,
|
platform_impl,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An iterator over all available monitors.
|
|
||||||
///
|
|
||||||
/// Can be acquired with:
|
|
||||||
/// - [`EventLoop::available_monitors`][loop_get]
|
|
||||||
/// - [`Window::available_monitors`][window_get].
|
|
||||||
///
|
|
||||||
/// [loop_get]: ../event_loop/struct.EventLoop.html#method.available_monitors
|
|
||||||
/// [window_get]: ../window/struct.Window.html#method.available_monitors
|
|
||||||
// Implementation note: we retrieve the list once, then serve each element by one by one.
|
|
||||||
// This may change in the future.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AvailableMonitorsIter {
|
|
||||||
pub(crate) data: VecDequeIter<platform_impl::MonitorHandle>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for AvailableMonitorsIter {
|
|
||||||
type Item = MonitorHandle;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<MonitorHandle> {
|
|
||||||
self.data.next().map(|id| MonitorHandle { inner: id })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.data.size_hint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Describes a fullscreen video mode of a monitor.
|
/// Describes a fullscreen video mode of a monitor.
|
||||||
///
|
///
|
||||||
/// Can be acquired with:
|
/// Can be acquired with:
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
dpi::{LogicalPosition, LogicalSize},
|
dpi::{LogicalPosition, LogicalSize},
|
||||||
error::{ExternalError, NotSupportedError, OsError},
|
error::{ExternalError, NotSupportedError, OsError},
|
||||||
event_loop::EventLoopWindowTarget,
|
event_loop::EventLoopWindowTarget,
|
||||||
monitor::{AvailableMonitorsIter, MonitorHandle, VideoMode},
|
monitor::{MonitorHandle, VideoMode},
|
||||||
platform_impl,
|
platform_impl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -703,11 +703,11 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// **iOS:** Can only be called on the main thread.
|
/// **iOS:** Can only be called on the main thread.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn available_monitors(&self) -> AvailableMonitorsIter {
|
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
|
||||||
let data = self.window.available_monitors();
|
self.window
|
||||||
AvailableMonitorsIter {
|
.available_monitors()
|
||||||
data: data.into_iter(),
|
.into_iter()
|
||||||
}
|
.map(|inner| MonitorHandle { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the primary monitor of the system.
|
/// Returns the primary monitor of the system.
|
||||||
|
|
Loading…
Add table
Reference in a new issue