Reviewed-on: iris/iris#16 Reviewed-by: iris <2+iris@noreply.localhost> Co-authored-by: iris-ai <4+iris-ai@noreply.localhost>
43 lines
880 B
Rust
43 lines
880 B
Rust
use crate::prelude::*;
|
|
use std::marker::Unsize;
|
|
|
|
pub struct WidgetPtr {
|
|
pub inner: Option<StrongWidget>,
|
|
}
|
|
|
|
impl Widget for WidgetPtr {
|
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
|
match &self.inner {
|
|
Some(id) => painter.widget(id).size(),
|
|
None => Size::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WidgetPtr {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
pub fn empty() -> Self {
|
|
Self {
|
|
inner: Default::default(),
|
|
}
|
|
}
|
|
pub fn set<W: ?Sized + Unsize<dyn Widget>>(&mut self, to: StrongWidget<W>) {
|
|
self.inner = Some(to)
|
|
}
|
|
|
|
pub fn replace<W: ?Sized + Unsize<dyn Widget>>(
|
|
&mut self,
|
|
to: StrongWidget<W>,
|
|
) -> Option<StrongWidget> {
|
|
self.inner.replace(to)
|
|
}
|
|
}
|
|
|
|
impl Default for WidgetPtr {
|
|
fn default() -> Self {
|
|
Self::empty()
|
|
}
|
|
}
|