arcdps_imgui\widget/
image.rs
1use std::os::raw::c_void;
2
3use crate::render::renderer::TextureId;
4use crate::sys;
5use crate::Ui;
6
7#[derive(Copy, Clone, Debug)]
9#[must_use]
10pub struct Image {
11 texture_id: TextureId,
12 size: [f32; 2],
13 uv0: [f32; 2],
14 uv1: [f32; 2],
15 tint_col: [f32; 4],
16 border_col: [f32; 4],
17}
18
19impl Image {
20 #[doc(alias = "Image")]
22 pub const fn new(texture_id: TextureId, size: [f32; 2]) -> Image {
23 Image {
24 texture_id,
25 size,
26 uv0: [0.0, 0.0],
27 uv1: [1.0, 1.0],
28 tint_col: [1.0, 1.0, 1.0, 1.0],
29 border_col: [0.0, 0.0, 0.0, 0.0],
30 }
31 }
32 pub const fn size(mut self, size: [f32; 2]) -> Self {
34 self.size = size;
35 self
36 }
37 pub const fn uv0(mut self, uv0: [f32; 2]) -> Self {
39 self.uv0 = uv0;
40 self
41 }
42 pub const fn uv1(mut self, uv1: [f32; 2]) -> Self {
44 self.uv1 = uv1;
45 self
46 }
47 pub const fn tint_col(mut self, tint_col: [f32; 4]) -> Self {
49 self.tint_col = tint_col;
50 self
51 }
52 pub const fn border_col(mut self, border_col: [f32; 4]) -> Self {
54 self.border_col = border_col;
55 self
56 }
57 pub fn build(self, _: &Ui<'_>) {
59 unsafe {
60 sys::igImage(
61 self.texture_id.id() as *mut c_void,
62 self.size.into(),
63 self.uv0.into(),
64 self.uv1.into(),
65 self.tint_col.into(),
66 self.border_col.into(),
67 );
68 }
69 }
70}
71
72#[derive(Copy, Clone, Debug)]
74#[must_use]
75pub struct ImageButton {
76 texture_id: TextureId,
77 size: [f32; 2],
78 uv0: [f32; 2],
79 uv1: [f32; 2],
80 frame_padding: i32,
81 bg_col: [f32; 4],
82 tint_col: [f32; 4],
83}
84
85impl ImageButton {
86 #[doc(alias = "ImageButton")]
88 pub fn new(texture_id: TextureId, size: [f32; 2]) -> ImageButton {
89 ImageButton {
90 texture_id,
91 size,
92 uv0: [0.0, 0.0],
93 uv1: [1.0, 1.0],
94 frame_padding: -1,
95 bg_col: [0.0, 0.0, 0.0, 0.0],
96 tint_col: [1.0, 1.0, 1.0, 1.0],
97 }
98 }
99 pub fn size(mut self, size: [f32; 2]) -> Self {
101 self.size = size;
102 self
103 }
104 pub fn uv0(mut self, uv0: [f32; 2]) -> Self {
106 self.uv0 = uv0;
107 self
108 }
109 pub fn uv1(mut self, uv1: [f32; 2]) -> Self {
111 self.uv1 = uv1;
112 self
113 }
114 pub fn frame_padding(mut self, frame_padding: i32) -> Self {
120 self.frame_padding = frame_padding;
121 self
122 }
123 pub fn background_col(mut self, bg_col: [f32; 4]) -> Self {
125 self.bg_col = bg_col;
126 self
127 }
128 pub fn tint_col(mut self, tint_col: [f32; 4]) -> Self {
130 self.tint_col = tint_col;
131 self
132 }
133 pub fn build(self, _: &Ui<'_>) -> bool {
135 unsafe {
136 sys::igImageButton(
137 self.texture_id.id() as *mut c_void,
138 self.size.into(),
139 self.uv0.into(),
140 self.uv1.into(),
141 self.frame_padding,
142 self.bg_col.into(),
143 self.tint_col.into(),
144 )
145 }
146 }
147}