gtk/auto/
viewport.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib_sys;
14use gtk_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Adjustment;
19use Align;
20use Bin;
21use Buildable;
22use Container;
23use ResizeMode;
24use Scrollable;
25use ShadowType;
26use Widget;
27
28glib_wrapper! {
29    pub struct Viewport(Object<gtk_sys::GtkViewport, gtk_sys::GtkViewportClass, ViewportClass>) @extends Bin, Container, Widget, @implements Buildable, Scrollable;
30
31    match fn {
32        get_type => || gtk_sys::gtk_viewport_get_type(),
33    }
34}
35
36impl Viewport {
37    pub fn new<P: IsA<Adjustment>, Q: IsA<Adjustment>>(
38        hadjustment: Option<&P>,
39        vadjustment: Option<&Q>,
40    ) -> Viewport {
41        assert_initialized_main_thread!();
42        unsafe {
43            Widget::from_glib_none(gtk_sys::gtk_viewport_new(
44                hadjustment.map(|p| p.as_ref()).to_glib_none().0,
45                vadjustment.map(|p| p.as_ref()).to_glib_none().0,
46            ))
47            .unsafe_cast()
48        }
49    }
50}
51
52pub struct ViewportBuilder {
53    shadow_type: Option<ShadowType>,
54    border_width: Option<u32>,
55    child: Option<Widget>,
56    resize_mode: Option<ResizeMode>,
57    app_paintable: Option<bool>,
58    can_default: Option<bool>,
59    can_focus: Option<bool>,
60    events: Option<gdk::EventMask>,
61    expand: Option<bool>,
62    #[cfg(any(feature = "v3_20", feature = "dox"))]
63    focus_on_click: Option<bool>,
64    halign: Option<Align>,
65    has_default: Option<bool>,
66    has_focus: Option<bool>,
67    has_tooltip: Option<bool>,
68    height_request: Option<i32>,
69    hexpand: Option<bool>,
70    hexpand_set: Option<bool>,
71    is_focus: Option<bool>,
72    margin: Option<i32>,
73    margin_bottom: Option<i32>,
74    margin_end: Option<i32>,
75    margin_start: Option<i32>,
76    margin_top: Option<i32>,
77    name: Option<String>,
78    no_show_all: Option<bool>,
79    opacity: Option<f64>,
80    parent: Option<Container>,
81    receives_default: Option<bool>,
82    sensitive: Option<bool>,
83    //style: /*Unknown type*/,
84    tooltip_markup: Option<String>,
85    tooltip_text: Option<String>,
86    valign: Option<Align>,
87    vexpand: Option<bool>,
88    vexpand_set: Option<bool>,
89    visible: Option<bool>,
90    width_request: Option<i32>,
91}
92
93impl ViewportBuilder {
94    pub fn new() -> Self {
95        Self {
96            shadow_type: None,
97            border_width: None,
98            child: None,
99            resize_mode: None,
100            app_paintable: None,
101            can_default: None,
102            can_focus: None,
103            events: None,
104            expand: None,
105            #[cfg(any(feature = "v3_20", feature = "dox"))]
106            focus_on_click: None,
107            halign: None,
108            has_default: None,
109            has_focus: None,
110            has_tooltip: None,
111            height_request: None,
112            hexpand: None,
113            hexpand_set: None,
114            is_focus: None,
115            margin: None,
116            margin_bottom: None,
117            margin_end: None,
118            margin_start: None,
119            margin_top: None,
120            name: None,
121            no_show_all: None,
122            opacity: None,
123            parent: None,
124            receives_default: None,
125            sensitive: None,
126            tooltip_markup: None,
127            tooltip_text: None,
128            valign: None,
129            vexpand: None,
130            vexpand_set: None,
131            visible: None,
132            width_request: None,
133        }
134    }
135
136    pub fn build(self) -> Viewport {
137        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
138        if let Some(ref shadow_type) = self.shadow_type {
139            properties.push(("shadow-type", shadow_type));
140        }
141        if let Some(ref border_width) = self.border_width {
142            properties.push(("border-width", border_width));
143        }
144        if let Some(ref child) = self.child {
145            properties.push(("child", child));
146        }
147        if let Some(ref resize_mode) = self.resize_mode {
148            properties.push(("resize-mode", resize_mode));
149        }
150        if let Some(ref app_paintable) = self.app_paintable {
151            properties.push(("app-paintable", app_paintable));
152        }
153        if let Some(ref can_default) = self.can_default {
154            properties.push(("can-default", can_default));
155        }
156        if let Some(ref can_focus) = self.can_focus {
157            properties.push(("can-focus", can_focus));
158        }
159        if let Some(ref events) = self.events {
160            properties.push(("events", events));
161        }
162        if let Some(ref expand) = self.expand {
163            properties.push(("expand", expand));
164        }
165        #[cfg(any(feature = "v3_20", feature = "dox"))]
166        {
167            if let Some(ref focus_on_click) = self.focus_on_click {
168                properties.push(("focus-on-click", focus_on_click));
169            }
170        }
171        if let Some(ref halign) = self.halign {
172            properties.push(("halign", halign));
173        }
174        if let Some(ref has_default) = self.has_default {
175            properties.push(("has-default", has_default));
176        }
177        if let Some(ref has_focus) = self.has_focus {
178            properties.push(("has-focus", has_focus));
179        }
180        if let Some(ref has_tooltip) = self.has_tooltip {
181            properties.push(("has-tooltip", has_tooltip));
182        }
183        if let Some(ref height_request) = self.height_request {
184            properties.push(("height-request", height_request));
185        }
186        if let Some(ref hexpand) = self.hexpand {
187            properties.push(("hexpand", hexpand));
188        }
189        if let Some(ref hexpand_set) = self.hexpand_set {
190            properties.push(("hexpand-set", hexpand_set));
191        }
192        if let Some(ref is_focus) = self.is_focus {
193            properties.push(("is-focus", is_focus));
194        }
195        if let Some(ref margin) = self.margin {
196            properties.push(("margin", margin));
197        }
198        if let Some(ref margin_bottom) = self.margin_bottom {
199            properties.push(("margin-bottom", margin_bottom));
200        }
201        if let Some(ref margin_end) = self.margin_end {
202            properties.push(("margin-end", margin_end));
203        }
204        if let Some(ref margin_start) = self.margin_start {
205            properties.push(("margin-start", margin_start));
206        }
207        if let Some(ref margin_top) = self.margin_top {
208            properties.push(("margin-top", margin_top));
209        }
210        if let Some(ref name) = self.name {
211            properties.push(("name", name));
212        }
213        if let Some(ref no_show_all) = self.no_show_all {
214            properties.push(("no-show-all", no_show_all));
215        }
216        if let Some(ref opacity) = self.opacity {
217            properties.push(("opacity", opacity));
218        }
219        if let Some(ref parent) = self.parent {
220            properties.push(("parent", parent));
221        }
222        if let Some(ref receives_default) = self.receives_default {
223            properties.push(("receives-default", receives_default));
224        }
225        if let Some(ref sensitive) = self.sensitive {
226            properties.push(("sensitive", sensitive));
227        }
228        if let Some(ref tooltip_markup) = self.tooltip_markup {
229            properties.push(("tooltip-markup", tooltip_markup));
230        }
231        if let Some(ref tooltip_text) = self.tooltip_text {
232            properties.push(("tooltip-text", tooltip_text));
233        }
234        if let Some(ref valign) = self.valign {
235            properties.push(("valign", valign));
236        }
237        if let Some(ref vexpand) = self.vexpand {
238            properties.push(("vexpand", vexpand));
239        }
240        if let Some(ref vexpand_set) = self.vexpand_set {
241            properties.push(("vexpand-set", vexpand_set));
242        }
243        if let Some(ref visible) = self.visible {
244            properties.push(("visible", visible));
245        }
246        if let Some(ref width_request) = self.width_request {
247            properties.push(("width-request", width_request));
248        }
249        glib::Object::new(Viewport::static_type(), &properties)
250            .expect("object new")
251            .downcast()
252            .expect("downcast")
253    }
254
255    pub fn shadow_type(mut self, shadow_type: ShadowType) -> Self {
256        self.shadow_type = Some(shadow_type);
257        self
258    }
259
260    pub fn border_width(mut self, border_width: u32) -> Self {
261        self.border_width = Some(border_width);
262        self
263    }
264
265    pub fn child(mut self, child: &Widget) -> Self {
266        self.child = Some(child.clone());
267        self
268    }
269
270    pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
271        self.resize_mode = Some(resize_mode);
272        self
273    }
274
275    pub fn app_paintable(mut self, app_paintable: bool) -> Self {
276        self.app_paintable = Some(app_paintable);
277        self
278    }
279
280    pub fn can_default(mut self, can_default: bool) -> Self {
281        self.can_default = Some(can_default);
282        self
283    }
284
285    pub fn can_focus(mut self, can_focus: bool) -> Self {
286        self.can_focus = Some(can_focus);
287        self
288    }
289
290    pub fn events(mut self, events: gdk::EventMask) -> Self {
291        self.events = Some(events);
292        self
293    }
294
295    pub fn expand(mut self, expand: bool) -> Self {
296        self.expand = Some(expand);
297        self
298    }
299
300    #[cfg(any(feature = "v3_20", feature = "dox"))]
301    pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
302        self.focus_on_click = Some(focus_on_click);
303        self
304    }
305
306    pub fn halign(mut self, halign: Align) -> Self {
307        self.halign = Some(halign);
308        self
309    }
310
311    pub fn has_default(mut self, has_default: bool) -> Self {
312        self.has_default = Some(has_default);
313        self
314    }
315
316    pub fn has_focus(mut self, has_focus: bool) -> Self {
317        self.has_focus = Some(has_focus);
318        self
319    }
320
321    pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
322        self.has_tooltip = Some(has_tooltip);
323        self
324    }
325
326    pub fn height_request(mut self, height_request: i32) -> Self {
327        self.height_request = Some(height_request);
328        self
329    }
330
331    pub fn hexpand(mut self, hexpand: bool) -> Self {
332        self.hexpand = Some(hexpand);
333        self
334    }
335
336    pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
337        self.hexpand_set = Some(hexpand_set);
338        self
339    }
340
341    pub fn is_focus(mut self, is_focus: bool) -> Self {
342        self.is_focus = Some(is_focus);
343        self
344    }
345
346    pub fn margin(mut self, margin: i32) -> Self {
347        self.margin = Some(margin);
348        self
349    }
350
351    pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
352        self.margin_bottom = Some(margin_bottom);
353        self
354    }
355
356    pub fn margin_end(mut self, margin_end: i32) -> Self {
357        self.margin_end = Some(margin_end);
358        self
359    }
360
361    pub fn margin_start(mut self, margin_start: i32) -> Self {
362        self.margin_start = Some(margin_start);
363        self
364    }
365
366    pub fn margin_top(mut self, margin_top: i32) -> Self {
367        self.margin_top = Some(margin_top);
368        self
369    }
370
371    pub fn name(mut self, name: &str) -> Self {
372        self.name = Some(name.to_string());
373        self
374    }
375
376    pub fn no_show_all(mut self, no_show_all: bool) -> Self {
377        self.no_show_all = Some(no_show_all);
378        self
379    }
380
381    pub fn opacity(mut self, opacity: f64) -> Self {
382        self.opacity = Some(opacity);
383        self
384    }
385
386    pub fn parent(mut self, parent: &Container) -> Self {
387        self.parent = Some(parent.clone());
388        self
389    }
390
391    pub fn receives_default(mut self, receives_default: bool) -> Self {
392        self.receives_default = Some(receives_default);
393        self
394    }
395
396    pub fn sensitive(mut self, sensitive: bool) -> Self {
397        self.sensitive = Some(sensitive);
398        self
399    }
400
401    pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
402        self.tooltip_markup = Some(tooltip_markup.to_string());
403        self
404    }
405
406    pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
407        self.tooltip_text = Some(tooltip_text.to_string());
408        self
409    }
410
411    pub fn valign(mut self, valign: Align) -> Self {
412        self.valign = Some(valign);
413        self
414    }
415
416    pub fn vexpand(mut self, vexpand: bool) -> Self {
417        self.vexpand = Some(vexpand);
418        self
419    }
420
421    pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
422        self.vexpand_set = Some(vexpand_set);
423        self
424    }
425
426    pub fn visible(mut self, visible: bool) -> Self {
427        self.visible = Some(visible);
428        self
429    }
430
431    pub fn width_request(mut self, width_request: i32) -> Self {
432        self.width_request = Some(width_request);
433        self
434    }
435}
436
437pub const NONE_VIEWPORT: Option<&Viewport> = None;
438
439pub trait ViewportExt: 'static {
440    fn get_bin_window(&self) -> Option<gdk::Window>;
441
442    fn get_shadow_type(&self) -> ShadowType;
443
444    fn get_view_window(&self) -> Option<gdk::Window>;
445
446    fn set_shadow_type(&self, type_: ShadowType);
447
448    fn connect_property_shadow_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
449}
450
451impl<O: IsA<Viewport>> ViewportExt for O {
452    fn get_bin_window(&self) -> Option<gdk::Window> {
453        unsafe {
454            from_glib_none(gtk_sys::gtk_viewport_get_bin_window(
455                self.as_ref().to_glib_none().0,
456            ))
457        }
458    }
459
460    fn get_shadow_type(&self) -> ShadowType {
461        unsafe {
462            from_glib(gtk_sys::gtk_viewport_get_shadow_type(
463                self.as_ref().to_glib_none().0,
464            ))
465        }
466    }
467
468    fn get_view_window(&self) -> Option<gdk::Window> {
469        unsafe {
470            from_glib_none(gtk_sys::gtk_viewport_get_view_window(
471                self.as_ref().to_glib_none().0,
472            ))
473        }
474    }
475
476    fn set_shadow_type(&self, type_: ShadowType) {
477        unsafe {
478            gtk_sys::gtk_viewport_set_shadow_type(self.as_ref().to_glib_none().0, type_.to_glib());
479        }
480    }
481
482    fn connect_property_shadow_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
483        unsafe extern "C" fn notify_shadow_type_trampoline<P, F: Fn(&P) + 'static>(
484            this: *mut gtk_sys::GtkViewport,
485            _param_spec: glib_sys::gpointer,
486            f: glib_sys::gpointer,
487        ) where
488            P: IsA<Viewport>,
489        {
490            let f: &F = &*(f as *const F);
491            f(&Viewport::from_glib_borrow(this).unsafe_cast())
492        }
493        unsafe {
494            let f: Box_<F> = Box_::new(f);
495            connect_raw(
496                self.as_ptr() as *mut _,
497                b"notify::shadow-type\0".as_ptr() as *const _,
498                Some(transmute(notify_shadow_type_trampoline::<Self, F> as usize)),
499                Box_::into_raw(f),
500            )
501        }
502    }
503}
504
505impl fmt::Display for Viewport {
506    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
507        write!(f, "Viewport")
508    }
509}