Skip to main content

dear_imgui_rs/widget/drag/
ui.rs

1use std::ptr;
2
3use crate::Ui;
4use crate::internal::DataTypeKind;
5use crate::sys;
6
7use super::Drag;
8
9impl Ui {
10    /// Creates a new drag slider widget. Returns true if the value has been edited.
11    pub fn drag<T: AsRef<str>, K: DataTypeKind>(&self, label: T, value: &mut K) -> bool {
12        Drag::new(label).build(self, value)
13    }
14
15    /// Creates a new unbuilt Drag.
16    pub fn drag_config<T: AsRef<str>, K: DataTypeKind>(&self, label: T) -> Drag<K, T> {
17        Drag::new(label)
18    }
19
20    /// Creates a drag float2 slider (2 floats)
21    #[doc(alias = "DragFloat2")]
22    pub fn drag_float2(&self, label: impl AsRef<str>, values: &mut [f32; 2]) -> bool {
23        self.run_with_bound_context(|| unsafe {
24            let label_cstr = self.scratch_txt(label);
25            sys::igDragFloat2(
26                label_cstr,
27                values.as_mut_ptr(),
28                1.0,
29                0.0,
30                0.0,
31                ptr::null(),
32                0,
33            )
34        })
35    }
36
37    /// Creates a drag float3 slider (3 floats)
38    #[doc(alias = "DragFloat3")]
39    pub fn drag_float3(&self, label: impl AsRef<str>, values: &mut [f32; 3]) -> bool {
40        self.run_with_bound_context(|| unsafe {
41            let label_cstr = self.scratch_txt(label);
42            sys::igDragFloat3(
43                label_cstr,
44                values.as_mut_ptr(),
45                1.0,
46                0.0,
47                0.0,
48                ptr::null(),
49                0,
50            )
51        })
52    }
53
54    /// Creates a drag float4 slider (4 floats)
55    #[doc(alias = "DragFloat4")]
56    pub fn drag_float4(&self, label: impl AsRef<str>, values: &mut [f32; 4]) -> bool {
57        self.run_with_bound_context(|| unsafe {
58            let label_cstr = self.scratch_txt(label);
59            sys::igDragFloat4(
60                label_cstr,
61                values.as_mut_ptr(),
62                1.0,
63                0.0,
64                0.0,
65                ptr::null(),
66                0,
67            )
68        })
69    }
70
71    /// Creates a drag int2 slider (2 ints)
72    #[doc(alias = "DragInt2")]
73    pub fn drag_int2(&self, label: impl AsRef<str>, values: &mut [i32; 2]) -> bool {
74        self.run_with_bound_context(|| unsafe {
75            let label_cstr = self.scratch_txt(label);
76            sys::igDragInt2(label_cstr, values.as_mut_ptr(), 1.0, 0, 0, ptr::null(), 0)
77        })
78    }
79
80    /// Creates a drag int3 slider (3 ints)
81    #[doc(alias = "DragInt3")]
82    pub fn drag_int3(&self, label: impl AsRef<str>, values: &mut [i32; 3]) -> bool {
83        self.run_with_bound_context(|| unsafe {
84            let label_cstr = self.scratch_txt(label);
85            sys::igDragInt3(label_cstr, values.as_mut_ptr(), 1.0, 0, 0, ptr::null(), 0)
86        })
87    }
88
89    /// Creates a drag int4 slider (4 ints)
90    #[doc(alias = "DragInt4")]
91    pub fn drag_int4(&self, label: impl AsRef<str>, values: &mut [i32; 4]) -> bool {
92        self.run_with_bound_context(|| unsafe {
93            let label_cstr = self.scratch_txt(label);
94            sys::igDragInt4(label_cstr, values.as_mut_ptr(), 1.0, 0, 0, ptr::null(), 0)
95        })
96    }
97}