dear_imgui_rs/render/draw_data/
vertex.rs1use crate::sys;
2
3#[repr(C)]
5#[derive(Copy, Clone, Debug, PartialEq)]
6pub struct DrawVert {
7 pub pos: [f32; 2],
9 pub uv: [f32; 2],
11 pub col: u32,
13}
14
15const _: [(); std::mem::size_of::<sys::ImDrawVert>()] = [(); std::mem::size_of::<DrawVert>()];
17const _: [(); std::mem::align_of::<sys::ImDrawVert>()] = [(); std::mem::align_of::<DrawVert>()];
18
19impl DrawVert {
20 pub fn new(pos: [f32; 2], uv: [f32; 2], col: u32) -> Self {
22 Self { pos, uv, col }
23 }
24
25 pub fn from_rgba(pos: [f32; 2], uv: [f32; 2], rgba: [u8; 4]) -> Self {
27 let col = ((rgba[3] as u32) << 24)
28 | ((rgba[2] as u32) << 16)
29 | ((rgba[1] as u32) << 8)
30 | (rgba[0] as u32);
31 Self { pos, uv, col }
32 }
33
34 pub fn rgba(&self) -> [u8; 4] {
36 [
37 (self.col & 0xFF) as u8,
38 ((self.col >> 8) & 0xFF) as u8,
39 ((self.col >> 16) & 0xFF) as u8,
40 ((self.col >> 24) & 0xFF) as u8,
41 ]
42 }
43}
44
45pub type DrawIdx = u16;
47
48const _: [(); std::mem::size_of::<sys::ImDrawIdx>()] = [(); std::mem::size_of::<DrawIdx>()];
49const _: [(); std::mem::align_of::<sys::ImDrawIdx>()] = [(); std::mem::align_of::<DrawIdx>()];