libadwaita/auto/
breakpoint.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{ffi, BreakpointCondition};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Describes a breakpoint for [`Window`][crate::Window] or [`Dialog`][crate::Dialog].
    ///
    /// Breakpoints are used to create adaptive UI, allowing to change the layout
    /// depending on available size.
    ///
    /// Breakpoint is a size threshold, specified by its condition, as well as one or
    /// more setters.
    ///
    /// Each setter has a target object, a property and a value. When a breakpoint
    /// is applied, each setter sets the target property on their target object to
    /// the specified value, and reset it back to the original value when it's
    /// unapplied.
    ///
    /// For more complicated scenarios, [`apply`][struct@crate::Breakpoint#apply] and
    /// [`unapply`][struct@crate::Breakpoint#unapply] can be used instead.
    ///
    /// Breakpoints can be used within [`Window`][crate::Window], [`ApplicationWindow`][crate::ApplicationWindow],
    /// [`Dialog`][crate::Dialog] or [`BreakpointBin`][crate::BreakpointBin].
    ///
    /// ## [`Breakpoint`][crate::Breakpoint] as [`gtk::Buildable`][crate::gtk::Buildable]:
    ///
    /// [`Breakpoint`][crate::Breakpoint] supports specifying its condition via the `<condition>`
    /// element. The contents of the element must be a string in a format accepted by
    /// `parse()`.
    ///
    /// It also supports adding setters via the `<setter>` element. Each `<setter>`
    /// element must have the `object` attribute specifying the target object, and
    /// the `property` attribute specifying the property name. The contents of the
    /// element are used as the setter value.
    ///
    /// For `G_TYPE_OBJECT` and `G_TYPE_BOXED` derived properties, empty contents are
    /// treated as `NULL`.
    ///
    /// Setter values can be translated with the usual `translatable`, `context` and
    /// `comments` attributes.
    ///
    /// Example of an [`Breakpoint`][crate::Breakpoint] UI definition:
    ///
    /// ```xml
    /// <object class="AdwBreakpoint">
    ///   <condition>max-width: 400px</condition>
    ///   <setter object="button" property="visible">True</setter>
    ///   <setter object="box" property="orientation">vertical</setter>
    ///   <setter object="page" property="title" translatable="yes">Example</setter>
    /// </object>
    /// ```
    ///
    /// ## Properties
    ///
    ///
    /// #### `condition`
    ///  The breakpoint's condition.
    ///
    /// Readable | Writeable
    ///
    /// ## Signals
    ///
    ///
    /// #### `apply`
    ///  Emitted when the breakpoint is applied.
    ///
    /// This signal is emitted after the setters have been applied.
    ///
    ///
    ///
    ///
    /// #### `unapply`
    ///  Emitted when the breakpoint is unapplied.
    ///
    /// This signal is emitted before resetting the setter values.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`trait@gtk::prelude::BuildableExt`]
    #[doc(alias = "AdwBreakpoint")]
    pub struct Breakpoint(Object<ffi::AdwBreakpoint, ffi::AdwBreakpointClass>) @implements gtk::Buildable;

    match fn {
        type_ => || ffi::adw_breakpoint_get_type(),
    }
}

impl Breakpoint {
    /// Creates a new [`Breakpoint`][crate::Breakpoint] with @condition.
    /// ## `condition`
    /// the condition
    ///
    /// # Returns
    ///
    /// the newly created [`Breakpoint`][crate::Breakpoint]
    #[doc(alias = "adw_breakpoint_new")]
    pub fn new(condition: BreakpointCondition) -> Breakpoint {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::adw_breakpoint_new(condition.into_glib_ptr())) }
    }

    /// Adds a setter to @self.
    ///
    /// The setter will automatically set @property on @object to @value when
    /// applying the breakpoint, and set it back to its original value upon
    /// unapplying it.
    ///
    /// ::: note
    ///     Setting properties to their original values does not work for properties
    ///     that have irreversible side effects. For example, changing
    ///     [`label`][struct@crate::Gtk::Button#label] while [`icon-name`][struct@crate::Gtk::Button#icon-name] is set
    ///     will reset the icon. However, resetting the label will not set
    ///     `icon-name` to its original value.
    ///
    /// Use the [`apply`][struct@crate::Breakpoint#apply] and [`unapply`][struct@crate::Breakpoint#unapply] signals
    /// for those properties instead, as follows:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// breakpoint_apply_cb (MyWidget *self)
    /// {
    ///   gtk_button_set_icon_name (self->button, "go-previous-symbolic");
    /// }
    ///
    /// static void
    /// breakpoint_apply_cb (MyWidget *self)
    /// {
    ///   gtk_button_set_label (self->button, _("_Back"));
    /// }
    ///
    /// // ...
    ///
    /// g_signal_connect_swapped (breakpoint, "apply",
    ///                           G_CALLBACK (breakpoint_apply_cb), self);
    /// g_signal_connect_swapped (breakpoint, "unapply",
    ///                           G_CALLBACK (breakpoint_unapply_cb), self);
    /// ```
    /// ## `object`
    /// the target object
    /// ## `property`
    /// the target property
    /// ## `value`
    /// the value to set
    #[doc(alias = "adw_breakpoint_add_setter")]
    pub fn add_setter(
        &self,
        object: &impl IsA<glib::Object>,
        property: &str,
        value: Option<&glib::Value>,
    ) {
        unsafe {
            ffi::adw_breakpoint_add_setter(
                self.to_glib_none().0,
                object.as_ref().to_glib_none().0,
                property.to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    /// Gets the condition for @self.
    ///
    /// # Returns
    ///
    /// the condition
    #[doc(alias = "adw_breakpoint_get_condition")]
    #[doc(alias = "get_condition")]
    pub fn condition(&self) -> Option<BreakpointCondition> {
        unsafe { from_glib_none(ffi::adw_breakpoint_get_condition(self.to_glib_none().0)) }
    }

    /// Sets the condition for @self.
    /// ## `condition`
    /// the new condition
    #[doc(alias = "adw_breakpoint_set_condition")]
    #[doc(alias = "condition")]
    pub fn set_condition(&self, condition: Option<&BreakpointCondition>) {
        unsafe {
            ffi::adw_breakpoint_set_condition(
                self.to_glib_none().0,
                mut_override(condition.to_glib_none().0),
            );
        }
    }

    /// Emitted when the breakpoint is applied.
    ///
    /// This signal is emitted after the setters have been applied.
    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "apply")]
    pub fn connect_apply<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn apply_trampoline<F: Fn(&Breakpoint) + 'static>(
            this: *mut ffi::AdwBreakpoint,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"apply\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    apply_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the breakpoint is unapplied.
    ///
    /// This signal is emitted before resetting the setter values.
    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "unapply")]
    pub fn connect_unapply<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn unapply_trampoline<F: Fn(&Breakpoint) + 'static>(
            this: *mut ffi::AdwBreakpoint,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"unapply\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    unapply_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "condition")]
    pub fn connect_condition_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_condition_trampoline<F: Fn(&Breakpoint) + 'static>(
            this: *mut ffi::AdwBreakpoint,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::condition\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_condition_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}