frame api is a mess...

This commit is contained in:
griffi-gh 2024-03-23 19:53:32 +01:00
parent 3ac83e161a
commit b12c62e06f
3 changed files with 31 additions and 8 deletions

View file

@ -1,7 +1,8 @@
pub mod point; pub mod point;
pub mod layer; pub mod layer;
use glam::Vec2;
use layer::{FrameLayer, RectFrame}; use layer::{FrameLayer, FrameLayerImpl};
use crate::draw::UiDrawCommandList;
///XXX: this is not used yet, and also kinda a mess, simplify? ///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) ///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 { pub fn finish(&mut self) -> Self {
self.clone() 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);
}
}
} }

View file

@ -9,7 +9,7 @@ use super::point::FramePoint2d;
#[enum_dispatch] #[enum_dispatch]
pub(crate) trait FrameLayerImpl { 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)] #[derive(Clone, Copy)]
@ -20,10 +20,28 @@ pub enum FrameLayer {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct RectFrame { 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, 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<ImageHandle>, pub image: Option<ImageHandle>,
/// Top left corner of the rectangle
pub top_left: FramePoint2d, pub top_left: FramePoint2d,
/// Bottom right corner of the rectangle
pub bottom_right: FramePoint2d, pub bottom_right: FramePoint2d,
/// Corner radius of the frame
pub corner_radius: Corners<f32>, pub corner_radius: Corners<f32>,
} }
@ -97,12 +115,12 @@ impl Default for RectFrame {
} }
impl FrameLayerImpl 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 //TODO: handle bottom_right < top_left
let top_left = self.top_left.resolve(parent_size); let top_left = self.top_left.resolve(parent_size);
let bottom_right = self.bottom_right.resolve(parent_size); let bottom_right = self.bottom_right.resolve(parent_size);
draw.add(UiDrawCommand::Rectangle { draw.add(UiDrawCommand::Rectangle {
position: top_left, position: position + top_left,
size: bottom_right - top_left, size: bottom_right - top_left,
color: self.color.corners(), color: self.color.corners(),
texture: self.image, texture: self.image,

View file

@ -22,8 +22,6 @@ pub mod state;
pub mod text; pub mod text;
pub mod color; pub mod color;
pub mod signal; pub mod signal;
//TODO change this to pub once the api is ready pub mod frame;
//pub mod frame;
mod frame;
pub use instance::UiInstance; pub use instance::UiInstance;