MakeWidget for Dynamic<WidgetInstance> + option

This commit is contained in:
Jonathan Johnson 2023-11-29 11:42:51 -08:00
parent c0d714331b
commit 589c3dbc7f
No known key found for this signature in database
GPG key ID: A66D6A34D6620579

View file

@ -18,7 +18,7 @@ use crate::context::sealed::WindowHandle;
use crate::context::{self, WidgetContext};
use crate::utils::{run_in_bg, IgnorePoison, UnwindsafeCondvar, WithClone};
use crate::widget::{MakeWidget, WidgetId, WidgetInstance};
use crate::widgets::{Radio, Switcher};
use crate::widgets::{Radio, Space, Switcher};
/// An instance of a value that provides APIs to observe and react to its
/// contents.
@ -589,6 +589,23 @@ impl Dynamic<WidgetInstance> {
}
}
impl MakeWidget for Dynamic<WidgetInstance> {
fn make_widget(self) -> WidgetInstance {
self.switcher().make_widget()
}
}
impl MakeWidget for Dynamic<Option<WidgetInstance>> {
fn make_widget(self) -> WidgetInstance {
self.map_each(|widget| {
widget
.as_ref()
.map_or_else(|| Space::clear().make_widget(), Clone::clone)
})
.make_widget()
}
}
impl<T> context::sealed::Trackable for Dynamic<T> {
fn redraw_when_changed(&self, handle: WindowHandle) {
self.redraw_when_changed(handle);