|
@@ -13,7 +13,6 @@ use super::Widget;
|
|
|
pub struct Frame<C: Component> {
|
|
|
layout: LayoutNode,
|
|
|
child: Option<Box<dyn Widget<C>>>,
|
|
|
- _ghost: std::marker::PhantomData<C>,
|
|
|
}
|
|
|
|
|
|
impl<C: Component> Frame<C> {
|
|
@@ -25,7 +24,23 @@ impl<C: Component> Frame<C> {
|
|
|
Self {
|
|
|
layout: nnode,
|
|
|
child: None,
|
|
|
- _ghost: Default::default(),
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn new_with_child(uih: &UIHandle, child: Box<dyn Widget<C>>) -> Self {
|
|
|
+ let mut fr = Self::new(uih);
|
|
|
+ fr.set_child(child);
|
|
|
+ fr
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn wrap_widget<W: 'static + Widget<C>>(child: W) -> Self {
|
|
|
+ let mut nnode = LayoutNode::new(child.layout_node().cache().clone());
|
|
|
+ nnode
|
|
|
+ .set_height_policy(SizePolicy::expanding(1))
|
|
|
+ .set_width_policy(SizePolicy::expanding(1));
|
|
|
+ Self {
|
|
|
+ layout: nnode,
|
|
|
+ child: Some(Box::new(child)),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -58,10 +73,14 @@ impl<C: Component> LayoutNodeContainer for Frame<C> {
|
|
|
impl<C: Component> Widget<C> for Frame<C> {
|
|
|
fn poll(
|
|
|
&mut self,
|
|
|
- _uih: &mut UIHandle,
|
|
|
- _input_state: Option<&crate::input::InputState>,
|
|
|
+ uih: &mut UIHandle,
|
|
|
+ input_state: Option<&crate::input::InputState>,
|
|
|
) -> Vec<C::Msg> {
|
|
|
- vec![]
|
|
|
+ if let Some(child) = self.child.as_mut() {
|
|
|
+ child.poll(uih, input_state)
|
|
|
+ } else {
|
|
|
+ vec![]
|
|
|
+ }
|
|
|
}
|
|
|
fn layout_node(&self) -> LayoutNodeAccess {
|
|
|
LayoutNodeAccess::new(self)
|
|
@@ -72,10 +91,15 @@ impl<C: Component> Widget<C> for Frame<C> {
|
|
|
fn render(&self, theme: &Theme, target: &mut kahlo::BitmapMut<RenderFormat>) {
|
|
|
let area = self.layout.render_area().unwrap();
|
|
|
|
|
|
- target.fill_region(area, theme.border);
|
|
|
- target.fill_region(
|
|
|
- area.inner_box(PixelSideOffsets::new_all_same(theme.border_width as i32)),
|
|
|
- theme.panel,
|
|
|
- );
|
|
|
+ if self.layout.render_check() {
|
|
|
+ target.rectangle(area, theme.border_width, theme.border);
|
|
|
+ target.fill_region(
|
|
|
+ area.inner_box(PixelSideOffsets::new_all_same(theme.border_width as i32)),
|
|
|
+ theme.panel,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if let Some(child) = self.child.as_ref() {
|
|
|
+ child.render(theme, target);
|
|
|
+ }
|
|
|
}
|
|
|
}
|