mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Deprecate window creation with stale event loop
Creating window when event loop is not running generally doesn't work, since a bunch of events and sync OS requests can't be processed. This is also an issue on e.g. Android, since window can't be created outside event loop easily. Thus deprecate the window creation when event loop is not running, as well as other resource creation to running event loop. Given that all the examples use the bad pattern of creating the window when event loop is not running and also most example existence is questionable, since they show single thing and the majority of their code is window/event loop initialization, they wore merged into a single example 'window.rs' example that showcases very simple application using winit. Fixes #3399.
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::window::{
|
||||
|
||||
use super::main_thread::{MainThreadMarker, MainThreadSafe};
|
||||
use super::r#async::Dispatcher;
|
||||
use super::{backend, monitor::MonitorHandle, EventLoopWindowTarget, Fullscreen};
|
||||
use super::{backend, monitor::MonitorHandle, ActiveEventLoop, Fullscreen};
|
||||
use web_sys::HtmlCanvasElement;
|
||||
|
||||
use std::cell::RefCell;
|
||||
@@ -29,7 +29,7 @@ pub struct Inner {
|
||||
|
||||
impl Window {
|
||||
pub(crate) fn new(
|
||||
target: &EventLoopWindowTarget,
|
||||
target: &ActiveEventLoop,
|
||||
mut attr: WindowAttributes,
|
||||
) -> Result<Self, RootOE> {
|
||||
let id = target.generate_id();
|
||||
@@ -466,14 +466,14 @@ impl From<u64> for WindowId {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub struct PlatformSpecificWindowAttributes {
|
||||
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,
|
||||
pub(crate) prevent_default: bool,
|
||||
pub(crate) focusable: bool,
|
||||
pub(crate) append: bool,
|
||||
}
|
||||
|
||||
impl PlatformSpecificWindowBuilderAttributes {
|
||||
impl PlatformSpecificWindowAttributes {
|
||||
pub(crate) fn set_canvas(&mut self, canvas: Option<backend::RawCanvasType>) {
|
||||
let Some(canvas) = canvas else {
|
||||
self.canvas = None;
|
||||
@@ -487,7 +487,7 @@ impl PlatformSpecificWindowBuilderAttributes {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||
impl Default for PlatformSpecificWindowAttributes {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
canvas: None,
|
||||
|
||||
Reference in New Issue
Block a user