dear_imgui/widget/
text.rs

1use crate::Ui;
2use crate::sys;
3
4impl Ui {
5    /// Display colored text
6    #[doc(alias = "TextColored")]
7    pub fn text_colored(&self, color: [f32; 4], text: impl AsRef<str>) {
8        let text_ptr = self.scratch_txt(text);
9        unsafe {
10            let color_vec = sys::ImVec4 {
11                x: color[0],
12                y: color[1],
13                z: color[2],
14                w: color[3],
15            };
16            sys::igTextColored(color_vec, text_ptr);
17        }
18    }
19
20    /// Display disabled (grayed out) text
21    #[doc(alias = "TextDisabled")]
22    pub fn text_disabled(&self, text: impl AsRef<str>) {
23        let text_ptr = self.scratch_txt(text);
24        unsafe {
25            sys::igTextDisabled(text_ptr);
26        }
27    }
28
29    /// Display text wrapped to fit the current item width
30    #[doc(alias = "TextWrapped")]
31    pub fn text_wrapped(&self, text: impl AsRef<str>) {
32        let text_ptr = self.scratch_txt(text);
33        unsafe {
34            sys::igTextWrapped(text_ptr);
35        }
36    }
37
38    /// Display a label and text on the same line
39    #[doc(alias = "LabelText")]
40    pub fn label_text(&self, label: impl AsRef<str>, text: impl AsRef<str>) {
41        let (label_ptr, text_ptr) = self.scratch_txt_two(label, text);
42        unsafe {
43            sys::igLabelText(label_ptr, text_ptr);
44        }
45    }
46
47    /// Render a hyperlink-style text button. Returns true when clicked.
48    #[doc(alias = "TextLink")]
49    pub fn text_link(&self, label: impl AsRef<str>) -> bool {
50        unsafe { sys::igTextLink(self.scratch_txt(label)) }
51    }
52
53    /// Render a hyperlink-style text button, and open the given URL when clicked.
54    /// Returns true when clicked.
55    #[doc(alias = "TextLinkOpenURL")]
56    pub fn text_link_open_url(&self, label: impl AsRef<str>, url: impl AsRef<str>) -> bool {
57        let (label_ptr, url_ptr) = self.scratch_txt_two(label, url);
58        unsafe { sys::igTextLinkOpenURL(label_ptr, url_ptr) }
59    }
60}