dear_imgui_rs/ui/
widgets.rs1use super::*;
2
3impl Ui {
4 #[doc(alias = "TextUnformatted")]
6 pub fn text<T: AsRef<str>>(&self, text: T) {
7 let s = text.as_ref();
8 self.run_with_bound_context(|| unsafe {
9 let start = s.as_ptr();
10 let end = start.add(s.len());
11 crate::sys::igTextUnformatted(
12 start as *const std::os::raw::c_char,
13 end as *const std::os::raw::c_char,
14 );
15 });
16 }
17
18 #[doc(alias = "ImageWithBg")]
22 pub fn image_with_bg<'tex>(
23 &self,
24 texture: impl Into<TextureRef<'tex>>,
25 size: [f32; 2],
26 bg_color: [f32; 4],
27 tint_color: [f32; 4],
28 ) {
29 crate::widget::image::Image::new(self, texture, size).build_with_bg(bg_color, tint_color)
30 }
31
32 #[doc(alias = "DragFloat")]
36 pub fn drag_float(&self, label: impl AsRef<str>, value: &mut f32) -> bool {
37 crate::widget::drag::Drag::new(label).build(self, value)
38 }
39
40 #[doc(alias = "DragFloat")]
42 pub fn drag_float_config<L: AsRef<str>>(&self, label: L) -> crate::widget::drag::Drag<f32, L> {
43 crate::widget::drag::Drag::new(label)
44 }
45
46 #[doc(alias = "DragInt")]
48 pub fn drag_int(&self, label: impl AsRef<str>, value: &mut i32) -> bool {
49 crate::widget::drag::Drag::new(label).build(self, value)
50 }
51
52 #[doc(alias = "DragInt")]
54 pub fn drag_int_config<L: AsRef<str>>(&self, label: L) -> crate::widget::drag::Drag<i32, L> {
55 crate::widget::drag::Drag::new(label)
56 }
57
58 #[doc(alias = "DragFloatRange2")]
60 pub fn drag_float_range2(&self, label: impl AsRef<str>, min: &mut f32, max: &mut f32) -> bool {
61 crate::widget::drag::DragRange::<f32, _>::new(label).build(self, min, max)
62 }
63
64 #[doc(alias = "DragFloatRange2")]
66 pub fn drag_float_range2_config<L: AsRef<str>>(
67 &self,
68 label: L,
69 ) -> crate::widget::drag::DragRange<f32, L> {
70 crate::widget::drag::DragRange::new(label)
71 }
72
73 #[doc(alias = "DragIntRange2")]
75 pub fn drag_int_range2(&self, label: impl AsRef<str>, min: &mut i32, max: &mut i32) -> bool {
76 crate::widget::drag::DragRange::<i32, _>::new(label).build(self, min, max)
77 }
78
79 #[doc(alias = "DragIntRange2")]
81 pub fn drag_int_range2_config<L: AsRef<str>>(
82 &self,
83 label: L,
84 ) -> crate::widget::drag::DragRange<i32, L> {
85 crate::widget::drag::DragRange::new(label)
86 }
87
88 #[doc(alias = "SetNextItemOpen")]
92 pub fn set_next_item_open(&self, is_open: bool) {
93 self.run_with_bound_context(|| unsafe {
94 sys::igSetNextItemOpen(is_open, 0); });
96 }
97
98 #[doc(alias = "SetNextItemOpen")]
100 pub fn set_next_item_open_with_cond(&self, is_open: bool, cond: crate::Condition) {
101 self.run_with_bound_context(|| unsafe {
102 sys::igSetNextItemOpen(is_open, cond as sys::ImGuiCond)
103 });
104 }
105
106 #[doc(alias = "SetNextItemWidth")]
110 pub fn set_next_item_width(&self, item_width: f32) {
111 Self::assert_finite_f32("Ui::set_next_item_width()", "item_width", item_width);
112 self.run_with_bound_context(|| unsafe {
113 sys::igSetNextItemWidth(item_width);
114 });
115 }
116
117 #[doc(alias = "Value")]
119 pub fn value_bool(&self, prefix: impl AsRef<str>, v: bool) {
120 self.run_with_bound_context(|| unsafe { sys::igValue_Bool(self.scratch_txt(prefix), v) })
121 }
122}