dear_imgui_rs/window/
scroll.rs

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