dear_imgui_rs/window/
scroll.rs1use crate::Ui;
7use crate::sys;
8
9fn assert_finite_f32(caller: &str, name: &str, value: f32) {
10 assert!(value.is_finite(), "{caller} {name} must be finite");
11}
12
13fn assert_unit_ratio(caller: &str, name: &str, value: f32) {
14 assert_finite_f32(caller, name, value);
15 assert!(
16 (0.0..=1.0).contains(&value),
17 "{caller} {name} must be between 0.0 and 1.0"
18 );
19}
20
21impl Ui {
22 #[doc(alias = "GetScrollX")]
24 pub fn scroll_x(&self) -> f32 {
25 unsafe { sys::igGetScrollX() }
26 }
27
28 #[doc(alias = "GetScrollY")]
30 pub fn scroll_y(&self) -> f32 {
31 unsafe { sys::igGetScrollY() }
32 }
33
34 #[doc(alias = "GetScrollMaxX")]
36 pub fn scroll_max_x(&self) -> f32 {
37 unsafe { sys::igGetScrollMaxX() }
38 }
39
40 #[doc(alias = "GetScrollMaxY")]
42 pub fn scroll_max_y(&self) -> f32 {
43 unsafe { sys::igGetScrollMaxY() }
44 }
45
46 #[doc(alias = "SetScrollX")]
48 pub fn set_scroll_x(&self, scroll_x: f32) {
49 assert_finite_f32("Ui::set_scroll_x()", "scroll_x", scroll_x);
50 unsafe {
51 sys::igSetScrollX_Float(scroll_x);
52 }
53 }
54
55 #[doc(alias = "SetScrollY")]
57 pub fn set_scroll_y(&self, scroll_y: f32) {
58 assert_finite_f32("Ui::set_scroll_y()", "scroll_y", scroll_y);
59 unsafe {
60 sys::igSetScrollY_Float(scroll_y);
61 }
62 }
63
64 #[doc(alias = "SetScrollFromPosX")]
68 pub fn set_scroll_from_pos_x(&self, local_x: f32, center_x_ratio: f32) {
69 assert_finite_f32("Ui::set_scroll_from_pos_x()", "local_x", local_x);
70 assert_unit_ratio(
71 "Ui::set_scroll_from_pos_x()",
72 "center_x_ratio",
73 center_x_ratio,
74 );
75 unsafe {
76 sys::igSetScrollFromPosX_Float(local_x, center_x_ratio);
77 }
78 }
79
80 #[doc(alias = "SetScrollFromPosY")]
84 pub fn set_scroll_from_pos_y(&self, local_y: f32, center_y_ratio: f32) {
85 assert_finite_f32("Ui::set_scroll_from_pos_y()", "local_y", local_y);
86 assert_unit_ratio(
87 "Ui::set_scroll_from_pos_y()",
88 "center_y_ratio",
89 center_y_ratio,
90 );
91 unsafe {
92 sys::igSetScrollFromPosY_Float(local_y, center_y_ratio);
93 }
94 }
95
96 #[doc(alias = "SetScrollHereX")]
100 pub fn set_scroll_here_x(&self, center_x_ratio: f32) {
101 assert_unit_ratio("Ui::set_scroll_here_x()", "center_x_ratio", center_x_ratio);
102 unsafe {
103 sys::igSetScrollHereX(center_x_ratio);
104 }
105 }
106
107 #[doc(alias = "SetScrollHereY")]
111 pub fn set_scroll_here_y(&self, center_y_ratio: f32) {
112 assert_unit_ratio("Ui::set_scroll_here_y()", "center_y_ratio", center_y_ratio);
113 unsafe {
114 sys::igSetScrollHereY(center_y_ratio);
115 }
116 }
117}