arcdps_imgui\widget/
text.rs
1use std::os::raw::c_char;
2
3use crate::style::StyleColor;
5use crate::Ui;
6
7static FMT: &[u8] = b"%s\0";
8
9#[inline]
10fn fmt_ptr() -> *const c_char {
11 FMT.as_ptr() as *const c_char
12}
13
14impl<'ui> Ui<'ui> {
16 #[doc(alias = "TextUnformatted")]
18 pub fn text<T: AsRef<str>>(&self, text: T) {
19 let s = text.as_ref();
20 unsafe {
21 let start = s.as_ptr();
22 let end = start.add(s.len());
23 sys::igTextUnformatted(start as *const c_char, end as *const c_char);
24 }
25 }
26 pub fn text_colored<T: AsRef<str>>(&self, color: [f32; 4], text: T) {
28 let style = self.push_style_color(StyleColor::Text, color);
29 self.text(text);
30 style.end();
31 }
32 pub fn text_disabled<T: AsRef<str>>(&self, text: T) {
34 let color = self.style_color(StyleColor::TextDisabled);
35 let style = self.push_style_color(StyleColor::Text, color);
36 self.text(text);
37 style.end();
38 }
39 #[doc(alias = "TextWrapperd")]
41 pub fn text_wrapped(&self, text: impl AsRef<str>) {
42 unsafe { sys::igTextWrapped(fmt_ptr(), self.scratch_txt(text)) }
43 }
44 #[doc(alias = "LabelText")]
46 pub fn label_text(&self, label: impl AsRef<str>, text: impl AsRef<str>) {
47 let (ptr_one, ptr_two) = self.scratch_txt_two(label, text);
48 unsafe { sys::igLabelText(ptr_one, fmt_ptr(), ptr_two) }
49 }
50 #[doc(alias = "BulletText")]
52 pub fn bullet_text(&self, text: impl AsRef<str>) {
53 unsafe { sys::igBulletText(fmt_ptr(), self.scratch_txt(text)) }
54 }
55}