imgui/window/scroll.rs
1use crate::sys;
2use crate::Ui;
3
4/// # Window scrolling
5impl Ui {
6 /// Returns the horizontal scrolling position.
7 ///
8 /// Value is between 0.0 and self.scroll_max_x().
9 #[doc(alias = "GetScrollX")]
10 pub fn scroll_x(&self) -> f32 {
11 unsafe { sys::igGetScrollX() }
12 }
13 /// Returns the vertical scrolling position.
14 ///
15 /// Value is between 0.0 and self.scroll_max_y().
16 #[doc(alias = "GetScrollY")]
17 pub fn scroll_y(&self) -> f32 {
18 unsafe { sys::igGetScrollY() }
19 }
20 /// Returns the maximum horizontal scrolling position.
21 ///
22 /// Roughly equal to content size X - window size X.
23 #[doc(alias = "GetScrollMaxX")]
24 pub fn scroll_max_x(&self) -> f32 {
25 unsafe { sys::igGetScrollMaxX() }
26 }
27 /// Returns the maximum vertical scrolling position.
28 ///
29 /// Roughly equal to content size Y - window size Y.
30 #[doc(alias = "GetScrollMaxY")]
31 pub fn scroll_max_y(&self) -> f32 {
32 unsafe { sys::igGetScrollMaxY() }
33 }
34 /// Sets the horizontal scrolling position
35 #[doc(alias = "SetScrollX")]
36 pub fn set_scroll_x(&self, scroll_x: f32) {
37 unsafe {
38 cfg_if::cfg_if! {
39 if #[cfg(feature = "docking")] {
40 sys::igSetScrollX_Float(scroll_x);
41 } else {
42 sys::igSetScrollX(scroll_x);
43 }
44 }
45 }
46 }
47 /// Sets the vertical scroll position
48 #[doc(alias = "SetScrollY")]
49 pub fn set_scroll_y(&self, scroll_y: f32) {
50 unsafe {
51 cfg_if::cfg_if! {
52 if #[cfg(feature = "docking")] {
53 sys::igSetScrollY_Float(scroll_y);
54 } else {
55 sys::igSetScrollY(scroll_y);
56 }
57 }
58 }
59 }
60 /// Adjusts the horizontal scroll position to make the current cursor position visible.
61 ///
62 /// This is the same as [set_scroll_here_x_with_ratio](Self::set_scroll_here_x_with_ratio) but with `ratio` at 0.5.
63 #[doc(alias = "SetScrollHereX")]
64 pub fn set_scroll_here_x(&self) {
65 self.set_scroll_here_x_with_ratio(0.5);
66 }
67 /// Adjusts the horizontal scroll position to make the current cursor position visible.
68 ///
69 /// center_x_ratio:
70 ///
71 /// - `0.0`: left
72 /// - `0.5`: center
73 /// - `1.0`: right
74 #[doc(alias = "SetScrollHereX")]
75 pub fn set_scroll_here_x_with_ratio(&self, center_x_ratio: f32) {
76 unsafe { sys::igSetScrollHereX(center_x_ratio) };
77 }
78 /// Adjusts the vertical scroll position to make the current cursor position visible
79 ///
80 /// This is the same as [set_scroll_here_y_with_ratio](Self::set_scroll_here_y_with_ratio) but with `ratio` at 0.5.
81 #[doc(alias = "SetScrollHereY")]
82 pub fn set_scroll_here_y(&self) {
83 self.set_scroll_here_y_with_ratio(0.5);
84 }
85 /// Adjusts the vertical scroll position to make the current cursor position visible.
86 ///
87 /// center_y_ratio:
88 ///
89 /// - `0.0`: top
90 /// - `0.5`: center
91 /// - `1.0`: bottom
92 #[doc(alias = "SetScrollHereY")]
93 pub fn set_scroll_here_y_with_ratio(&self, center_y_ratio: f32) {
94 unsafe { sys::igSetScrollHereY(center_y_ratio) };
95 }
96 #[doc(alias = "SetScrollFromPosX")]
97 /// Adjusts the horizontal scroll position to make the given position visible
98 ///
99 /// This is the same as [set_scroll_from_pos_x_with_ratio](Self::set_scroll_from_pos_x_with_ratio)
100 /// but with `ratio` at 0.5.
101 pub fn set_scroll_from_pos_x(&self, local_x: f32) {
102 self.set_scroll_from_pos_x_with_ratio(local_x, 0.5);
103 }
104 /// Adjusts the horizontal scroll position to make the given position visible.
105 ///
106 /// center_x_ratio:
107 ///
108 /// - `0.0`: left
109 /// - `0.5`: center
110 /// - `1.0`: right
111 #[doc(alias = "SetScrollFromPosX")]
112 pub fn set_scroll_from_pos_x_with_ratio(&self, local_x: f32, center_x_ratio: f32) {
113 unsafe {
114 cfg_if::cfg_if! {
115 if #[cfg(feature = "docking")] {
116 sys::igSetScrollFromPosX_Float(local_x, center_x_ratio)
117 } else {
118 sys::igSetScrollFromPosX(local_x, center_x_ratio)
119 }
120 }
121 };
122 }
123 /// Adjusts the vertical scroll position to make the given position visible
124 ///
125 /// This is the same as [set_scroll_from_pos_y_with_ratio](Self::set_scroll_from_pos_y_with_ratio)
126 /// but with `ratio` at 0.5.
127 #[doc(alias = "SetScrollFromPosY")]
128 pub fn set_scroll_from_pos_y(&self, local_y: f32) {
129 self.set_scroll_from_pos_y_with_ratio(local_y, 0.5);
130 }
131 /// Adjusts the vertical scroll position to make the given position visible.
132 ///
133 /// center_y_ratio:
134 ///
135 /// - `0.0`: top
136 /// - `0.5`: center
137 /// - `1.0`: bottom
138 #[doc(alias = "SetScrollFromPosY")]
139 pub fn set_scroll_from_pos_y_with_ratio(&self, local_y: f32, center_y_ratio: f32) {
140 unsafe {
141 cfg_if::cfg_if! {
142 if #[cfg(feature = "docking")] {
143 sys::igSetScrollFromPosY_Float(local_y, center_y_ratio);
144 } else {
145 sys::igSetScrollFromPosY(local_y, center_y_ratio);
146 }
147 }
148 }
149 }
150}