mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 22:58:42 -06:00
move impls into separate module
This commit is contained in:
parent
d44a2bae53
commit
d2598f8a20
|
@ -1,37 +1,13 @@
|
|||
use glam::Vec2;
|
||||
use crate::{draw::{UiDrawCommand, UiDrawCommandList}, rect::FillColor};
|
||||
use crate::draw::UiDrawCommandList;
|
||||
|
||||
pub mod point;
|
||||
mod rect;
|
||||
pub mod stack;
|
||||
mod impls;
|
||||
|
||||
pub use rect::FrameRect;
|
||||
|
||||
pub trait Frame {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2);
|
||||
}
|
||||
|
||||
impl Frame for FillColor {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position,
|
||||
size: parent_size,
|
||||
color: self.corners(),
|
||||
texture: None,
|
||||
rounded_corners: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T: Into<FillColor> + Clone> Frame for T {
|
||||
// fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
// let color: FillColor = self.clone().into();
|
||||
// draw.add(UiDrawCommand::Rectangle {
|
||||
// position,
|
||||
// size: parent_size,
|
||||
// color: color.corners(),
|
||||
// texture: None,
|
||||
// rounded_corners: None,
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
|
125
hui/src/frame/impls.rs
Normal file
125
hui/src/frame/impls.rs
Normal file
|
@ -0,0 +1,125 @@
|
|||
use glam::{Vec2, Vec3, Vec4};
|
||||
use super::Frame;
|
||||
use crate::{
|
||||
color,
|
||||
draw::{ImageHandle, UiDrawCommand, UiDrawCommandList},
|
||||
rect::{Corners, FillColor},
|
||||
};
|
||||
|
||||
impl Frame for ImageHandle {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position,
|
||||
size: parent_size,
|
||||
color: color::WHITE.into(),
|
||||
texture: Some(*self),
|
||||
rounded_corners: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for FillColor {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position,
|
||||
size: parent_size,
|
||||
color: self.corners(),
|
||||
texture: None,
|
||||
rounded_corners: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// impl for various types resembling colors
|
||||
|
||||
// Corners (RGBA):
|
||||
|
||||
impl Frame for Corners<Vec4> {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for (Vec4, Vec4, Vec4, Vec4) {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for ((f32, f32, f32, f32), (f32, f32, f32, f32), (f32, f32, f32, f32), (f32, f32, f32, f32)) {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for [[f32; 4]; 4] {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
// Corners (RGB):
|
||||
|
||||
impl Frame for Corners<Vec3> {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for (Vec3, Vec3, Vec3, Vec3) {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for ((f32, f32, f32), (f32, f32, f32), (f32, f32, f32), (f32, f32, f32)) {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for [[f32; 3]; 4] {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
// RGBA:
|
||||
|
||||
impl Frame for Vec4 {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for (f32, f32, f32, f32) {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for [f32; 4] {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
// RGB:
|
||||
|
||||
impl Frame for Vec3 {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for (f32, f32, f32) {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame for [f32; 3] {
|
||||
fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) {
|
||||
FillColor::from(*self).draw(draw, position, parent_size)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue