gtk/auto/
layout.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::Value;
14use glib_sys;
15use gobject_sys;
16use gtk_sys;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem;
20use std::mem::transmute;
21use Adjustment;
22use Align;
23use Buildable;
24use Container;
25use ResizeMode;
26use Scrollable;
27use Widget;
28
29glib_wrapper! {
30    pub struct Layout(Object<gtk_sys::GtkLayout, gtk_sys::GtkLayoutClass, LayoutClass>) @extends Container, Widget, @implements Buildable, Scrollable;
31
32    match fn {
33        get_type => || gtk_sys::gtk_layout_get_type(),
34    }
35}
36
37impl Layout {
38    pub fn new<P: IsA<Adjustment>, Q: IsA<Adjustment>>(
39        hadjustment: Option<&P>,
40        vadjustment: Option<&Q>,
41    ) -> Layout {
42        assert_initialized_main_thread!();
43        unsafe {
44            Widget::from_glib_none(gtk_sys::gtk_layout_new(
45                hadjustment.map(|p| p.as_ref()).to_glib_none().0,
46                vadjustment.map(|p| p.as_ref()).to_glib_none().0,
47            ))
48            .unsafe_cast()
49        }
50    }
51}
52
53pub struct LayoutBuilder {
54    height: Option<u32>,
55    width: Option<u32>,
56    border_width: Option<u32>,
57    child: Option<Widget>,
58    resize_mode: Option<ResizeMode>,
59    app_paintable: Option<bool>,
60    can_default: Option<bool>,
61    can_focus: Option<bool>,
62    events: Option<gdk::EventMask>,
63    expand: Option<bool>,
64    #[cfg(any(feature = "v3_20", feature = "dox"))]
65    focus_on_click: Option<bool>,
66    halign: Option<Align>,
67    has_default: Option<bool>,
68    has_focus: Option<bool>,
69    has_tooltip: Option<bool>,
70    height_request: Option<i32>,
71    hexpand: Option<bool>,
72    hexpand_set: Option<bool>,
73    is_focus: Option<bool>,
74    margin: Option<i32>,
75    margin_bottom: Option<i32>,
76    margin_end: Option<i32>,
77    margin_start: Option<i32>,
78    margin_top: Option<i32>,
79    name: Option<String>,
80    no_show_all: Option<bool>,
81    opacity: Option<f64>,
82    parent: Option<Container>,
83    receives_default: Option<bool>,
84    sensitive: Option<bool>,
85    //style: /*Unknown type*/,
86    tooltip_markup: Option<String>,
87    tooltip_text: Option<String>,
88    valign: Option<Align>,
89    vexpand: Option<bool>,
90    vexpand_set: Option<bool>,
91    visible: Option<bool>,
92    width_request: Option<i32>,
93}
94
95impl LayoutBuilder {
96    pub fn new() -> Self {
97        Self {
98            height: None,
99            width: None,
100            border_width: None,
101            child: None,
102            resize_mode: None,
103            app_paintable: None,
104            can_default: None,
105            can_focus: None,
106            events: None,
107            expand: None,
108            #[cfg(any(feature = "v3_20", feature = "dox"))]
109            focus_on_click: None,
110            halign: None,
111            has_default: None,
112            has_focus: None,
113            has_tooltip: None,
114            height_request: None,
115            hexpand: None,
116            hexpand_set: None,
117            is_focus: None,
118            margin: None,
119            margin_bottom: None,
120            margin_end: None,
121            margin_start: None,
122            margin_top: None,
123            name: None,
124            no_show_all: None,
125            opacity: None,
126            parent: None,
127            receives_default: None,
128            sensitive: None,
129            tooltip_markup: None,
130            tooltip_text: None,
131            valign: None,
132            vexpand: None,
133            vexpand_set: None,
134            visible: None,
135            width_request: None,
136        }
137    }
138
139    pub fn build(self) -> Layout {
140        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
141        if let Some(ref height) = self.height {
142            properties.push(("height", height));
143        }
144        if let Some(ref width) = self.width {
145            properties.push(("width", width));
146        }
147        if let Some(ref border_width) = self.border_width {
148            properties.push(("border-width", border_width));
149        }
150        if let Some(ref child) = self.child {
151            properties.push(("child", child));
152        }
153        if let Some(ref resize_mode) = self.resize_mode {
154            properties.push(("resize-mode", resize_mode));
155        }
156        if let Some(ref app_paintable) = self.app_paintable {
157            properties.push(("app-paintable", app_paintable));
158        }
159        if let Some(ref can_default) = self.can_default {
160            properties.push(("can-default", can_default));
161        }
162        if let Some(ref can_focus) = self.can_focus {
163            properties.push(("can-focus", can_focus));
164        }
165        if let Some(ref events) = self.events {
166            properties.push(("events", events));
167        }
168        if let Some(ref expand) = self.expand {
169            properties.push(("expand", expand));
170        }
171        #[cfg(any(feature = "v3_20", feature = "dox"))]
172        {
173            if let Some(ref focus_on_click) = self.focus_on_click {
174                properties.push(("focus-on-click", focus_on_click));
175            }
176        }
177        if let Some(ref halign) = self.halign {
178            properties.push(("halign", halign));
179        }
180        if let Some(ref has_default) = self.has_default {
181            properties.push(("has-default", has_default));
182        }
183        if let Some(ref has_focus) = self.has_focus {
184            properties.push(("has-focus", has_focus));
185        }
186        if let Some(ref has_tooltip) = self.has_tooltip {
187            properties.push(("has-tooltip", has_tooltip));
188        }
189        if let Some(ref height_request) = self.height_request {
190            properties.push(("height-request", height_request));
191        }
192        if let Some(ref hexpand) = self.hexpand {
193            properties.push(("hexpand", hexpand));
194        }
195        if let Some(ref hexpand_set) = self.hexpand_set {
196            properties.push(("hexpand-set", hexpand_set));
197        }
198        if let Some(ref is_focus) = self.is_focus {
199            properties.push(("is-focus", is_focus));
200        }
201        if let Some(ref margin) = self.margin {
202            properties.push(("margin", margin));
203        }
204        if let Some(ref margin_bottom) = self.margin_bottom {
205            properties.push(("margin-bottom", margin_bottom));
206        }
207        if let Some(ref margin_end) = self.margin_end {
208            properties.push(("margin-end", margin_end));
209        }
210        if let Some(ref margin_start) = self.margin_start {
211            properties.push(("margin-start", margin_start));
212        }
213        if let Some(ref margin_top) = self.margin_top {
214            properties.push(("margin-top", margin_top));
215        }
216        if let Some(ref name) = self.name {
217            properties.push(("name", name));
218        }
219        if let Some(ref no_show_all) = self.no_show_all {
220            properties.push(("no-show-all", no_show_all));
221        }
222        if let Some(ref opacity) = self.opacity {
223            properties.push(("opacity", opacity));
224        }
225        if let Some(ref parent) = self.parent {
226            properties.push(("parent", parent));
227        }
228        if let Some(ref receives_default) = self.receives_default {
229            properties.push(("receives-default", receives_default));
230        }
231        if let Some(ref sensitive) = self.sensitive {
232            properties.push(("sensitive", sensitive));
233        }
234        if let Some(ref tooltip_markup) = self.tooltip_markup {
235            properties.push(("tooltip-markup", tooltip_markup));
236        }
237        if let Some(ref tooltip_text) = self.tooltip_text {
238            properties.push(("tooltip-text", tooltip_text));
239        }
240        if let Some(ref valign) = self.valign {
241            properties.push(("valign", valign));
242        }
243        if let Some(ref vexpand) = self.vexpand {
244            properties.push(("vexpand", vexpand));
245        }
246        if let Some(ref vexpand_set) = self.vexpand_set {
247            properties.push(("vexpand-set", vexpand_set));
248        }
249        if let Some(ref visible) = self.visible {
250            properties.push(("visible", visible));
251        }
252        if let Some(ref width_request) = self.width_request {
253            properties.push(("width-request", width_request));
254        }
255        glib::Object::new(Layout::static_type(), &properties)
256            .expect("object new")
257            .downcast()
258            .expect("downcast")
259    }
260
261    pub fn height(mut self, height: u32) -> Self {
262        self.height = Some(height);
263        self
264    }
265
266    pub fn width(mut self, width: u32) -> Self {
267        self.width = Some(width);
268        self
269    }
270
271    pub fn border_width(mut self, border_width: u32) -> Self {
272        self.border_width = Some(border_width);
273        self
274    }
275
276    pub fn child(mut self, child: &Widget) -> Self {
277        self.child = Some(child.clone());
278        self
279    }
280
281    pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
282        self.resize_mode = Some(resize_mode);
283        self
284    }
285
286    pub fn app_paintable(mut self, app_paintable: bool) -> Self {
287        self.app_paintable = Some(app_paintable);
288        self
289    }
290
291    pub fn can_default(mut self, can_default: bool) -> Self {
292        self.can_default = Some(can_default);
293        self
294    }
295
296    pub fn can_focus(mut self, can_focus: bool) -> Self {
297        self.can_focus = Some(can_focus);
298        self
299    }
300
301    pub fn events(mut self, events: gdk::EventMask) -> Self {
302        self.events = Some(events);
303        self
304    }
305
306    pub fn expand(mut self, expand: bool) -> Self {
307        self.expand = Some(expand);
308        self
309    }
310
311    #[cfg(any(feature = "v3_20", feature = "dox"))]
312    pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
313        self.focus_on_click = Some(focus_on_click);
314        self
315    }
316
317    pub fn halign(mut self, halign: Align) -> Self {
318        self.halign = Some(halign);
319        self
320    }
321
322    pub fn has_default(mut self, has_default: bool) -> Self {
323        self.has_default = Some(has_default);
324        self
325    }
326
327    pub fn has_focus(mut self, has_focus: bool) -> Self {
328        self.has_focus = Some(has_focus);
329        self
330    }
331
332    pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
333        self.has_tooltip = Some(has_tooltip);
334        self
335    }
336
337    pub fn height_request(mut self, height_request: i32) -> Self {
338        self.height_request = Some(height_request);
339        self
340    }
341
342    pub fn hexpand(mut self, hexpand: bool) -> Self {
343        self.hexpand = Some(hexpand);
344        self
345    }
346
347    pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
348        self.hexpand_set = Some(hexpand_set);
349        self
350    }
351
352    pub fn is_focus(mut self, is_focus: bool) -> Self {
353        self.is_focus = Some(is_focus);
354        self
355    }
356
357    pub fn margin(mut self, margin: i32) -> Self {
358        self.margin = Some(margin);
359        self
360    }
361
362    pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
363        self.margin_bottom = Some(margin_bottom);
364        self
365    }
366
367    pub fn margin_end(mut self, margin_end: i32) -> Self {
368        self.margin_end = Some(margin_end);
369        self
370    }
371
372    pub fn margin_start(mut self, margin_start: i32) -> Self {
373        self.margin_start = Some(margin_start);
374        self
375    }
376
377    pub fn margin_top(mut self, margin_top: i32) -> Self {
378        self.margin_top = Some(margin_top);
379        self
380    }
381
382    pub fn name(mut self, name: &str) -> Self {
383        self.name = Some(name.to_string());
384        self
385    }
386
387    pub fn no_show_all(mut self, no_show_all: bool) -> Self {
388        self.no_show_all = Some(no_show_all);
389        self
390    }
391
392    pub fn opacity(mut self, opacity: f64) -> Self {
393        self.opacity = Some(opacity);
394        self
395    }
396
397    pub fn parent(mut self, parent: &Container) -> Self {
398        self.parent = Some(parent.clone());
399        self
400    }
401
402    pub fn receives_default(mut self, receives_default: bool) -> Self {
403        self.receives_default = Some(receives_default);
404        self
405    }
406
407    pub fn sensitive(mut self, sensitive: bool) -> Self {
408        self.sensitive = Some(sensitive);
409        self
410    }
411
412    pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
413        self.tooltip_markup = Some(tooltip_markup.to_string());
414        self
415    }
416
417    pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
418        self.tooltip_text = Some(tooltip_text.to_string());
419        self
420    }
421
422    pub fn valign(mut self, valign: Align) -> Self {
423        self.valign = Some(valign);
424        self
425    }
426
427    pub fn vexpand(mut self, vexpand: bool) -> Self {
428        self.vexpand = Some(vexpand);
429        self
430    }
431
432    pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
433        self.vexpand_set = Some(vexpand_set);
434        self
435    }
436
437    pub fn visible(mut self, visible: bool) -> Self {
438        self.visible = Some(visible);
439        self
440    }
441
442    pub fn width_request(mut self, width_request: i32) -> Self {
443        self.width_request = Some(width_request);
444        self
445    }
446}
447
448pub const NONE_LAYOUT: Option<&Layout> = None;
449
450pub trait LayoutExt: 'static {
451    fn get_bin_window(&self) -> Option<gdk::Window>;
452
453    fn get_size(&self) -> (u32, u32);
454
455    fn move_<P: IsA<Widget>>(&self, child_widget: &P, x: i32, y: i32);
456
457    fn put<P: IsA<Widget>>(&self, child_widget: &P, x: i32, y: i32);
458
459    fn set_size(&self, width: u32, height: u32);
460
461    fn get_property_height(&self) -> u32;
462
463    fn set_property_height(&self, height: u32);
464
465    fn get_property_width(&self) -> u32;
466
467    fn set_property_width(&self, width: u32);
468
469    fn get_child_x<T: IsA<Widget>>(&self, item: &T) -> i32;
470
471    fn set_child_x<T: IsA<Widget>>(&self, item: &T, x: i32);
472
473    fn get_child_y<T: IsA<Widget>>(&self, item: &T) -> i32;
474
475    fn set_child_y<T: IsA<Widget>>(&self, item: &T, y: i32);
476
477    fn connect_property_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
478
479    fn connect_property_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
480}
481
482impl<O: IsA<Layout>> LayoutExt for O {
483    fn get_bin_window(&self) -> Option<gdk::Window> {
484        unsafe {
485            from_glib_none(gtk_sys::gtk_layout_get_bin_window(
486                self.as_ref().to_glib_none().0,
487            ))
488        }
489    }
490
491    fn get_size(&self) -> (u32, u32) {
492        unsafe {
493            let mut width = mem::uninitialized();
494            let mut height = mem::uninitialized();
495            gtk_sys::gtk_layout_get_size(self.as_ref().to_glib_none().0, &mut width, &mut height);
496            (width, height)
497        }
498    }
499
500    fn move_<P: IsA<Widget>>(&self, child_widget: &P, x: i32, y: i32) {
501        unsafe {
502            gtk_sys::gtk_layout_move(
503                self.as_ref().to_glib_none().0,
504                child_widget.as_ref().to_glib_none().0,
505                x,
506                y,
507            );
508        }
509    }
510
511    fn put<P: IsA<Widget>>(&self, child_widget: &P, x: i32, y: i32) {
512        unsafe {
513            gtk_sys::gtk_layout_put(
514                self.as_ref().to_glib_none().0,
515                child_widget.as_ref().to_glib_none().0,
516                x,
517                y,
518            );
519        }
520    }
521
522    fn set_size(&self, width: u32, height: u32) {
523        unsafe {
524            gtk_sys::gtk_layout_set_size(self.as_ref().to_glib_none().0, width, height);
525        }
526    }
527
528    fn get_property_height(&self) -> u32 {
529        unsafe {
530            let mut value = Value::from_type(<u32 as StaticType>::static_type());
531            gobject_sys::g_object_get_property(
532                self.to_glib_none().0 as *mut gobject_sys::GObject,
533                b"height\0".as_ptr() as *const _,
534                value.to_glib_none_mut().0,
535            );
536            value.get().unwrap()
537        }
538    }
539
540    fn set_property_height(&self, height: u32) {
541        unsafe {
542            gobject_sys::g_object_set_property(
543                self.to_glib_none().0 as *mut gobject_sys::GObject,
544                b"height\0".as_ptr() as *const _,
545                Value::from(&height).to_glib_none().0,
546            );
547        }
548    }
549
550    fn get_property_width(&self) -> u32 {
551        unsafe {
552            let mut value = Value::from_type(<u32 as StaticType>::static_type());
553            gobject_sys::g_object_get_property(
554                self.to_glib_none().0 as *mut gobject_sys::GObject,
555                b"width\0".as_ptr() as *const _,
556                value.to_glib_none_mut().0,
557            );
558            value.get().unwrap()
559        }
560    }
561
562    fn set_property_width(&self, width: u32) {
563        unsafe {
564            gobject_sys::g_object_set_property(
565                self.to_glib_none().0 as *mut gobject_sys::GObject,
566                b"width\0".as_ptr() as *const _,
567                Value::from(&width).to_glib_none().0,
568            );
569        }
570    }
571
572    fn get_child_x<T: IsA<Widget>>(&self, item: &T) -> i32 {
573        unsafe {
574            let mut value = Value::from_type(<i32 as StaticType>::static_type());
575            gtk_sys::gtk_container_child_get_property(
576                self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
577                item.to_glib_none().0 as *mut _,
578                b"x\0".as_ptr() as *const _,
579                value.to_glib_none_mut().0,
580            );
581            value.get().unwrap()
582        }
583    }
584
585    fn set_child_x<T: IsA<Widget>>(&self, item: &T, x: i32) {
586        unsafe {
587            gtk_sys::gtk_container_child_set_property(
588                self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
589                item.to_glib_none().0 as *mut _,
590                b"x\0".as_ptr() as *const _,
591                Value::from(&x).to_glib_none().0,
592            );
593        }
594    }
595
596    fn get_child_y<T: IsA<Widget>>(&self, item: &T) -> i32 {
597        unsafe {
598            let mut value = Value::from_type(<i32 as StaticType>::static_type());
599            gtk_sys::gtk_container_child_get_property(
600                self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
601                item.to_glib_none().0 as *mut _,
602                b"y\0".as_ptr() as *const _,
603                value.to_glib_none_mut().0,
604            );
605            value.get().unwrap()
606        }
607    }
608
609    fn set_child_y<T: IsA<Widget>>(&self, item: &T, y: i32) {
610        unsafe {
611            gtk_sys::gtk_container_child_set_property(
612                self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
613                item.to_glib_none().0 as *mut _,
614                b"y\0".as_ptr() as *const _,
615                Value::from(&y).to_glib_none().0,
616            );
617        }
618    }
619
620    fn connect_property_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
621        unsafe extern "C" fn notify_height_trampoline<P, F: Fn(&P) + 'static>(
622            this: *mut gtk_sys::GtkLayout,
623            _param_spec: glib_sys::gpointer,
624            f: glib_sys::gpointer,
625        ) where
626            P: IsA<Layout>,
627        {
628            let f: &F = &*(f as *const F);
629            f(&Layout::from_glib_borrow(this).unsafe_cast())
630        }
631        unsafe {
632            let f: Box_<F> = Box_::new(f);
633            connect_raw(
634                self.as_ptr() as *mut _,
635                b"notify::height\0".as_ptr() as *const _,
636                Some(transmute(notify_height_trampoline::<Self, F> as usize)),
637                Box_::into_raw(f),
638            )
639        }
640    }
641
642    fn connect_property_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
643        unsafe extern "C" fn notify_width_trampoline<P, F: Fn(&P) + 'static>(
644            this: *mut gtk_sys::GtkLayout,
645            _param_spec: glib_sys::gpointer,
646            f: glib_sys::gpointer,
647        ) where
648            P: IsA<Layout>,
649        {
650            let f: &F = &*(f as *const F);
651            f(&Layout::from_glib_borrow(this).unsafe_cast())
652        }
653        unsafe {
654            let f: Box_<F> = Box_::new(f);
655            connect_raw(
656                self.as_ptr() as *mut _,
657                b"notify::width\0".as_ptr() as *const _,
658                Some(transmute(notify_width_trampoline::<Self, F> as usize)),
659                Box_::into_raw(f),
660            )
661        }
662    }
663}
664
665impl fmt::Display for Layout {
666    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
667        write!(f, "Layout")
668    }
669}