diff --git a/hui/src/frame.rs b/hui/src/frame.rs index 27c8fca..bb31897 100644 --- a/hui/src/frame.rs +++ b/hui/src/frame.rs @@ -1,7 +1,8 @@ pub mod point; pub mod layer; - -use layer::{FrameLayer, RectFrame}; +use glam::Vec2; +use layer::{FrameLayer, FrameLayerImpl}; +use crate::draw::UiDrawCommandList; ///XXX: this is not used yet, and also kinda a mess, simplify? ///Maybe limit to a single layer? (aka `Frame` will be just one of the options) @@ -57,4 +58,10 @@ impl Frame { pub fn finish(&mut self) -> Self { self.clone() } + + pub(crate) fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) { + for layer in &self.layers { + layer.draw(draw, position, parent_size); + } + } } diff --git a/hui/src/frame/layer.rs b/hui/src/frame/layer.rs index 40df3a7..e95b236 100644 --- a/hui/src/frame/layer.rs +++ b/hui/src/frame/layer.rs @@ -9,7 +9,7 @@ use super::point::FramePoint2d; #[enum_dispatch] pub(crate) trait FrameLayerImpl { - fn draw(&self, draw: &mut UiDrawCommandList, parent_size: Vec2); + fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2); } #[derive(Clone, Copy)] @@ -20,10 +20,28 @@ pub enum FrameLayer { #[derive(Clone, Copy)] pub struct RectFrame { + /// Background color of the frame\ + /// + /// If the container has a background texture, it will be multiplied by this color + pub color: FillColor, + + /// Background texture of the frame + /// + /// Can be used in conjunction with the background color\ + /// In this case, the texture will be shaded by the color + /// + /// Please note that if the background color is NOT set (or set to transparent), the texture will NOT be visible\ + /// This is because the texture is multiplied by the color, and if the color is transparent, the texture will be too\ pub image: Option, + + /// Top left corner of the rectangle pub top_left: FramePoint2d, + + /// Bottom right corner of the rectangle pub bottom_right: FramePoint2d, + + /// Corner radius of the frame pub corner_radius: Corners, } @@ -97,12 +115,12 @@ impl Default for RectFrame { } impl FrameLayerImpl for RectFrame { - fn draw(&self, draw: &mut UiDrawCommandList, parent_size: Vec2) { + fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) { //TODO: handle bottom_right < top_left let top_left = self.top_left.resolve(parent_size); let bottom_right = self.bottom_right.resolve(parent_size); draw.add(UiDrawCommand::Rectangle { - position: top_left, + position: position + top_left, size: bottom_right - top_left, color: self.color.corners(), texture: self.image, diff --git a/hui/src/lib.rs b/hui/src/lib.rs index 31cfef6..42cbe65 100644 --- a/hui/src/lib.rs +++ b/hui/src/lib.rs @@ -22,8 +22,6 @@ pub mod state; pub mod text; pub mod color; pub mod signal; -//TODO change this to pub once the api is ready -//pub mod frame; -mod frame; +pub mod frame; pub use instance::UiInstance;