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