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