Initialize debug with proper Program name

This commit is contained in:
Héctor Ramón Jiménez 2025-03-05 11:52:05 +01:00
parent f618382a0d
commit a106f7f837
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 24 additions and 0 deletions

View file

@ -110,6 +110,10 @@ pub trait Program: Sized {
type Flags = (P, I); type Flags = (P, I);
type Executor = P::Executor; type Executor = P::Executor;
fn name() -> &'static str {
std::any::type_name::<P::State>()
}
fn new( fn new(
(program, initialize): Self::Flags, (program, initialize): Self::Flags,
) -> (Self, Task<Self::Message>) { ) -> (Self, Task<Self::Message>) {

View file

@ -6,6 +6,7 @@ pub use state::State;
use crate::conversion; use crate::conversion;
use crate::core; use crate::core;
use crate::core::keyboard;
use crate::core::mouse; use crate::core::mouse;
use crate::core::renderer; use crate::core::renderer;
use crate::core::theme; use crate::core::theme;
@ -69,6 +70,9 @@ where
/// The data needed to initialize your [`Program`]. /// The data needed to initialize your [`Program`].
type Flags; type Flags;
/// Returns the unique name of the [`Program`].
fn name() -> &'static str;
/// Initializes the [`Program`] with the flags provided to /// Initializes the [`Program`] with the flags provided to
/// [`run`] as part of the [`Settings`]. /// [`run`] as part of the [`Settings`].
/// ///
@ -154,6 +158,8 @@ where
{ {
use winit::event_loop::EventLoop; use winit::event_loop::EventLoop;
debug::init(P::name());
let boot_span = debug::boot(); let boot_span = debug::boot();
let event_loop = EventLoop::with_user_event() let event_loop = EventLoop::with_user_event()
@ -973,6 +979,20 @@ async fn run_instance<P, C>(
window.state.scale_factor(), window.state.scale_factor(),
window.state.modifiers(), window.state.modifiers(),
) { ) {
if matches!(
event,
core::Event::Keyboard(
keyboard::Event::KeyPressed {
modified_key: keyboard::Key::Named(
keyboard::key::Named::F12
),
..
}
)
) {
debug::toggle_comet();
}
events.push((id, event)); events.push((id, event));
} }
} }