Inherit Theme palette from Program in tester

This commit is contained in:
Héctor Ramón Jiménez 2025-10-08 04:15:42 +02:00
parent d47c921b29
commit 964a4707dc
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F

View file

@ -16,6 +16,7 @@ use crate::core::Length::Fill;
use crate::core::alignment::Horizontal::Right;
use crate::core::border;
use crate::core::mouse;
use crate::core::theme;
use crate::core::window;
use crate::core::{Color, Element, Font, Settings, Size, Theme};
use crate::futures::futures::channel::mpsc;
@ -95,6 +96,14 @@ where
) -> Element<'a, Self::Message, Self::Theme, Self::Renderer> {
state.view(&self.program, window).map(Message)
}
fn theme(&self, state: &Self::State, window: window::Id) -> Option<Theme> {
state
.theme(&self.program, window)
.as_ref()
.and_then(theme::Base::palette)
.map(|palette| Theme::custom("Tester", palette))
}
}
/// A tester decorates a [`Program`] definition and attaches a test recorder on top.
@ -399,6 +408,19 @@ impl<P: Program + 'static> Tester<P> {
self.edit = None;
}
fn theme(&self, program: &P, window: window::Id) -> Option<P::Theme> {
match &self.state {
State::Empty => None,
State::Idle { state } => program.theme(state, window),
State::Recording { emulator } | State::Playing { emulator, .. } => {
emulator.theme(program)
}
State::Asserting { state, window, .. } => {
program.theme(state, *window)
}
}
}
fn preset<'a>(
&self,
program: &'a P,