mirror of
https://github.com/danbulant/cushy
synced 2026-06-17 21:41:11 +00:00
MakeWidget for Dynamic<WidgetInstance> + option
This commit is contained in:
parent
c0d714331b
commit
589c3dbc7f
1 changed files with 18 additions and 1 deletions
19
src/value.rs
19
src/value.rs
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue