Move native events subscription to iced_native
This commit is contained in:
parent
e71978456a
commit
ba06d458d3
2 changed files with 32 additions and 35 deletions
|
|
@ -49,7 +49,7 @@ impl Application for Events {
|
||||||
|
|
||||||
fn subscriptions(&self) -> Subscription<Message> {
|
fn subscriptions(&self) -> Subscription<Message> {
|
||||||
if self.enabled {
|
if self.enabled {
|
||||||
events::all().map(Message::EventOccurred)
|
iced_native::subscription::events().map(Message::EventOccurred)
|
||||||
} else {
|
} else {
|
||||||
Subscription::none()
|
Subscription::none()
|
||||||
}
|
}
|
||||||
|
|
@ -67,8 +67,12 @@ impl Application for Events {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let toggle = Checkbox::new(self.enabled, "Enabled", Message::Toggled)
|
let toggle = Checkbox::new(
|
||||||
.width(Length::Shrink);
|
self.enabled,
|
||||||
|
"Listen to runtime events",
|
||||||
|
Message::Toggled,
|
||||||
|
)
|
||||||
|
.width(Length::Shrink);
|
||||||
|
|
||||||
let content = Column::new()
|
let content = Column::new()
|
||||||
.width(Length::Shrink)
|
.width(Length::Shrink)
|
||||||
|
|
@ -85,35 +89,3 @@ impl Application for Events {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod events {
|
|
||||||
pub fn all() -> iced::Subscription<iced_native::Event> {
|
|
||||||
iced::Subscription::from_recipe(All)
|
|
||||||
}
|
|
||||||
|
|
||||||
struct All;
|
|
||||||
|
|
||||||
impl
|
|
||||||
iced_native::subscription::Recipe<
|
|
||||||
iced_native::Hasher,
|
|
||||||
iced_native::subscription::Input,
|
|
||||||
> for All
|
|
||||||
{
|
|
||||||
type Output = iced_native::Event;
|
|
||||||
|
|
||||||
fn hash(&self, state: &mut iced_native::Hasher) {
|
|
||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
std::any::TypeId::of::<All>().hash(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stream(
|
|
||||||
self: Box<Self>,
|
|
||||||
input: iced_native::subscription::Input,
|
|
||||||
) -> futures::stream::BoxStream<'static, Self::Output> {
|
|
||||||
use futures::StreamExt;
|
|
||||||
|
|
||||||
input.boxed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,28 @@ pub type Subscription<T> = iced_core::Subscription<Hasher, Input, T>;
|
||||||
pub type Input = futures::channel::mpsc::Receiver<Event>;
|
pub type Input = futures::channel::mpsc::Receiver<Event>;
|
||||||
|
|
||||||
pub use iced_core::subscription::Recipe;
|
pub use iced_core::subscription::Recipe;
|
||||||
|
|
||||||
|
pub fn events() -> Subscription<Event> {
|
||||||
|
Subscription::from_recipe(Events)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Events;
|
||||||
|
|
||||||
|
impl Recipe<Hasher, Input> for Events {
|
||||||
|
type Output = Event;
|
||||||
|
|
||||||
|
fn hash(&self, state: &mut Hasher) {
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
std::any::TypeId::of::<Self>().hash(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stream(
|
||||||
|
self: Box<Self>,
|
||||||
|
input: Input,
|
||||||
|
) -> futures::stream::BoxStream<'static, Self::Output> {
|
||||||
|
use futures::StreamExt;
|
||||||
|
|
||||||
|
input.boxed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue