1use crate::{ffi, ConstraintStrength, ConstraintTarget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkConstraintGuide")]
81 pub struct ConstraintGuide(Object<ffi::GtkConstraintGuide, ffi::GtkConstraintGuideClass>) @implements ConstraintTarget;
82
83 match fn {
84 type_ => || ffi::gtk_constraint_guide_get_type(),
85 }
86}
87
88impl ConstraintGuide {
89 #[doc(alias = "gtk_constraint_guide_new")]
95 pub fn new() -> ConstraintGuide {
96 assert_initialized_main_thread!();
97 unsafe { from_glib_full(ffi::gtk_constraint_guide_new()) }
98 }
99
100 pub fn builder() -> ConstraintGuideBuilder {
105 ConstraintGuideBuilder::new()
106 }
107
108 #[doc(alias = "gtk_constraint_guide_get_name")]
114 #[doc(alias = "get_name")]
115 pub fn name(&self) -> Option<glib::GString> {
116 unsafe { from_glib_none(ffi::gtk_constraint_guide_get_name(self.to_glib_none().0)) }
117 }
118
119 #[doc(alias = "gtk_constraint_guide_get_strength")]
125 #[doc(alias = "get_strength")]
126 pub fn strength(&self) -> ConstraintStrength {
127 unsafe {
128 from_glib(ffi::gtk_constraint_guide_get_strength(
129 self.to_glib_none().0,
130 ))
131 }
132 }
133
134 #[doc(alias = "gtk_constraint_guide_set_max_size")]
143 pub fn set_max_size(&self, width: i32, height: i32) {
144 unsafe {
145 ffi::gtk_constraint_guide_set_max_size(self.to_glib_none().0, width, height);
146 }
147 }
148
149 #[doc(alias = "gtk_constraint_guide_set_min_size")]
158 pub fn set_min_size(&self, width: i32, height: i32) {
159 unsafe {
160 ffi::gtk_constraint_guide_set_min_size(self.to_glib_none().0, width, height);
161 }
162 }
163
164 #[doc(alias = "gtk_constraint_guide_set_name")]
170 #[doc(alias = "name")]
171 pub fn set_name(&self, name: Option<&str>) {
172 unsafe {
173 ffi::gtk_constraint_guide_set_name(self.to_glib_none().0, name.to_glib_none().0);
174 }
175 }
176
177 #[doc(alias = "gtk_constraint_guide_set_nat_size")]
186 pub fn set_nat_size(&self, width: i32, height: i32) {
187 unsafe {
188 ffi::gtk_constraint_guide_set_nat_size(self.to_glib_none().0, width, height);
189 }
190 }
191
192 #[doc(alias = "gtk_constraint_guide_set_strength")]
197 #[doc(alias = "strength")]
198 pub fn set_strength(&self, strength: ConstraintStrength) {
199 unsafe {
200 ffi::gtk_constraint_guide_set_strength(self.to_glib_none().0, strength.into_glib());
201 }
202 }
203
204 #[doc(alias = "max-height")]
206 pub fn max_height(&self) -> i32 {
207 ObjectExt::property(self, "max-height")
208 }
209
210 #[doc(alias = "max-height")]
212 pub fn set_max_height(&self, max_height: i32) {
213 ObjectExt::set_property(self, "max-height", max_height)
214 }
215
216 #[doc(alias = "max-width")]
218 pub fn max_width(&self) -> i32 {
219 ObjectExt::property(self, "max-width")
220 }
221
222 #[doc(alias = "max-width")]
224 pub fn set_max_width(&self, max_width: i32) {
225 ObjectExt::set_property(self, "max-width", max_width)
226 }
227
228 #[doc(alias = "min-height")]
230 pub fn min_height(&self) -> i32 {
231 ObjectExt::property(self, "min-height")
232 }
233
234 #[doc(alias = "min-height")]
236 pub fn set_min_height(&self, min_height: i32) {
237 ObjectExt::set_property(self, "min-height", min_height)
238 }
239
240 #[doc(alias = "min-width")]
242 pub fn min_width(&self) -> i32 {
243 ObjectExt::property(self, "min-width")
244 }
245
246 #[doc(alias = "min-width")]
248 pub fn set_min_width(&self, min_width: i32) {
249 ObjectExt::set_property(self, "min-width", min_width)
250 }
251
252 #[doc(alias = "nat-height")]
254 pub fn nat_height(&self) -> i32 {
255 ObjectExt::property(self, "nat-height")
256 }
257
258 #[doc(alias = "nat-height")]
260 pub fn set_nat_height(&self, nat_height: i32) {
261 ObjectExt::set_property(self, "nat-height", nat_height)
262 }
263
264 #[doc(alias = "nat-width")]
266 pub fn nat_width(&self) -> i32 {
267 ObjectExt::property(self, "nat-width")
268 }
269
270 #[doc(alias = "nat-width")]
272 pub fn set_nat_width(&self, nat_width: i32) {
273 ObjectExt::set_property(self, "nat-width", nat_width)
274 }
275
276 #[doc(alias = "max-height")]
277 pub fn connect_max_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
278 unsafe extern "C" fn notify_max_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
279 this: *mut ffi::GtkConstraintGuide,
280 _param_spec: glib::ffi::gpointer,
281 f: glib::ffi::gpointer,
282 ) {
283 let f: &F = &*(f as *const F);
284 f(&from_glib_borrow(this))
285 }
286 unsafe {
287 let f: Box_<F> = Box_::new(f);
288 connect_raw(
289 self.as_ptr() as *mut _,
290 c"notify::max-height".as_ptr() as *const _,
291 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292 notify_max_height_trampoline::<F> as *const (),
293 )),
294 Box_::into_raw(f),
295 )
296 }
297 }
298
299 #[doc(alias = "max-width")]
300 pub fn connect_max_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
301 unsafe extern "C" fn notify_max_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
302 this: *mut ffi::GtkConstraintGuide,
303 _param_spec: glib::ffi::gpointer,
304 f: glib::ffi::gpointer,
305 ) {
306 let f: &F = &*(f as *const F);
307 f(&from_glib_borrow(this))
308 }
309 unsafe {
310 let f: Box_<F> = Box_::new(f);
311 connect_raw(
312 self.as_ptr() as *mut _,
313 c"notify::max-width".as_ptr() as *const _,
314 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315 notify_max_width_trampoline::<F> as *const (),
316 )),
317 Box_::into_raw(f),
318 )
319 }
320 }
321
322 #[doc(alias = "min-height")]
323 pub fn connect_min_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
324 unsafe extern "C" fn notify_min_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
325 this: *mut ffi::GtkConstraintGuide,
326 _param_spec: glib::ffi::gpointer,
327 f: glib::ffi::gpointer,
328 ) {
329 let f: &F = &*(f as *const F);
330 f(&from_glib_borrow(this))
331 }
332 unsafe {
333 let f: Box_<F> = Box_::new(f);
334 connect_raw(
335 self.as_ptr() as *mut _,
336 c"notify::min-height".as_ptr() as *const _,
337 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
338 notify_min_height_trampoline::<F> as *const (),
339 )),
340 Box_::into_raw(f),
341 )
342 }
343 }
344
345 #[doc(alias = "min-width")]
346 pub fn connect_min_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
347 unsafe extern "C" fn notify_min_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
348 this: *mut ffi::GtkConstraintGuide,
349 _param_spec: glib::ffi::gpointer,
350 f: glib::ffi::gpointer,
351 ) {
352 let f: &F = &*(f as *const F);
353 f(&from_glib_borrow(this))
354 }
355 unsafe {
356 let f: Box_<F> = Box_::new(f);
357 connect_raw(
358 self.as_ptr() as *mut _,
359 c"notify::min-width".as_ptr() as *const _,
360 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361 notify_min_width_trampoline::<F> as *const (),
362 )),
363 Box_::into_raw(f),
364 )
365 }
366 }
367
368 #[doc(alias = "name")]
369 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370 unsafe extern "C" fn notify_name_trampoline<F: Fn(&ConstraintGuide) + 'static>(
371 this: *mut ffi::GtkConstraintGuide,
372 _param_spec: glib::ffi::gpointer,
373 f: glib::ffi::gpointer,
374 ) {
375 let f: &F = &*(f as *const F);
376 f(&from_glib_borrow(this))
377 }
378 unsafe {
379 let f: Box_<F> = Box_::new(f);
380 connect_raw(
381 self.as_ptr() as *mut _,
382 c"notify::name".as_ptr() as *const _,
383 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
384 notify_name_trampoline::<F> as *const (),
385 )),
386 Box_::into_raw(f),
387 )
388 }
389 }
390
391 #[doc(alias = "nat-height")]
392 pub fn connect_nat_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
393 unsafe extern "C" fn notify_nat_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
394 this: *mut ffi::GtkConstraintGuide,
395 _param_spec: glib::ffi::gpointer,
396 f: glib::ffi::gpointer,
397 ) {
398 let f: &F = &*(f as *const F);
399 f(&from_glib_borrow(this))
400 }
401 unsafe {
402 let f: Box_<F> = Box_::new(f);
403 connect_raw(
404 self.as_ptr() as *mut _,
405 c"notify::nat-height".as_ptr() as *const _,
406 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
407 notify_nat_height_trampoline::<F> as *const (),
408 )),
409 Box_::into_raw(f),
410 )
411 }
412 }
413
414 #[doc(alias = "nat-width")]
415 pub fn connect_nat_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
416 unsafe extern "C" fn notify_nat_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
417 this: *mut ffi::GtkConstraintGuide,
418 _param_spec: glib::ffi::gpointer,
419 f: glib::ffi::gpointer,
420 ) {
421 let f: &F = &*(f as *const F);
422 f(&from_glib_borrow(this))
423 }
424 unsafe {
425 let f: Box_<F> = Box_::new(f);
426 connect_raw(
427 self.as_ptr() as *mut _,
428 c"notify::nat-width".as_ptr() as *const _,
429 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
430 notify_nat_width_trampoline::<F> as *const (),
431 )),
432 Box_::into_raw(f),
433 )
434 }
435 }
436
437 #[doc(alias = "strength")]
438 pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
439 unsafe extern "C" fn notify_strength_trampoline<F: Fn(&ConstraintGuide) + 'static>(
440 this: *mut ffi::GtkConstraintGuide,
441 _param_spec: glib::ffi::gpointer,
442 f: glib::ffi::gpointer,
443 ) {
444 let f: &F = &*(f as *const F);
445 f(&from_glib_borrow(this))
446 }
447 unsafe {
448 let f: Box_<F> = Box_::new(f);
449 connect_raw(
450 self.as_ptr() as *mut _,
451 c"notify::strength".as_ptr() as *const _,
452 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
453 notify_strength_trampoline::<F> as *const (),
454 )),
455 Box_::into_raw(f),
456 )
457 }
458 }
459}
460
461impl Default for ConstraintGuide {
462 fn default() -> Self {
463 Self::new()
464 }
465}
466
467#[must_use = "The builder must be built to be used"]
472pub struct ConstraintGuideBuilder {
473 builder: glib::object::ObjectBuilder<'static, ConstraintGuide>,
474}
475
476impl ConstraintGuideBuilder {
477 fn new() -> Self {
478 Self {
479 builder: glib::object::Object::builder(),
480 }
481 }
482
483 pub fn max_height(self, max_height: i32) -> Self {
485 Self {
486 builder: self.builder.property("max-height", max_height),
487 }
488 }
489
490 pub fn max_width(self, max_width: i32) -> Self {
492 Self {
493 builder: self.builder.property("max-width", max_width),
494 }
495 }
496
497 pub fn min_height(self, min_height: i32) -> Self {
499 Self {
500 builder: self.builder.property("min-height", min_height),
501 }
502 }
503
504 pub fn min_width(self, min_width: i32) -> Self {
506 Self {
507 builder: self.builder.property("min-width", min_width),
508 }
509 }
510
511 pub fn name(self, name: impl Into<glib::GString>) -> Self {
513 Self {
514 builder: self.builder.property("name", name.into()),
515 }
516 }
517
518 pub fn nat_height(self, nat_height: i32) -> Self {
520 Self {
521 builder: self.builder.property("nat-height", nat_height),
522 }
523 }
524
525 pub fn nat_width(self, nat_width: i32) -> Self {
527 Self {
528 builder: self.builder.property("nat-width", nat_width),
529 }
530 }
531
532 pub fn strength(self, strength: ConstraintStrength) -> Self {
535 Self {
536 builder: self.builder.property("strength", strength),
537 }
538 }
539
540 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
543 pub fn build(self) -> ConstraintGuide {
544 assert_initialized_main_thread!();
545 self.builder.build()
546 }
547}