arcdps_imgui\fonts/
glyph.rs

1use crate::internal::RawCast;
2use crate::sys;
3
4/// A single font glyph
5#[derive(Copy, Clone, Debug, PartialEq)]
6#[repr(C)]
7pub struct FontGlyph {
8    bitfields: u32,
9    pub advance_x: f32,
10    pub x0: f32,
11    pub y0: f32,
12    pub x1: f32,
13    pub y1: f32,
14    pub u0: f32,
15    pub v0: f32,
16    pub u1: f32,
17    pub v1: f32,
18}
19
20impl FontGlyph {
21    pub fn codepoint(&self) -> u32 {
22        unsafe { self.raw().Codepoint() }
23    }
24    pub fn set_codepoint(&mut self, codepoint: u32) {
25        unsafe { self.raw_mut().set_Codepoint(codepoint) };
26    }
27    pub fn visible(&self) -> bool {
28        unsafe { self.raw().Visible() != 0 }
29    }
30    pub fn set_visible(&mut self, visible: bool) {
31        unsafe { self.raw_mut().set_Visible(visible as u32) }
32    }
33}
34
35unsafe impl RawCast<sys::ImFontGlyph> for FontGlyph {}
36
37#[test]
38fn test_font_glyph_memory_layout() {
39    use std::mem;
40    assert_eq!(
41        mem::size_of::<FontGlyph>(),
42        mem::size_of::<sys::ImFontGlyph>()
43    );
44    assert_eq!(
45        mem::align_of::<FontGlyph>(),
46        mem::align_of::<sys::ImFontGlyph>()
47    );
48    use sys::ImFontGlyph;
49    macro_rules! assert_field_offset {
50        ($l:ident, $r:ident) => {
51            assert_eq!(
52                memoffset::offset_of!(FontGlyph, $l),
53                memoffset::offset_of!(ImFontGlyph, $r)
54            );
55        };
56    }
57    assert_field_offset!(bitfields, _bitfield_1);
58    assert_field_offset!(advance_x, AdvanceX);
59    assert_field_offset!(x0, X0);
60    assert_field_offset!(y0, Y0);
61    assert_field_offset!(x1, X1);
62    assert_field_offset!(y1, Y1);
63    assert_field_offset!(u0, U0);
64    assert_field_offset!(v0, V0);
65    assert_field_offset!(u1, U1);
66    assert_field_offset!(v1, V1);
67}