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::thread;
pub fn attach(program: impl Program + 'static) -> impl Program {
struct Attach<P> {
program: P,
}
pub fn attach<P: Program + 'static>(program: P) -> Attach<P> {
Attach { program }
}
impl<P> Program for Attach<P>
where
/// A [`Program`] with some devtools attached to it.
#[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,
{
{
type State = DevTools<P>;
type Message = Event<P>;
type Theme = P::Theme;
@ -53,10 +59,7 @@ pub fn attach(program: impl Program + 'static) -> impl Program {
(
devtools,
Task::batch([
boot.map(Event::Program),
task.map(Event::Message),
]),
Task::batch([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)
}
fn theme(
&self,
state: &Self::State,
window: window::Id,
) -> Self::Theme {
fn theme(&self, state: &Self::State, window: window::Id) -> Self::Theme {
state.theme(&self.program, window)
}
fn style(
&self,
state: &Self::State,
theme: &Self::Theme,
) -> theme::Style {
fn style(&self, state: &Self::State, theme: &Self::Theme) -> theme::Style {
state.style(&self.program, theme)
}
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
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
P: Program,
{
@ -122,7 +116,7 @@ where
}
#[derive(Debug, Clone)]
enum Message {
pub enum Message {
HideNotification,
ToggleComet,
CometLaunched(comet::launch::Result),
@ -403,7 +397,7 @@ where
}
}
enum Event<P>
pub enum Event<P>
where
P: Program,
{