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:
Mads Marquart
2025-03-03 08:40:04 +01:00
committed by GitHub
parent 39c0862198
commit be1baf164c
43 changed files with 152 additions and 42 deletions

View File

@@ -11,6 +11,7 @@ mod window_target;
pub(crate) use window_target::ActiveEventLoop;
#[derive(Debug)]
pub struct EventLoop {
elw: ActiveEventLoop,
}

View File

@@ -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,

View File

@@ -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 }

View File

@@ -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,