rhai
This commit is contained in:
73
src/render/primitive.rs
Normal file
73
src/render/primitive.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use glam::Vec2;
|
||||
use rhai::{CustomType, TypeBuilder};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable, CustomType)]
|
||||
pub struct RoundedRect {
|
||||
pub top_left: UIPos,
|
||||
pub bottom_right: UIPos,
|
||||
pub colors: [[f32; 4]; 4],
|
||||
pub radius: f32,
|
||||
pub inner_radius: f32,
|
||||
pub thickness: f32,
|
||||
}
|
||||
|
||||
impl Default for RoundedRect {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
top_left: Default::default(),
|
||||
bottom_right: Default::default(),
|
||||
colors: [
|
||||
[1.0, 0.0, 0.0, 1.0],
|
||||
[0.0, 1.0, 0.0, 1.0],
|
||||
[0.0, 0.0, 1.0, 1.0],
|
||||
[1.0, 1.0, 1.0, 1.0],
|
||||
],
|
||||
radius: Default::default(),
|
||||
inner_radius: Default::default(),
|
||||
thickness: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub struct Text {
|
||||
pub content: String,
|
||||
pub align: Align,
|
||||
pub pos: Vec2,
|
||||
pub bounds: (f32, f32),
|
||||
}
|
||||
|
||||
impl Text {
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
content: String::new(),
|
||||
align: Align::Left,
|
||||
pos: Vec2::default(),
|
||||
bounds: (0.0, 0.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable, Default)]
|
||||
pub struct UIPos {
|
||||
pub anchor: Vec2,
|
||||
pub offset: Vec2,
|
||||
}
|
||||
|
||||
impl UIPos {
|
||||
pub fn anchor_offset(anchor_x: f32, anchor_y: f32, offset_x: f32, offset_y: f32) -> Self {
|
||||
Self {
|
||||
anchor: Vec2::new(anchor_x, anchor_y),
|
||||
offset: Vec2::new(offset_x, offset_y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub enum Align {
|
||||
Left,
|
||||
Right,
|
||||
Center,
|
||||
}
|
||||
Reference in New Issue
Block a user