2025-04-05 19:27:15 +02:00
|
|
|
#![allow(missing_docs)]
|
2025-04-05 20:08:54 +02:00
|
|
|
use iced_debug as debug;
|
2025-04-05 19:27:15 +02:00
|
|
|
use iced_program as program;
|
2025-04-05 20:08:54 +02:00
|
|
|
use iced_widget as widget;
|
2025-04-05 19:27:15 +02:00
|
|
|
use iced_widget::core;
|
|
|
|
|
use iced_widget::runtime;
|
2025-04-05 20:08:54 +02:00
|
|
|
use iced_widget::runtime::futures;
|
2025-04-05 19:27:15 +02:00
|
|
|
|
2025-04-28 09:48:55 +02:00
|
|
|
mod comet;
|
2025-04-06 17:21:20 +02:00
|
|
|
mod executor;
|
2025-04-20 22:11:24 +02:00
|
|
|
mod time_machine;
|
2025-04-06 17:21:20 +02:00
|
|
|
|
2025-04-05 20:08:54 +02:00
|
|
|
use crate::core::keyboard;
|
|
|
|
|
use crate::core::theme::{self, Base, Theme};
|
|
|
|
|
use crate::core::time::seconds;
|
2025-04-05 19:27:15 +02:00
|
|
|
use crate::core::window;
|
2025-04-06 17:21:20 +02:00
|
|
|
use crate::core::{Color, Element, Length::Fill};
|
2025-04-05 19:27:15 +02:00
|
|
|
use crate::futures::Subscription;
|
|
|
|
|
use crate::program::Program;
|
|
|
|
|
use crate::runtime::Task;
|
2025-04-20 22:11:24 +02:00
|
|
|
use crate::time_machine::TimeMachine;
|
2025-04-06 17:21:20 +02:00
|
|
|
use crate::widget::{
|
2025-04-11 01:22:54 +02:00
|
|
|
bottom_right, button, center, column, container, horizontal_space, opaque,
|
|
|
|
|
row, scrollable, stack, text, themer,
|
2025-04-06 17:21:20 +02:00
|
|
|
};
|
2025-04-05 19:27:15 +02:00
|
|
|
|
|
|
|
|
use std::fmt;
|
2025-04-05 20:14:51 +02:00
|
|
|
use std::thread;
|
2025-04-05 19:27:15 +02:00
|
|
|
|
|
|
|
|
pub fn attach(program: impl Program + 'static) -> impl Program {
|
|
|
|
|
struct Attach<P> {
|
|
|
|
|
program: P,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<P> Program for Attach<P>
|
|
|
|
|
where
|
|
|
|
|
P: Program + 'static,
|
|
|
|
|
{
|
|
|
|
|
type State = DevTools<P>;
|
2025-04-06 17:21:20 +02:00
|
|
|
type Message = Event<P>;
|
2025-04-05 19:27:15 +02:00
|
|
|
type Theme = P::Theme;
|
|
|
|
|
type Renderer = P::Renderer;
|
|
|
|
|
type Executor = P::Executor;
|
|
|
|
|
|
|
|
|
|
fn name() -> &'static str {
|
|
|
|
|
P::name()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn boot(&self) -> (Self::State, Task<Self::Message>) {
|
2025-04-05 20:08:54 +02:00
|
|
|
let (state, boot) = self.program.boot();
|
|
|
|
|
let (devtools, task) = DevTools::new(state);
|
2025-04-05 19:27:15 +02:00
|
|
|
|
2025-04-06 17:21:20 +02:00
|
|
|
(
|
|
|
|
|
devtools,
|
|
|
|
|
Task::batch([
|
|
|
|
|
boot.map(Event::Program),
|
|
|
|
|
task.map(Event::Message),
|
|
|
|
|
]),
|
|
|
|
|
)
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update(
|
|
|
|
|
&self,
|
|
|
|
|
state: &mut Self::State,
|
|
|
|
|
message: Self::Message,
|
|
|
|
|
) -> Task<Self::Message> {
|
|
|
|
|
state.update(&self.program, message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn view<'a>(
|
|
|
|
|
&self,
|
|
|
|
|
state: &'a Self::State,
|
|
|
|
|
window: window::Id,
|
|
|
|
|
) -> Element<'a, Self::Message, Self::Theme, Self::Renderer> {
|
|
|
|
|
state.view(&self.program, window)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn title(&self, state: &Self::State, window: window::Id) -> String {
|
|
|
|
|
state.title(&self.program, window)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn subscription(
|
|
|
|
|
&self,
|
|
|
|
|
state: &Self::State,
|
|
|
|
|
) -> runtime::futures::Subscription<Self::Message> {
|
|
|
|
|
state.subscription(&self.program)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
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>
|
|
|
|
|
where
|
|
|
|
|
P: Program,
|
|
|
|
|
{
|
|
|
|
|
state: P::State,
|
2025-04-06 17:21:20 +02:00
|
|
|
mode: Mode,
|
2025-04-05 20:08:54 +02:00
|
|
|
show_notification: bool,
|
2025-04-20 22:11:24 +02:00
|
|
|
time_machine: TimeMachine<P>,
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-06 17:21:20 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
enum Message {
|
|
|
|
|
HideNotification,
|
|
|
|
|
ToggleComet,
|
2025-04-28 09:48:55 +02:00
|
|
|
CometLaunched(Result<(), comet::Error>),
|
2025-04-06 17:21:20 +02:00
|
|
|
InstallComet,
|
2025-04-28 09:48:55 +02:00
|
|
|
InstallationProgressed(Result<comet::Installation, comet::Error>),
|
2025-04-06 17:21:20 +02:00
|
|
|
CancelSetup,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Mode {
|
|
|
|
|
None,
|
|
|
|
|
Setup(Setup),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Setup {
|
2025-04-28 09:48:55 +02:00
|
|
|
Idle { goal: Goal },
|
2025-04-06 17:21:20 +02:00
|
|
|
Running { logs: Vec<String> },
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 09:48:55 +02:00
|
|
|
enum Goal {
|
|
|
|
|
Installation,
|
|
|
|
|
Update { revision: Option<String> },
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 19:27:15 +02:00
|
|
|
impl<P> DevTools<P>
|
|
|
|
|
where
|
|
|
|
|
P: Program + 'static,
|
|
|
|
|
{
|
2025-04-20 22:11:24 +02:00
|
|
|
fn new(state: P::State) -> (Self, Task<Message>) {
|
2025-04-05 20:08:54 +02:00
|
|
|
(
|
|
|
|
|
Self {
|
|
|
|
|
state,
|
2025-04-06 17:21:20 +02:00
|
|
|
mode: Mode::None,
|
2025-04-05 20:08:54 +02:00
|
|
|
show_notification: true,
|
2025-04-20 22:11:24 +02:00
|
|
|
time_machine: TimeMachine::new(),
|
2025-04-05 20:08:54 +02:00
|
|
|
},
|
2025-04-06 17:21:20 +02:00
|
|
|
executor::spawn_blocking(|mut sender| {
|
|
|
|
|
thread::sleep(seconds(2));
|
|
|
|
|
let _ = sender.try_send(());
|
|
|
|
|
})
|
|
|
|
|
.map(|_| Message::HideNotification),
|
2025-04-05 20:08:54 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn title(&self, program: &P, window: window::Id) -> String {
|
2025-04-05 19:27:15 +02:00
|
|
|
program.title(&self.state, window)
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn update(&mut self, program: &P, event: Event<P>) -> Task<Event<P>> {
|
2025-04-06 17:21:20 +02:00
|
|
|
match event {
|
|
|
|
|
Event::Message(message) => match message {
|
|
|
|
|
Message::HideNotification => {
|
|
|
|
|
self.show_notification = false;
|
2025-04-05 20:08:54 +02:00
|
|
|
|
2025-04-06 17:21:20 +02:00
|
|
|
Task::none()
|
|
|
|
|
}
|
|
|
|
|
Message::ToggleComet => {
|
|
|
|
|
if let Mode::Setup(setup) = &self.mode {
|
2025-04-28 09:48:55 +02:00
|
|
|
if matches!(setup, Setup::Idle { .. }) {
|
2025-04-06 17:21:20 +02:00
|
|
|
self.mode = Mode::None;
|
|
|
|
|
}
|
2025-04-28 09:48:55 +02:00
|
|
|
|
|
|
|
|
Task::none()
|
|
|
|
|
} else if debug::quit() {
|
|
|
|
|
Task::none()
|
|
|
|
|
} else {
|
|
|
|
|
comet::launch()
|
|
|
|
|
.map(Message::CometLaunched)
|
|
|
|
|
.map(Event::Message)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Message::CometLaunched(Ok(())) => Task::none(),
|
|
|
|
|
Message::CometLaunched(Err(error)) => {
|
|
|
|
|
match error {
|
|
|
|
|
comet::Error::NotFound => {
|
|
|
|
|
self.mode = Mode::Setup(Setup::Idle {
|
|
|
|
|
goal: Goal::Installation,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
comet::Error::Outdated { revision } => {
|
|
|
|
|
self.mode = Mode::Setup(Setup::Idle {
|
|
|
|
|
goal: Goal::Update { revision },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
comet::Error::IoFailed(error) => {
|
|
|
|
|
log::error!("comet failed to run: {error}");
|
2025-04-06 17:21:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task::none()
|
|
|
|
|
}
|
|
|
|
|
Message::InstallComet => {
|
|
|
|
|
self.mode =
|
|
|
|
|
Mode::Setup(Setup::Running { logs: Vec::new() });
|
|
|
|
|
|
2025-04-28 09:48:55 +02:00
|
|
|
comet::install()
|
|
|
|
|
.map(Message::InstallationProgressed)
|
|
|
|
|
.map(Event::Message)
|
2025-04-06 17:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-28 09:48:55 +02:00
|
|
|
Message::InstallationProgressed(Ok(installation)) => {
|
|
|
|
|
let Mode::Setup(Setup::Running { logs }) = &mut self.mode
|
|
|
|
|
else {
|
|
|
|
|
return Task::none();
|
|
|
|
|
};
|
2025-04-05 20:08:54 +02:00
|
|
|
|
2025-04-28 09:48:55 +02:00
|
|
|
match installation {
|
|
|
|
|
comet::Installation::Logged(log) => {
|
|
|
|
|
logs.push(log);
|
|
|
|
|
Task::none()
|
|
|
|
|
}
|
|
|
|
|
comet::Installation::Finished => {
|
|
|
|
|
self.mode = Mode::None;
|
|
|
|
|
comet::launch().discard()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Message::InstallationProgressed(_error) => {
|
|
|
|
|
// TODO
|
2025-04-06 17:21:20 +02:00
|
|
|
Task::none()
|
|
|
|
|
}
|
|
|
|
|
Message::CancelSetup => {
|
|
|
|
|
self.mode = Mode::None;
|
|
|
|
|
|
|
|
|
|
Task::none()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Event::Program(message) => {
|
2025-04-21 05:12:08 +02:00
|
|
|
self.time_machine.push(&message);
|
2025-04-20 21:50:12 +02:00
|
|
|
|
2025-04-21 05:12:08 +02:00
|
|
|
if self.time_machine.is_rewinding() {
|
|
|
|
|
debug::enable();
|
2025-04-17 03:24:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let span = debug::update(&message);
|
|
|
|
|
let task = program.update(&mut self.state, message);
|
|
|
|
|
debug::tasks_spawned(task.units());
|
|
|
|
|
span.finish();
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
if self.time_machine.is_rewinding() {
|
2025-04-20 21:50:12 +02:00
|
|
|
debug::disable();
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-17 03:24:17 +02:00
|
|
|
task.map(Event::Program)
|
|
|
|
|
}
|
|
|
|
|
Event::Command(command) => {
|
|
|
|
|
match command {
|
|
|
|
|
debug::Command::RewindTo { message } => {
|
2025-04-20 22:11:24 +02:00
|
|
|
self.time_machine.rewind(program, message);
|
2025-04-17 03:24:17 +02:00
|
|
|
}
|
2025-04-20 21:50:12 +02:00
|
|
|
debug::Command::GoLive => {
|
2025-04-20 22:11:24 +02:00
|
|
|
self.time_machine.go_to_present();
|
2025-04-20 21:50:12 +02:00
|
|
|
}
|
2025-04-17 03:24:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task::none()
|
2025-04-05 20:08:54 +02:00
|
|
|
}
|
2025-04-20 21:50:12 +02:00
|
|
|
Event::Discard => Task::none(),
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn view(
|
2025-04-05 19:27:15 +02:00
|
|
|
&self,
|
|
|
|
|
program: &P,
|
|
|
|
|
window: window::Id,
|
2025-04-06 17:21:20 +02:00
|
|
|
) -> Element<'_, Event<P>, P::Theme, P::Renderer> {
|
2025-04-20 22:11:24 +02:00
|
|
|
let state = self.state();
|
2025-04-17 03:24:17 +02:00
|
|
|
|
2025-04-20 21:50:12 +02:00
|
|
|
let view = {
|
|
|
|
|
let view = program.view(state, window);
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
if self.time_machine.is_rewinding() {
|
2025-04-20 21:50:12 +02:00
|
|
|
view.map(|_| Event::Discard)
|
|
|
|
|
} else {
|
|
|
|
|
view.map(Event::Program)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-17 03:24:17 +02:00
|
|
|
let theme = program.theme(state, window);
|
2025-04-05 20:08:54 +02:00
|
|
|
|
2025-04-06 17:21:20 +02:00
|
|
|
let derive_theme = move || {
|
2025-04-05 20:08:54 +02:00
|
|
|
theme
|
|
|
|
|
.palette()
|
|
|
|
|
.map(|palette| Theme::custom("DevTools".to_owned(), palette))
|
2025-04-06 17:21:20 +02:00
|
|
|
.unwrap_or_default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mode = match &self.mode {
|
|
|
|
|
Mode::None => None,
|
|
|
|
|
Mode::Setup(setup) => {
|
|
|
|
|
let stage: Element<'_, _, Theme, P::Renderer> = match setup {
|
2025-04-28 09:48:55 +02:00
|
|
|
Setup::Idle { goal } => {
|
2025-04-06 17:21:20 +02:00
|
|
|
let controls = row![
|
|
|
|
|
button(text("Cancel").center().width(Fill))
|
|
|
|
|
.width(100)
|
|
|
|
|
.on_press(Message::CancelSetup)
|
|
|
|
|
.style(button::danger),
|
|
|
|
|
horizontal_space(),
|
2025-04-28 09:48:55 +02:00
|
|
|
button(
|
|
|
|
|
text(match goal {
|
|
|
|
|
Goal::Installation => "Install",
|
|
|
|
|
Goal::Update { .. } => "Update",
|
|
|
|
|
})
|
|
|
|
|
.center()
|
|
|
|
|
.width(Fill)
|
|
|
|
|
)
|
|
|
|
|
.width(100)
|
|
|
|
|
.on_press(Message::InstallComet)
|
|
|
|
|
.style(button::success),
|
2025-04-06 17:21:20 +02:00
|
|
|
];
|
|
|
|
|
|
2025-04-28 09:48:55 +02:00
|
|
|
let command = container(
|
|
|
|
|
text(
|
|
|
|
|
"cargo install --locked \
|
|
|
|
|
--git https://github.com/iced-rs/comet.git",
|
2025-04-06 17:21:20 +02:00
|
|
|
)
|
2025-04-28 09:48:55 +02:00
|
|
|
.size(14),
|
|
|
|
|
)
|
|
|
|
|
.width(Fill)
|
|
|
|
|
.padding(5)
|
|
|
|
|
.style(container::dark);
|
|
|
|
|
|
|
|
|
|
match goal {
|
|
|
|
|
Goal::Installation => column![
|
|
|
|
|
text("comet is not installed!").size(20),
|
|
|
|
|
"In order to display performance \
|
|
|
|
|
metrics, the comet debugger must \
|
|
|
|
|
be installed in your system.",
|
|
|
|
|
"The comet debugger is an official \
|
|
|
|
|
companion tool that helps you debug \
|
|
|
|
|
your iced applications.",
|
|
|
|
|
"Do you wish to install it with the \
|
|
|
|
|
following command?",
|
|
|
|
|
command,
|
|
|
|
|
controls,
|
|
|
|
|
]
|
|
|
|
|
.spacing(20),
|
|
|
|
|
Goal::Update { revision } => column![
|
|
|
|
|
text("comet is out of date!").size(20),
|
|
|
|
|
text!(
|
|
|
|
|
"The installed revision is \"{current}\", \
|
|
|
|
|
but the latest compatible is \"{compatible}\".",
|
|
|
|
|
current = revision
|
|
|
|
|
.as_deref()
|
|
|
|
|
.unwrap_or("Unknown"),
|
|
|
|
|
compatible = comet::COMPATIBLE_REVISION,
|
|
|
|
|
),
|
|
|
|
|
"Do you wish to update it with the following \
|
|
|
|
|
command?",
|
|
|
|
|
command,
|
|
|
|
|
controls,
|
|
|
|
|
]
|
|
|
|
|
.spacing(20),
|
|
|
|
|
}
|
2025-04-06 17:21:20 +02:00
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
Setup::Running { logs } => column![
|
|
|
|
|
text("Installing comet...").size(20),
|
|
|
|
|
container(
|
|
|
|
|
scrollable(
|
|
|
|
|
column(
|
|
|
|
|
logs.iter()
|
|
|
|
|
.map(|log| text(log).size(12).into()),
|
|
|
|
|
)
|
|
|
|
|
.spacing(3),
|
|
|
|
|
)
|
|
|
|
|
.spacing(10)
|
|
|
|
|
.width(Fill)
|
|
|
|
|
.height(300)
|
|
|
|
|
.anchor_bottom(),
|
|
|
|
|
)
|
|
|
|
|
.padding(10)
|
|
|
|
|
.style(container::dark)
|
|
|
|
|
]
|
|
|
|
|
.spacing(20)
|
|
|
|
|
.into(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let setup = center(
|
|
|
|
|
container(stage)
|
|
|
|
|
.padding(20)
|
|
|
|
|
.width(500)
|
|
|
|
|
.style(container::bordered_box),
|
|
|
|
|
)
|
|
|
|
|
.padding(10)
|
|
|
|
|
.style(|_theme| {
|
|
|
|
|
container::Style::default()
|
|
|
|
|
.background(Color::BLACK.scale_alpha(0.8))
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Some(setup)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.map(|mode| {
|
|
|
|
|
themer(derive_theme(), Element::from(mode).map(Event::Message))
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let notification = self.show_notification.then(|| {
|
|
|
|
|
themer(
|
|
|
|
|
derive_theme(),
|
2025-04-11 01:22:54 +02:00
|
|
|
bottom_right(opaque(
|
2025-04-06 17:21:20 +02:00
|
|
|
container(text("Press F12 to open debug metrics"))
|
|
|
|
|
.padding(10)
|
|
|
|
|
.style(container::dark),
|
2025-04-11 01:22:54 +02:00
|
|
|
)),
|
2025-04-06 17:21:20 +02:00
|
|
|
)
|
|
|
|
|
});
|
2025-04-05 20:08:54 +02:00
|
|
|
|
|
|
|
|
stack![view]
|
2025-04-17 03:24:17 +02:00
|
|
|
.height(Fill)
|
2025-04-11 01:22:54 +02:00
|
|
|
.push_maybe(mode.map(opaque))
|
2025-04-06 17:21:20 +02:00
|
|
|
.push_maybe(notification)
|
2025-04-05 20:08:54 +02:00
|
|
|
.into()
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn subscription(&self, program: &P) -> Subscription<Event<P>> {
|
2025-04-05 20:08:54 +02:00
|
|
|
let subscription =
|
2025-04-06 17:21:20 +02:00
|
|
|
program.subscription(&self.state).map(Event::Program);
|
2025-04-17 03:24:17 +02:00
|
|
|
debug::subscriptions_tracked(subscription.units());
|
|
|
|
|
|
2025-04-05 20:08:54 +02:00
|
|
|
let hotkeys =
|
|
|
|
|
futures::keyboard::on_key_press(|key, _modifiers| match key {
|
|
|
|
|
keyboard::Key::Named(keyboard::key::Named::F12) => {
|
|
|
|
|
Some(Message::ToggleComet)
|
|
|
|
|
}
|
|
|
|
|
_ => None,
|
2025-04-06 17:21:20 +02:00
|
|
|
})
|
|
|
|
|
.map(Event::Message);
|
2025-04-05 20:08:54 +02:00
|
|
|
|
2025-04-17 03:24:17 +02:00
|
|
|
let commands = debug::commands().map(Event::Command);
|
|
|
|
|
|
|
|
|
|
Subscription::batch([subscription, hotkeys, commands])
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn theme(&self, program: &P, window: window::Id) -> P::Theme {
|
|
|
|
|
program.theme(self.state(), window)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn style(&self, program: &P, theme: &P::Theme) -> theme::Style {
|
|
|
|
|
program.style(self.state(), theme)
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn scale_factor(&self, program: &P, window: window::Id) -> f64 {
|
|
|
|
|
program.scale_factor(self.state(), window)
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-20 22:11:24 +02:00
|
|
|
fn state(&self) -> &P::State {
|
|
|
|
|
self.time_machine.state().unwrap_or(&self.state)
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-06 17:21:20 +02:00
|
|
|
enum Event<P>
|
2025-04-05 19:27:15 +02:00
|
|
|
where
|
|
|
|
|
P: Program,
|
|
|
|
|
{
|
2025-04-06 17:21:20 +02:00
|
|
|
Message(Message),
|
2025-04-05 19:27:15 +02:00
|
|
|
Program(P::Message),
|
2025-04-17 03:24:17 +02:00
|
|
|
Command(debug::Command),
|
2025-04-20 21:50:12 +02:00
|
|
|
Discard,
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-06 17:21:20 +02:00
|
|
|
impl<P> fmt::Debug for Event<P>
|
2025-04-05 19:27:15 +02:00
|
|
|
where
|
|
|
|
|
P: Program,
|
|
|
|
|
{
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
match self {
|
2025-04-06 17:21:20 +02:00
|
|
|
Self::Message(message) => message.fmt(f),
|
|
|
|
|
Self::Program(message) => message.fmt(f),
|
2025-04-17 03:24:17 +02:00
|
|
|
Self::Command(command) => command.fmt(f),
|
2025-04-20 21:50:12 +02:00
|
|
|
Self::Discard => f.write_str("Discard"),
|
2025-04-17 03:24:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "time-travel")]
|
|
|
|
|
impl<P> Clone for Event<P>
|
|
|
|
|
where
|
|
|
|
|
P: Program,
|
|
|
|
|
{
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
match self {
|
2025-04-20 21:50:12 +02:00
|
|
|
Self::Message(message) => Self::Message(message.clone()),
|
|
|
|
|
Self::Program(message) => Self::Program(message.clone()),
|
|
|
|
|
Self::Command(command) => Self::Command(*command),
|
|
|
|
|
Self::Discard => Self::Discard,
|
2025-04-05 19:27:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|