|
@@ -1,36 +1,36 @@
|
|
|
+use kahlo::{prelude::*, math::PixelSideOffsets};
|
|
|
+
|
|
|
use crate::{
|
|
|
component::Component,
|
|
|
- layout::{LayoutNode, LayoutNodeAccess, LayoutNodeContainer},
|
|
|
- platform::{
|
|
|
- render::{Colour, Painter},
|
|
|
- PlatformPainter, PlatformSpec,
|
|
|
- },
|
|
|
+ layout::{LayoutNode, LayoutNodeAccess, LayoutNodeContainer, SizePolicy}, ui::UIHandle, theme::Theme,
|
|
|
};
|
|
|
|
|
|
-use super::{BuildContext, Widget};
|
|
|
+use super::Widget;
|
|
|
|
|
|
-pub struct Frame<P: PlatformSpec, C: Component> {
|
|
|
+pub struct Frame<C: Component> {
|
|
|
layout: LayoutNode,
|
|
|
- child: Option<Box<dyn Widget<P, C>>>,
|
|
|
+ child: Option<Box<dyn Widget<C>>>,
|
|
|
_ghost: std::marker::PhantomData<C>,
|
|
|
}
|
|
|
|
|
|
-impl<P: PlatformSpec, C: Component> Frame<P, C> {
|
|
|
- pub fn new(bc: &BuildContext) -> Self {
|
|
|
+impl<C: Component> Frame<C> {
|
|
|
+ pub fn new(uih: &UIHandle) -> Self {
|
|
|
+ let mut nnode = uih.new_layout_node();
|
|
|
+ nnode.set_height_policy(SizePolicy::expands(1)).set_width_policy(SizePolicy::expands(1));
|
|
|
Self {
|
|
|
- layout: LayoutNode::new(bc.lcache.clone()),
|
|
|
+ layout: nnode,
|
|
|
child: None,
|
|
|
_ghost: Default::default(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub fn set_child(&mut self, child: Box<dyn Widget<P, C>>) {
|
|
|
+ pub fn set_child(&mut self, child: Box<dyn Widget<C>>) {
|
|
|
self.child = Some(child);
|
|
|
self.layout.relayout();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<P: PlatformSpec, C: Component> LayoutNodeContainer for Frame<P, C> {
|
|
|
+impl<C: Component> LayoutNodeContainer for Frame<C> {
|
|
|
fn layout_node(&self) -> &LayoutNode {
|
|
|
&self.layout
|
|
|
}
|
|
@@ -50,8 +50,8 @@ impl<P: PlatformSpec, C: Component> LayoutNodeContainer for Frame<P, C> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<P: PlatformSpec, C: Component> Widget<P, C> for Frame<P, C> {
|
|
|
- fn poll(&mut self, _input_state: Option<&crate::input::InputState>) -> Vec<C::Msg> {
|
|
|
+impl<C: Component> Widget<C> for Frame<C> {
|
|
|
+ fn poll(&mut self, _uih: &mut UIHandle, _input_state: Option<&crate::input::InputState>) -> Vec<C::Msg> {
|
|
|
vec![]
|
|
|
}
|
|
|
fn layout_node(&self) -> LayoutNodeAccess {
|
|
@@ -60,11 +60,10 @@ impl<P: PlatformSpec, C: Component> Widget<P, C> for Frame<P, C> {
|
|
|
fn layout_node_mut(&mut self) -> &mut LayoutNode {
|
|
|
&mut self.layout
|
|
|
}
|
|
|
- fn render(&self, painter: &mut PlatformPainter<P>, ti: &P::Text) {
|
|
|
+ fn render(&self, theme: &Theme, target: &mut kahlo::RgbaBitmap) {
|
|
|
let rect = self.layout.cached_rect().unwrap();
|
|
|
- painter.fill(rect, Colour::new_rgb(50, 42, 0));
|
|
|
- if let Some(child) = self.child.as_ref() {
|
|
|
- child.render(painter, ti);
|
|
|
- }
|
|
|
+
|
|
|
+ target.fill_region(&rect.to_box2d(), theme.border);
|
|
|
+ target.fill_region(&rect.to_box2d().inner_box(PixelSideOffsets::new_all_same(theme.border_width as i32)), theme.panel);
|
|
|
}
|
|
|
}
|