Make Attach struct public in devtools

This commit is contained in:
Héctor Ramón Jiménez 2025-05-04 22:39:23 +02:00
parent 6bf709e03e
commit fcff94fca3
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -28,15 +28,21 @@ use crate::widget::{
use std::fmt; use std::fmt;
use std::thread; use std::thread;
pub fn attach(program: impl Program + 'static) -> impl Program { pub fn attach<P: Program + 'static>(program: P) -> Attach<P> {
struct Attach<P> { Attach { program }
program: P, }
}
impl<P> Program for Attach<P> /// A [`Program`] with some devtools attached to it.
where #[derive(Debug)]
pub struct Attach<P> {
/// The original [`Program`] managed by these devtools.
pub program: P,
}
impl<P> Program for Attach<P>
where
P: Program + 'static, P: Program + 'static,
{ {
type State = DevTools<P>; type State = DevTools<P>;
type Message = Event<P>; type Message = Event<P>;
type Theme = P::Theme; type Theme = P::Theme;
@ -53,10 +59,7 @@ pub fn attach(program: impl Program + 'static) -> impl Program {
( (
devtools, devtools,
Task::batch([ Task::batch([boot.map(Event::Program), task.map(Event::Message)]),
boot.map(Event::Program),
task.map(Event::Message),
]),
) )
} }
@ -87,31 +90,22 @@ pub fn attach(program: impl Program + 'static) -> impl Program {
state.subscription(&self.program) state.subscription(&self.program)
} }
fn theme( fn theme(&self, state: &Self::State, window: window::Id) -> Self::Theme {
&self,
state: &Self::State,
window: window::Id,
) -> Self::Theme {
state.theme(&self.program, window) state.theme(&self.program, window)
} }
fn style( fn style(&self, state: &Self::State, theme: &Self::Theme) -> theme::Style {
&self,
state: &Self::State,
theme: &Self::Theme,
) -> theme::Style {
state.style(&self.program, theme) state.style(&self.program, theme)
} }
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 { fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
state.scale_factor(&self.program, window) state.scale_factor(&self.program, window)
} }
}
Attach { program }
} }
struct DevTools<P> /// The state of the devtools.
#[allow(missing_debug_implementations)]
pub struct DevTools<P>
where where
P: Program, P: Program,
{ {
@ -122,7 +116,7 @@ where
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Message { pub enum Message {
HideNotification, HideNotification,
ToggleComet, ToggleComet,
CometLaunched(comet::launch::Result), CometLaunched(comet::launch::Result),
@ -403,7 +397,7 @@ where
} }
} }
enum Event<P> pub enum Event<P>
where where
P: Program, P: Program,
{ {