dear_imgui/window/
scroll.rs

1use crate::Ui;
2use crate::sys;
3
4impl Ui {
5    /// Returns the current scroll position of the window
6    #[doc(alias = "GetScrollX")]
7    pub fn scroll_x(&self) -> f32 {
8        unsafe { sys::igGetScrollX() }
9    }
10
11    /// Returns the current vertical scroll position of the window
12    #[doc(alias = "GetScrollY")]
13    pub fn scroll_y(&self) -> f32 {
14        unsafe { sys::igGetScrollY() }
15    }
16
17    /// Returns the maximum horizontal scroll position
18    #[doc(alias = "GetScrollMaxX")]
19    pub fn scroll_max_x(&self) -> f32 {
20        unsafe { sys::igGetScrollMaxX() }
21    }
22
23    /// Returns the maximum vertical scroll position
24    #[doc(alias = "GetScrollMaxY")]
25    pub fn scroll_max_y(&self) -> f32 {
26        unsafe { sys::igGetScrollMaxY() }
27    }
28
29    /// Sets the horizontal scroll position
30    #[doc(alias = "SetScrollX")]
31    pub fn set_scroll_x(&self, scroll_x: f32) {
32        unsafe {
33            sys::igSetScrollX_Float(scroll_x);
34        }
35    }
36
37    /// Sets the vertical scroll position
38    #[doc(alias = "SetScrollY")]
39    pub fn set_scroll_y(&self, scroll_y: f32) {
40        unsafe {
41            sys::igSetScrollY_Float(scroll_y);
42        }
43    }
44
45    /// Sets the horizontal scroll position to center on the given position
46    ///
47    /// The center_x_ratio parameter should be between 0.0 (left) and 1.0 (right)
48    #[doc(alias = "SetScrollFromPosX")]
49    pub fn set_scroll_from_pos_x(&self, local_x: f32, center_x_ratio: f32) {
50        unsafe {
51            sys::igSetScrollFromPosX_Float(local_x, center_x_ratio);
52        }
53    }
54
55    /// Sets the vertical scroll position to center on the given position
56    ///
57    /// The center_y_ratio parameter should be between 0.0 (top) and 1.0 (bottom)
58    #[doc(alias = "SetScrollFromPosY")]
59    pub fn set_scroll_from_pos_y(&self, local_y: f32, center_y_ratio: f32) {
60        unsafe {
61            sys::igSetScrollFromPosY_Float(local_y, center_y_ratio);
62        }
63    }
64
65    /// Scrolls to make the current item visible
66    ///
67    /// This is useful when you want to ensure a specific item is visible in a scrollable region
68    #[doc(alias = "SetScrollHereX")]
69    pub fn set_scroll_here_x(&self, center_x_ratio: f32) {
70        unsafe {
71            sys::igSetScrollHereX(center_x_ratio);
72        }
73    }
74
75    /// Scrolls to make the current item visible vertically
76    ///
77    /// This is useful when you want to ensure a specific item is visible in a scrollable region
78    #[doc(alias = "SetScrollHereY")]
79    pub fn set_scroll_here_y(&self, center_y_ratio: f32) {
80        unsafe {
81            sys::igSetScrollHereY(center_y_ratio);
82        }
83    }
84}