mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Properly implement Debug for Window and EventLoop types (#3297)
For EventLoop, EventLoopBuilder, EventLoopProxy and by requiring it as a supertrait of Window and ActiveEventLoop. It is especially useful for user to be able to know that Window is Debug.
This commit is contained in:
@@ -11,6 +11,7 @@ mod window_target;
|
||||
|
||||
pub(crate) use window_target::ActiveEventLoop;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventLoop {
|
||||
elw: ActiveEventLoop,
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ use crate::event_loop::EventLoopProxyProvider;
|
||||
use crate::platform_impl::web::event_loop::runner::WeakShared;
|
||||
use crate::platform_impl::web::r#async::{AtomicWaker, Wrapper};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventLoopProxy(Wrapper<WeakShared, Arc<State>, ()>);
|
||||
|
||||
#[derive(Debug)]
|
||||
struct State {
|
||||
awoken: AtomicBool,
|
||||
waker: AtomicWaker,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::iter;
|
||||
use std::ops::Deref;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::sync::Arc;
|
||||
use std::{fmt, iter};
|
||||
|
||||
use wasm_bindgen::prelude::Closure;
|
||||
use wasm_bindgen::JsCast;
|
||||
@@ -26,6 +26,7 @@ use crate::platform_impl::platform::r#async::DispatchRunner;
|
||||
use crate::platform_impl::platform::window::Inner;
|
||||
use crate::window::WindowId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Shared(Rc<Execution>);
|
||||
|
||||
impl Clone for Shared {
|
||||
@@ -68,6 +69,12 @@ struct Execution {
|
||||
on_visibility_change: OnEventHandle<web_sys::Event>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Execution {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Execution").finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
enum RunnerEnum {
|
||||
/// The `EventLoop` is created but not being run.
|
||||
Pending,
|
||||
@@ -96,6 +103,16 @@ struct Runner {
|
||||
event_loop: ActiveEventLoop,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Runner {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Runner")
|
||||
.field("state", &self.state)
|
||||
.field("app", &"<ApplicationHandler>")
|
||||
.field("event_loop", &self.event_loop)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Runner {
|
||||
pub fn new(app: Box<dyn ApplicationHandler>, event_loop: ActiveEventLoop) -> Self {
|
||||
Runner { state: State::Init, app, event_loop }
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::platform_impl::web::event_loop::proxy::EventLoopProxy;
|
||||
use crate::platform_impl::Window;
|
||||
use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId};
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Debug)]
|
||||
struct ModifiersShared(Rc<Cell<ModifiersState>>);
|
||||
|
||||
impl ModifiersShared {
|
||||
@@ -44,7 +44,7 @@ impl Clone for ModifiersShared {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ActiveEventLoop {
|
||||
pub(crate) runner: runner::Shared,
|
||||
modifiers: ModifiersShared,
|
||||
|
||||
Reference in New Issue
Block a user