1use crate::{ffi, Layout};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwMultiLayoutView")]
16 pub struct MultiLayoutView(Object<ffi::AdwMultiLayoutView, ffi::AdwMultiLayoutViewClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::adw_multi_layout_view_get_type(),
20 }
21}
22
23impl MultiLayoutView {
24 #[doc(alias = "adw_multi_layout_view_new")]
25 pub fn new() -> MultiLayoutView {
26 assert_initialized_main_thread!();
27 unsafe { gtk::Widget::from_glib_none(ffi::adw_multi_layout_view_new()).unsafe_cast() }
28 }
29
30 pub fn builder() -> MultiLayoutViewBuilder {
35 MultiLayoutViewBuilder::new()
36 }
37
38 #[doc(alias = "adw_multi_layout_view_add_layout")]
39 pub fn add_layout(&self, layout: Layout) {
40 unsafe {
41 ffi::adw_multi_layout_view_add_layout(self.to_glib_none().0, layout.into_glib_ptr());
42 }
43 }
44
45 #[doc(alias = "adw_multi_layout_view_get_child")]
46 #[doc(alias = "get_child")]
47 pub fn child(&self, id: &str) -> Option<gtk::Widget> {
48 unsafe {
49 from_glib_none(ffi::adw_multi_layout_view_get_child(
50 self.to_glib_none().0,
51 id.to_glib_none().0,
52 ))
53 }
54 }
55
56 #[doc(alias = "adw_multi_layout_view_get_layout")]
57 #[doc(alias = "get_layout")]
58 pub fn layout(&self) -> Option<Layout> {
59 unsafe { from_glib_none(ffi::adw_multi_layout_view_get_layout(self.to_glib_none().0)) }
60 }
61
62 #[doc(alias = "adw_multi_layout_view_get_layout_by_name")]
63 #[doc(alias = "get_layout_by_name")]
64 pub fn layout_by_name(&self, name: &str) -> Option<Layout> {
65 unsafe {
66 from_glib_none(ffi::adw_multi_layout_view_get_layout_by_name(
67 self.to_glib_none().0,
68 name.to_glib_none().0,
69 ))
70 }
71 }
72
73 #[doc(alias = "adw_multi_layout_view_get_layout_name")]
74 #[doc(alias = "get_layout_name")]
75 #[doc(alias = "layout-name")]
76 pub fn layout_name(&self) -> Option<glib::GString> {
77 unsafe {
78 from_glib_none(ffi::adw_multi_layout_view_get_layout_name(
79 self.to_glib_none().0,
80 ))
81 }
82 }
83
84 #[doc(alias = "adw_multi_layout_view_remove_layout")]
85 pub fn remove_layout(&self, layout: &Layout) {
86 unsafe {
87 ffi::adw_multi_layout_view_remove_layout(
88 self.to_glib_none().0,
89 layout.to_glib_none().0,
90 );
91 }
92 }
93
94 #[doc(alias = "adw_multi_layout_view_set_child")]
95 pub fn set_child(&self, id: &str, child: &impl IsA<gtk::Widget>) {
96 unsafe {
97 ffi::adw_multi_layout_view_set_child(
98 self.to_glib_none().0,
99 id.to_glib_none().0,
100 child.as_ref().to_glib_none().0,
101 );
102 }
103 }
104
105 #[doc(alias = "adw_multi_layout_view_set_layout")]
106 #[doc(alias = "layout")]
107 pub fn set_layout(&self, layout: &Layout) {
108 unsafe {
109 ffi::adw_multi_layout_view_set_layout(self.to_glib_none().0, layout.to_glib_none().0);
110 }
111 }
112
113 #[doc(alias = "adw_multi_layout_view_set_layout_name")]
114 #[doc(alias = "layout-name")]
115 pub fn set_layout_name(&self, name: &str) {
116 unsafe {
117 ffi::adw_multi_layout_view_set_layout_name(
118 self.to_glib_none().0,
119 name.to_glib_none().0,
120 );
121 }
122 }
123
124 #[cfg(feature = "v1_6")]
125 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
126 #[doc(alias = "layout")]
127 pub fn connect_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128 unsafe extern "C" fn notify_layout_trampoline<F: Fn(&MultiLayoutView) + 'static>(
129 this: *mut ffi::AdwMultiLayoutView,
130 _param_spec: glib::ffi::gpointer,
131 f: glib::ffi::gpointer,
132 ) {
133 let f: &F = &*(f as *const F);
134 f(&from_glib_borrow(this))
135 }
136 unsafe {
137 let f: Box_<F> = Box_::new(f);
138 connect_raw(
139 self.as_ptr() as *mut _,
140 c"notify::layout".as_ptr() as *const _,
141 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
142 notify_layout_trampoline::<F> as *const (),
143 )),
144 Box_::into_raw(f),
145 )
146 }
147 }
148
149 #[cfg(feature = "v1_6")]
150 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
151 #[doc(alias = "layout-name")]
152 pub fn connect_layout_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
153 unsafe extern "C" fn notify_layout_name_trampoline<F: Fn(&MultiLayoutView) + 'static>(
154 this: *mut ffi::AdwMultiLayoutView,
155 _param_spec: glib::ffi::gpointer,
156 f: glib::ffi::gpointer,
157 ) {
158 let f: &F = &*(f as *const F);
159 f(&from_glib_borrow(this))
160 }
161 unsafe {
162 let f: Box_<F> = Box_::new(f);
163 connect_raw(
164 self.as_ptr() as *mut _,
165 c"notify::layout-name".as_ptr() as *const _,
166 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
167 notify_layout_name_trampoline::<F> as *const (),
168 )),
169 Box_::into_raw(f),
170 )
171 }
172 }
173}
174
175#[cfg(feature = "v1_6")]
176#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
177impl Default for MultiLayoutView {
178 fn default() -> Self {
179 Self::new()
180 }
181}
182
183#[must_use = "The builder must be built to be used"]
188pub struct MultiLayoutViewBuilder {
189 builder: glib::object::ObjectBuilder<'static, MultiLayoutView>,
190}
191
192impl MultiLayoutViewBuilder {
193 fn new() -> Self {
194 Self {
195 builder: glib::object::Object::builder(),
196 }
197 }
198
199 #[cfg(feature = "v1_6")]
200 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
201 pub fn layout(self, layout: &Layout) -> Self {
202 Self {
203 builder: self.builder.property("layout", layout.clone()),
204 }
205 }
206
207 #[cfg(feature = "v1_6")]
208 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
209 pub fn layout_name(self, layout_name: impl Into<glib::GString>) -> Self {
210 Self {
211 builder: self.builder.property("layout-name", layout_name.into()),
212 }
213 }
214
215 pub fn can_focus(self, can_focus: bool) -> Self {
216 Self {
217 builder: self.builder.property("can-focus", can_focus),
218 }
219 }
220
221 pub fn can_target(self, can_target: bool) -> Self {
222 Self {
223 builder: self.builder.property("can-target", can_target),
224 }
225 }
226
227 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
228 Self {
229 builder: self.builder.property("css-classes", css_classes.into()),
230 }
231 }
232
233 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
234 Self {
235 builder: self.builder.property("css-name", css_name.into()),
236 }
237 }
238
239 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
240 Self {
241 builder: self.builder.property("cursor", cursor.clone()),
242 }
243 }
244
245 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
246 Self {
247 builder: self.builder.property("focus-on-click", focus_on_click),
248 }
249 }
250
251 pub fn focusable(self, focusable: bool) -> Self {
252 Self {
253 builder: self.builder.property("focusable", focusable),
254 }
255 }
256
257 pub fn halign(self, halign: gtk::Align) -> Self {
258 Self {
259 builder: self.builder.property("halign", halign),
260 }
261 }
262
263 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
264 Self {
265 builder: self.builder.property("has-tooltip", has_tooltip),
266 }
267 }
268
269 pub fn height_request(self, height_request: i32) -> Self {
270 Self {
271 builder: self.builder.property("height-request", height_request),
272 }
273 }
274
275 pub fn hexpand(self, hexpand: bool) -> Self {
276 Self {
277 builder: self.builder.property("hexpand", hexpand),
278 }
279 }
280
281 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
282 Self {
283 builder: self.builder.property("hexpand-set", hexpand_set),
284 }
285 }
286
287 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
288 Self {
289 builder: self
290 .builder
291 .property("layout-manager", layout_manager.clone().upcast()),
292 }
293 }
294
295 #[cfg(feature = "gtk_v4_18")]
296 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
297 pub fn limit_events(self, limit_events: bool) -> Self {
298 Self {
299 builder: self.builder.property("limit-events", limit_events),
300 }
301 }
302
303 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
304 Self {
305 builder: self.builder.property("margin-bottom", margin_bottom),
306 }
307 }
308
309 pub fn margin_end(self, margin_end: i32) -> Self {
310 Self {
311 builder: self.builder.property("margin-end", margin_end),
312 }
313 }
314
315 pub fn margin_start(self, margin_start: i32) -> Self {
316 Self {
317 builder: self.builder.property("margin-start", margin_start),
318 }
319 }
320
321 pub fn margin_top(self, margin_top: i32) -> Self {
322 Self {
323 builder: self.builder.property("margin-top", margin_top),
324 }
325 }
326
327 pub fn name(self, name: impl Into<glib::GString>) -> Self {
328 Self {
329 builder: self.builder.property("name", name.into()),
330 }
331 }
332
333 pub fn opacity(self, opacity: f64) -> Self {
334 Self {
335 builder: self.builder.property("opacity", opacity),
336 }
337 }
338
339 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
340 Self {
341 builder: self.builder.property("overflow", overflow),
342 }
343 }
344
345 pub fn receives_default(self, receives_default: bool) -> Self {
346 Self {
347 builder: self.builder.property("receives-default", receives_default),
348 }
349 }
350
351 pub fn sensitive(self, sensitive: bool) -> Self {
352 Self {
353 builder: self.builder.property("sensitive", sensitive),
354 }
355 }
356
357 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
358 Self {
359 builder: self
360 .builder
361 .property("tooltip-markup", tooltip_markup.into()),
362 }
363 }
364
365 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
366 Self {
367 builder: self.builder.property("tooltip-text", tooltip_text.into()),
368 }
369 }
370
371 pub fn valign(self, valign: gtk::Align) -> Self {
372 Self {
373 builder: self.builder.property("valign", valign),
374 }
375 }
376
377 pub fn vexpand(self, vexpand: bool) -> Self {
378 Self {
379 builder: self.builder.property("vexpand", vexpand),
380 }
381 }
382
383 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
384 Self {
385 builder: self.builder.property("vexpand-set", vexpand_set),
386 }
387 }
388
389 pub fn visible(self, visible: bool) -> Self {
390 Self {
391 builder: self.builder.property("visible", visible),
392 }
393 }
394
395 pub fn width_request(self, width_request: i32) -> Self {
396 Self {
397 builder: self.builder.property("width-request", width_request),
398 }
399 }
400
401 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
402 Self {
403 builder: self.builder.property("accessible-role", accessible_role),
404 }
405 }
406
407 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
410 pub fn build(self) -> MultiLayoutView {
411 assert_initialized_main_thread!();
412 self.builder.build()
413 }
414}