1use crate::{ConstraintStrength, ConstraintTarget, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
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 unsafe {
284 let f: &F = &*(f as *const F);
285 f(&from_glib_borrow(this))
286 }
287 }
288 unsafe {
289 let f: Box_<F> = Box_::new(f);
290 connect_raw(
291 self.as_ptr() as *mut _,
292 c"notify::max-height".as_ptr() as *const _,
293 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
294 notify_max_height_trampoline::<F> as *const (),
295 )),
296 Box_::into_raw(f),
297 )
298 }
299 }
300
301 #[doc(alias = "max-width")]
302 pub fn connect_max_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
303 unsafe extern "C" fn notify_max_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
304 this: *mut ffi::GtkConstraintGuide,
305 _param_spec: glib::ffi::gpointer,
306 f: glib::ffi::gpointer,
307 ) {
308 unsafe {
309 let f: &F = &*(f as *const F);
310 f(&from_glib_borrow(this))
311 }
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"notify::max-width".as_ptr() as *const _,
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 notify_max_width_trampoline::<F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "min-height")]
327 pub fn connect_min_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328 unsafe extern "C" fn notify_min_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
329 this: *mut ffi::GtkConstraintGuide,
330 _param_spec: glib::ffi::gpointer,
331 f: glib::ffi::gpointer,
332 ) {
333 unsafe {
334 let f: &F = &*(f as *const F);
335 f(&from_glib_borrow(this))
336 }
337 }
338 unsafe {
339 let f: Box_<F> = Box_::new(f);
340 connect_raw(
341 self.as_ptr() as *mut _,
342 c"notify::min-height".as_ptr() as *const _,
343 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
344 notify_min_height_trampoline::<F> as *const (),
345 )),
346 Box_::into_raw(f),
347 )
348 }
349 }
350
351 #[doc(alias = "min-width")]
352 pub fn connect_min_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
353 unsafe extern "C" fn notify_min_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
354 this: *mut ffi::GtkConstraintGuide,
355 _param_spec: glib::ffi::gpointer,
356 f: glib::ffi::gpointer,
357 ) {
358 unsafe {
359 let f: &F = &*(f as *const F);
360 f(&from_glib_borrow(this))
361 }
362 }
363 unsafe {
364 let f: Box_<F> = Box_::new(f);
365 connect_raw(
366 self.as_ptr() as *mut _,
367 c"notify::min-width".as_ptr() as *const _,
368 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
369 notify_min_width_trampoline::<F> as *const (),
370 )),
371 Box_::into_raw(f),
372 )
373 }
374 }
375
376 #[doc(alias = "name")]
377 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
378 unsafe extern "C" fn notify_name_trampoline<F: Fn(&ConstraintGuide) + 'static>(
379 this: *mut ffi::GtkConstraintGuide,
380 _param_spec: glib::ffi::gpointer,
381 f: glib::ffi::gpointer,
382 ) {
383 unsafe {
384 let f: &F = &*(f as *const F);
385 f(&from_glib_borrow(this))
386 }
387 }
388 unsafe {
389 let f: Box_<F> = Box_::new(f);
390 connect_raw(
391 self.as_ptr() as *mut _,
392 c"notify::name".as_ptr() as *const _,
393 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
394 notify_name_trampoline::<F> as *const (),
395 )),
396 Box_::into_raw(f),
397 )
398 }
399 }
400
401 #[doc(alias = "nat-height")]
402 pub fn connect_nat_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
403 unsafe extern "C" fn notify_nat_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
404 this: *mut ffi::GtkConstraintGuide,
405 _param_spec: glib::ffi::gpointer,
406 f: glib::ffi::gpointer,
407 ) {
408 unsafe {
409 let f: &F = &*(f as *const F);
410 f(&from_glib_borrow(this))
411 }
412 }
413 unsafe {
414 let f: Box_<F> = Box_::new(f);
415 connect_raw(
416 self.as_ptr() as *mut _,
417 c"notify::nat-height".as_ptr() as *const _,
418 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
419 notify_nat_height_trampoline::<F> as *const (),
420 )),
421 Box_::into_raw(f),
422 )
423 }
424 }
425
426 #[doc(alias = "nat-width")]
427 pub fn connect_nat_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
428 unsafe extern "C" fn notify_nat_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
429 this: *mut ffi::GtkConstraintGuide,
430 _param_spec: glib::ffi::gpointer,
431 f: glib::ffi::gpointer,
432 ) {
433 unsafe {
434 let f: &F = &*(f as *const F);
435 f(&from_glib_borrow(this))
436 }
437 }
438 unsafe {
439 let f: Box_<F> = Box_::new(f);
440 connect_raw(
441 self.as_ptr() as *mut _,
442 c"notify::nat-width".as_ptr() as *const _,
443 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
444 notify_nat_width_trampoline::<F> as *const (),
445 )),
446 Box_::into_raw(f),
447 )
448 }
449 }
450
451 #[doc(alias = "strength")]
452 pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
453 unsafe extern "C" fn notify_strength_trampoline<F: Fn(&ConstraintGuide) + 'static>(
454 this: *mut ffi::GtkConstraintGuide,
455 _param_spec: glib::ffi::gpointer,
456 f: glib::ffi::gpointer,
457 ) {
458 unsafe {
459 let f: &F = &*(f as *const F);
460 f(&from_glib_borrow(this))
461 }
462 }
463 unsafe {
464 let f: Box_<F> = Box_::new(f);
465 connect_raw(
466 self.as_ptr() as *mut _,
467 c"notify::strength".as_ptr() as *const _,
468 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
469 notify_strength_trampoline::<F> as *const (),
470 )),
471 Box_::into_raw(f),
472 )
473 }
474 }
475}
476
477impl Default for ConstraintGuide {
478 fn default() -> Self {
479 Self::new()
480 }
481}
482
483#[must_use = "The builder must be built to be used"]
488pub struct ConstraintGuideBuilder {
489 builder: glib::object::ObjectBuilder<'static, ConstraintGuide>,
490}
491
492impl ConstraintGuideBuilder {
493 fn new() -> Self {
494 Self {
495 builder: glib::object::Object::builder(),
496 }
497 }
498
499 pub fn max_height(self, max_height: i32) -> Self {
501 Self {
502 builder: self.builder.property("max-height", max_height),
503 }
504 }
505
506 pub fn max_width(self, max_width: i32) -> Self {
508 Self {
509 builder: self.builder.property("max-width", max_width),
510 }
511 }
512
513 pub fn min_height(self, min_height: i32) -> Self {
515 Self {
516 builder: self.builder.property("min-height", min_height),
517 }
518 }
519
520 pub fn min_width(self, min_width: i32) -> Self {
522 Self {
523 builder: self.builder.property("min-width", min_width),
524 }
525 }
526
527 pub fn name(self, name: impl Into<glib::GString>) -> Self {
529 Self {
530 builder: self.builder.property("name", name.into()),
531 }
532 }
533
534 pub fn nat_height(self, nat_height: i32) -> Self {
536 Self {
537 builder: self.builder.property("nat-height", nat_height),
538 }
539 }
540
541 pub fn nat_width(self, nat_width: i32) -> Self {
543 Self {
544 builder: self.builder.property("nat-width", nat_width),
545 }
546 }
547
548 pub fn strength(self, strength: ConstraintStrength) -> Self {
551 Self {
552 builder: self.builder.property("strength", strength),
553 }
554 }
555
556 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
559 pub fn build(self) -> ConstraintGuide {
560 assert_initialized_main_thread!();
561 self.builder.build()
562 }
563}