arcdps_imgui\widget/
text.rs

1use std::os::raw::c_char;
2
3// use crate::string::ImStr;
4use 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
14/// # Widgets: Text
15impl<'ui> Ui<'ui> {
16    /// Renders simple text
17    #[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    /// Renders simple text using the given text color
27    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    /// Renders simple text using `StyleColor::TextDisabled` color
33    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    /// Renders text wrapped to the end of window (or column)
40    #[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    /// Render a text + label combination aligned the same way as value+label widgets
45    #[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    /// Renders text with a little bullet aligned to the typical tree node
51    #[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}