1#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::AccessibleRange;
8use crate::{
9 ffi, Accessible, AccessibleRole, Adjustment, Align, Buildable, ConstraintTarget, LayoutManager,
10 Orientable, Orientation, Overflow, Widget,
11};
12use glib::{
13 prelude::*,
14 signal::{connect_raw, SignalHandlerId},
15 translate::*,
16};
17use std::boxed::Box as Box_;
18
19#[cfg(feature = "v4_10")]
20#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
21glib::wrapper! {
22 #[doc(alias = "GtkScrollbar")]
23 pub struct Scrollbar(Object<ffi::GtkScrollbar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
24
25 match fn {
26 type_ => || ffi::gtk_scrollbar_get_type(),
27 }
28}
29
30#[cfg(not(any(feature = "v4_10")))]
31glib::wrapper! {
32 #[doc(alias = "GtkScrollbar")]
33 pub struct Scrollbar(Object<ffi::GtkScrollbar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
34
35 match fn {
36 type_ => || ffi::gtk_scrollbar_get_type(),
37 }
38}
39
40impl Scrollbar {
41 #[doc(alias = "gtk_scrollbar_new")]
42 pub fn new(orientation: Orientation, adjustment: Option<&impl IsA<Adjustment>>) -> Scrollbar {
43 assert_initialized_main_thread!();
44 unsafe {
45 Widget::from_glib_none(ffi::gtk_scrollbar_new(
46 orientation.into_glib(),
47 adjustment.map(|p| p.as_ref()).to_glib_none().0,
48 ))
49 .unsafe_cast()
50 }
51 }
52
53 pub fn builder() -> ScrollbarBuilder {
58 ScrollbarBuilder::new()
59 }
60
61 #[doc(alias = "gtk_scrollbar_get_adjustment")]
62 #[doc(alias = "get_adjustment")]
63 pub fn adjustment(&self) -> Adjustment {
64 unsafe { from_glib_none(ffi::gtk_scrollbar_get_adjustment(self.to_glib_none().0)) }
65 }
66
67 #[doc(alias = "gtk_scrollbar_set_adjustment")]
68 #[doc(alias = "adjustment")]
69 pub fn set_adjustment(&self, adjustment: Option<&impl IsA<Adjustment>>) {
70 unsafe {
71 ffi::gtk_scrollbar_set_adjustment(
72 self.to_glib_none().0,
73 adjustment.map(|p| p.as_ref()).to_glib_none().0,
74 );
75 }
76 }
77
78 #[doc(alias = "adjustment")]
79 pub fn connect_adjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
80 unsafe extern "C" fn notify_adjustment_trampoline<F: Fn(&Scrollbar) + 'static>(
81 this: *mut ffi::GtkScrollbar,
82 _param_spec: glib::ffi::gpointer,
83 f: glib::ffi::gpointer,
84 ) {
85 let f: &F = &*(f as *const F);
86 f(&from_glib_borrow(this))
87 }
88 unsafe {
89 let f: Box_<F> = Box_::new(f);
90 connect_raw(
91 self.as_ptr() as *mut _,
92 c"notify::adjustment".as_ptr() as *const _,
93 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
94 notify_adjustment_trampoline::<F> as *const (),
95 )),
96 Box_::into_raw(f),
97 )
98 }
99 }
100}
101
102impl Default for Scrollbar {
103 fn default() -> Self {
104 glib::object::Object::new::<Self>()
105 }
106}
107
108#[must_use = "The builder must be built to be used"]
113pub struct ScrollbarBuilder {
114 builder: glib::object::ObjectBuilder<'static, Scrollbar>,
115}
116
117impl ScrollbarBuilder {
118 fn new() -> Self {
119 Self {
120 builder: glib::object::Object::builder(),
121 }
122 }
123
124 pub fn adjustment(self, adjustment: &impl IsA<Adjustment>) -> Self {
125 Self {
126 builder: self
127 .builder
128 .property("adjustment", adjustment.clone().upcast()),
129 }
130 }
131
132 pub fn can_focus(self, can_focus: bool) -> Self {
133 Self {
134 builder: self.builder.property("can-focus", can_focus),
135 }
136 }
137
138 pub fn can_target(self, can_target: bool) -> Self {
139 Self {
140 builder: self.builder.property("can-target", can_target),
141 }
142 }
143
144 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
145 Self {
146 builder: self.builder.property("css-classes", css_classes.into()),
147 }
148 }
149
150 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
151 Self {
152 builder: self.builder.property("css-name", css_name.into()),
153 }
154 }
155
156 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
157 Self {
158 builder: self.builder.property("cursor", cursor.clone()),
159 }
160 }
161
162 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
163 Self {
164 builder: self.builder.property("focus-on-click", focus_on_click),
165 }
166 }
167
168 pub fn focusable(self, focusable: bool) -> Self {
169 Self {
170 builder: self.builder.property("focusable", focusable),
171 }
172 }
173
174 pub fn halign(self, halign: Align) -> Self {
175 Self {
176 builder: self.builder.property("halign", halign),
177 }
178 }
179
180 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
181 Self {
182 builder: self.builder.property("has-tooltip", has_tooltip),
183 }
184 }
185
186 pub fn height_request(self, height_request: i32) -> Self {
187 Self {
188 builder: self.builder.property("height-request", height_request),
189 }
190 }
191
192 pub fn hexpand(self, hexpand: bool) -> Self {
193 Self {
194 builder: self.builder.property("hexpand", hexpand),
195 }
196 }
197
198 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
199 Self {
200 builder: self.builder.property("hexpand-set", hexpand_set),
201 }
202 }
203
204 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
205 Self {
206 builder: self
207 .builder
208 .property("layout-manager", layout_manager.clone().upcast()),
209 }
210 }
211
212 #[cfg(feature = "v4_18")]
213 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
214 pub fn limit_events(self, limit_events: bool) -> Self {
215 Self {
216 builder: self.builder.property("limit-events", limit_events),
217 }
218 }
219
220 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
221 Self {
222 builder: self.builder.property("margin-bottom", margin_bottom),
223 }
224 }
225
226 pub fn margin_end(self, margin_end: i32) -> Self {
227 Self {
228 builder: self.builder.property("margin-end", margin_end),
229 }
230 }
231
232 pub fn margin_start(self, margin_start: i32) -> Self {
233 Self {
234 builder: self.builder.property("margin-start", margin_start),
235 }
236 }
237
238 pub fn margin_top(self, margin_top: i32) -> Self {
239 Self {
240 builder: self.builder.property("margin-top", margin_top),
241 }
242 }
243
244 pub fn name(self, name: impl Into<glib::GString>) -> Self {
245 Self {
246 builder: self.builder.property("name", name.into()),
247 }
248 }
249
250 pub fn opacity(self, opacity: f64) -> Self {
251 Self {
252 builder: self.builder.property("opacity", opacity),
253 }
254 }
255
256 pub fn overflow(self, overflow: Overflow) -> Self {
257 Self {
258 builder: self.builder.property("overflow", overflow),
259 }
260 }
261
262 pub fn receives_default(self, receives_default: bool) -> Self {
263 Self {
264 builder: self.builder.property("receives-default", receives_default),
265 }
266 }
267
268 pub fn sensitive(self, sensitive: bool) -> Self {
269 Self {
270 builder: self.builder.property("sensitive", sensitive),
271 }
272 }
273
274 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
275 Self {
276 builder: self
277 .builder
278 .property("tooltip-markup", tooltip_markup.into()),
279 }
280 }
281
282 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
283 Self {
284 builder: self.builder.property("tooltip-text", tooltip_text.into()),
285 }
286 }
287
288 pub fn valign(self, valign: Align) -> Self {
289 Self {
290 builder: self.builder.property("valign", valign),
291 }
292 }
293
294 pub fn vexpand(self, vexpand: bool) -> Self {
295 Self {
296 builder: self.builder.property("vexpand", vexpand),
297 }
298 }
299
300 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
301 Self {
302 builder: self.builder.property("vexpand-set", vexpand_set),
303 }
304 }
305
306 pub fn visible(self, visible: bool) -> Self {
307 Self {
308 builder: self.builder.property("visible", visible),
309 }
310 }
311
312 pub fn width_request(self, width_request: i32) -> Self {
313 Self {
314 builder: self.builder.property("width-request", width_request),
315 }
316 }
317
318 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
319 Self {
320 builder: self.builder.property("accessible-role", accessible_role),
321 }
322 }
323
324 pub fn orientation(self, orientation: Orientation) -> Self {
325 Self {
326 builder: self.builder.property("orientation", orientation),
327 }
328 }
329
330 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
333 pub fn build(self) -> Scrollbar {
334 assert_initialized_main_thread!();
335 self.builder.build()
336 }
337}