Enable tester feature in websocket example
This commit is contained in:
parent
1821dc7ff0
commit
9cd1a93e5a
5 changed files with 44 additions and 16 deletions
|
|
@ -104,10 +104,7 @@ where
|
|||
state.title(&self.program, window)
|
||||
}
|
||||
|
||||
fn subscription(
|
||||
&self,
|
||||
state: &Self::State,
|
||||
) -> runtime::futures::Subscription<Self::Message> {
|
||||
fn subscription(&self, state: &Self::State) -> Subscription<Self::Message> {
|
||||
state.subscription(&self.program)
|
||||
}
|
||||
|
||||
|
|
@ -438,9 +435,19 @@ where
|
|||
}
|
||||
|
||||
fn subscription(&self, program: &P) -> Subscription<Event<P>> {
|
||||
let subscription =
|
||||
program.subscription(&self.state).map(Event::Program);
|
||||
debug::subscriptions_tracked(subscription.units());
|
||||
let subscription = match &self.mode {
|
||||
Mode::Open { tester } if !tester.is_idle() => {
|
||||
tester.subscription(program).map(Event::Tester)
|
||||
}
|
||||
_ => {
|
||||
let subscription =
|
||||
program.subscription(&self.state).map(Event::Program);
|
||||
|
||||
debug::subscriptions_tracked(subscription.units());
|
||||
|
||||
subscription
|
||||
}
|
||||
};
|
||||
|
||||
let hotkeys =
|
||||
futures::keyboard::on_key_press(|key, _modifiers| match key {
|
||||
|
|
@ -473,7 +480,11 @@ where
|
|||
}
|
||||
|
||||
fn scale_factor(&self, program: &P, window: window::Id) -> f64 {
|
||||
program.scale_factor(self.state(), window)
|
||||
if let Mode::Open { .. } = &self.mode {
|
||||
1.0
|
||||
} else {
|
||||
program.scale_factor(self.state(), window)
|
||||
}
|
||||
}
|
||||
|
||||
fn state(&self) -> &P::State {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use crate::core::alignment::Horizontal::Right;
|
|||
use crate::core::border;
|
||||
use crate::core::window;
|
||||
use crate::core::{Element, Event, Size, Theme};
|
||||
use crate::futures::Subscription;
|
||||
use crate::futures::futures::channel::mpsc;
|
||||
use crate::icon;
|
||||
use crate::program;
|
||||
|
|
@ -62,8 +63,12 @@ impl<P: Program + 'static> Tester<P> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_idle(&self) -> bool {
|
||||
matches!(self.state, State::Idle)
|
||||
}
|
||||
|
||||
pub fn is_busy(&self) -> bool {
|
||||
matches!(self.state, State::Idle | State::Playing { .. })
|
||||
matches!(self.state, State::Recording { .. } | State::Playing { .. })
|
||||
}
|
||||
|
||||
pub fn update(&mut self, program: &P, message: Message) -> Task<Tick<P>> {
|
||||
|
|
@ -160,6 +165,15 @@ impl<P: Program + 'static> Tester<P> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn subscription(&self, program: &P) -> Subscription<Tick<P>> {
|
||||
match &self.state {
|
||||
State::Idle | State::Playing { .. } => Subscription::none(),
|
||||
State::Recording { state } => {
|
||||
program.subscription(state).map(Tick::Program)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view<'a, T: 'static>(
|
||||
&'a self,
|
||||
program: &P,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue