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")]
15 pub struct ConstraintGuide(Object<ffi::GtkConstraintGuide, ffi::GtkConstraintGuideClass>) @implements ConstraintTarget;
16
17 match fn {
18 type_ => || ffi::gtk_constraint_guide_get_type(),
19 }
20}
21
22impl ConstraintGuide {
23 #[doc(alias = "gtk_constraint_guide_new")]
24 pub fn new() -> ConstraintGuide {
25 assert_initialized_main_thread!();
26 unsafe { from_glib_full(ffi::gtk_constraint_guide_new()) }
27 }
28
29 pub fn builder() -> ConstraintGuideBuilder {
34 ConstraintGuideBuilder::new()
35 }
36
37 #[doc(alias = "gtk_constraint_guide_get_name")]
38 #[doc(alias = "get_name")]
39 pub fn name(&self) -> Option<glib::GString> {
40 unsafe { from_glib_none(ffi::gtk_constraint_guide_get_name(self.to_glib_none().0)) }
41 }
42
43 #[doc(alias = "gtk_constraint_guide_get_strength")]
44 #[doc(alias = "get_strength")]
45 pub fn strength(&self) -> ConstraintStrength {
46 unsafe {
47 from_glib(ffi::gtk_constraint_guide_get_strength(
48 self.to_glib_none().0,
49 ))
50 }
51 }
52
53 #[doc(alias = "gtk_constraint_guide_set_max_size")]
54 pub fn set_max_size(&self, width: i32, height: i32) {
55 unsafe {
56 ffi::gtk_constraint_guide_set_max_size(self.to_glib_none().0, width, height);
57 }
58 }
59
60 #[doc(alias = "gtk_constraint_guide_set_min_size")]
61 pub fn set_min_size(&self, width: i32, height: i32) {
62 unsafe {
63 ffi::gtk_constraint_guide_set_min_size(self.to_glib_none().0, width, height);
64 }
65 }
66
67 #[doc(alias = "gtk_constraint_guide_set_name")]
68 #[doc(alias = "name")]
69 pub fn set_name(&self, name: Option<&str>) {
70 unsafe {
71 ffi::gtk_constraint_guide_set_name(self.to_glib_none().0, name.to_glib_none().0);
72 }
73 }
74
75 #[doc(alias = "gtk_constraint_guide_set_nat_size")]
76 pub fn set_nat_size(&self, width: i32, height: i32) {
77 unsafe {
78 ffi::gtk_constraint_guide_set_nat_size(self.to_glib_none().0, width, height);
79 }
80 }
81
82 #[doc(alias = "gtk_constraint_guide_set_strength")]
83 #[doc(alias = "strength")]
84 pub fn set_strength(&self, strength: ConstraintStrength) {
85 unsafe {
86 ffi::gtk_constraint_guide_set_strength(self.to_glib_none().0, strength.into_glib());
87 }
88 }
89
90 #[doc(alias = "max-height")]
91 pub fn max_height(&self) -> i32 {
92 ObjectExt::property(self, "max-height")
93 }
94
95 #[doc(alias = "max-height")]
96 pub fn set_max_height(&self, max_height: i32) {
97 ObjectExt::set_property(self, "max-height", max_height)
98 }
99
100 #[doc(alias = "max-width")]
101 pub fn max_width(&self) -> i32 {
102 ObjectExt::property(self, "max-width")
103 }
104
105 #[doc(alias = "max-width")]
106 pub fn set_max_width(&self, max_width: i32) {
107 ObjectExt::set_property(self, "max-width", max_width)
108 }
109
110 #[doc(alias = "min-height")]
111 pub fn min_height(&self) -> i32 {
112 ObjectExt::property(self, "min-height")
113 }
114
115 #[doc(alias = "min-height")]
116 pub fn set_min_height(&self, min_height: i32) {
117 ObjectExt::set_property(self, "min-height", min_height)
118 }
119
120 #[doc(alias = "min-width")]
121 pub fn min_width(&self) -> i32 {
122 ObjectExt::property(self, "min-width")
123 }
124
125 #[doc(alias = "min-width")]
126 pub fn set_min_width(&self, min_width: i32) {
127 ObjectExt::set_property(self, "min-width", min_width)
128 }
129
130 #[doc(alias = "nat-height")]
131 pub fn nat_height(&self) -> i32 {
132 ObjectExt::property(self, "nat-height")
133 }
134
135 #[doc(alias = "nat-height")]
136 pub fn set_nat_height(&self, nat_height: i32) {
137 ObjectExt::set_property(self, "nat-height", nat_height)
138 }
139
140 #[doc(alias = "nat-width")]
141 pub fn nat_width(&self) -> i32 {
142 ObjectExt::property(self, "nat-width")
143 }
144
145 #[doc(alias = "nat-width")]
146 pub fn set_nat_width(&self, nat_width: i32) {
147 ObjectExt::set_property(self, "nat-width", nat_width)
148 }
149
150 #[doc(alias = "max-height")]
151 pub fn connect_max_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
152 unsafe extern "C" fn notify_max_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
153 this: *mut ffi::GtkConstraintGuide,
154 _param_spec: glib::ffi::gpointer,
155 f: glib::ffi::gpointer,
156 ) {
157 let f: &F = &*(f as *const F);
158 f(&from_glib_borrow(this))
159 }
160 unsafe {
161 let f: Box_<F> = Box_::new(f);
162 connect_raw(
163 self.as_ptr() as *mut _,
164 c"notify::max-height".as_ptr() as *const _,
165 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
166 notify_max_height_trampoline::<F> as *const (),
167 )),
168 Box_::into_raw(f),
169 )
170 }
171 }
172
173 #[doc(alias = "max-width")]
174 pub fn connect_max_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
175 unsafe extern "C" fn notify_max_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
176 this: *mut ffi::GtkConstraintGuide,
177 _param_spec: glib::ffi::gpointer,
178 f: glib::ffi::gpointer,
179 ) {
180 let f: &F = &*(f as *const F);
181 f(&from_glib_borrow(this))
182 }
183 unsafe {
184 let f: Box_<F> = Box_::new(f);
185 connect_raw(
186 self.as_ptr() as *mut _,
187 c"notify::max-width".as_ptr() as *const _,
188 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
189 notify_max_width_trampoline::<F> as *const (),
190 )),
191 Box_::into_raw(f),
192 )
193 }
194 }
195
196 #[doc(alias = "min-height")]
197 pub fn connect_min_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
198 unsafe extern "C" fn notify_min_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
199 this: *mut ffi::GtkConstraintGuide,
200 _param_spec: glib::ffi::gpointer,
201 f: glib::ffi::gpointer,
202 ) {
203 let f: &F = &*(f as *const F);
204 f(&from_glib_borrow(this))
205 }
206 unsafe {
207 let f: Box_<F> = Box_::new(f);
208 connect_raw(
209 self.as_ptr() as *mut _,
210 c"notify::min-height".as_ptr() as *const _,
211 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
212 notify_min_height_trampoline::<F> as *const (),
213 )),
214 Box_::into_raw(f),
215 )
216 }
217 }
218
219 #[doc(alias = "min-width")]
220 pub fn connect_min_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
221 unsafe extern "C" fn notify_min_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
222 this: *mut ffi::GtkConstraintGuide,
223 _param_spec: glib::ffi::gpointer,
224 f: glib::ffi::gpointer,
225 ) {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this))
228 }
229 unsafe {
230 let f: Box_<F> = Box_::new(f);
231 connect_raw(
232 self.as_ptr() as *mut _,
233 c"notify::min-width".as_ptr() as *const _,
234 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235 notify_min_width_trampoline::<F> as *const (),
236 )),
237 Box_::into_raw(f),
238 )
239 }
240 }
241
242 #[doc(alias = "name")]
243 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244 unsafe extern "C" fn notify_name_trampoline<F: Fn(&ConstraintGuide) + 'static>(
245 this: *mut ffi::GtkConstraintGuide,
246 _param_spec: glib::ffi::gpointer,
247 f: glib::ffi::gpointer,
248 ) {
249 let f: &F = &*(f as *const F);
250 f(&from_glib_borrow(this))
251 }
252 unsafe {
253 let f: Box_<F> = Box_::new(f);
254 connect_raw(
255 self.as_ptr() as *mut _,
256 c"notify::name".as_ptr() as *const _,
257 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258 notify_name_trampoline::<F> as *const (),
259 )),
260 Box_::into_raw(f),
261 )
262 }
263 }
264
265 #[doc(alias = "nat-height")]
266 pub fn connect_nat_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267 unsafe extern "C" fn notify_nat_height_trampoline<F: Fn(&ConstraintGuide) + 'static>(
268 this: *mut ffi::GtkConstraintGuide,
269 _param_spec: glib::ffi::gpointer,
270 f: glib::ffi::gpointer,
271 ) {
272 let f: &F = &*(f as *const F);
273 f(&from_glib_borrow(this))
274 }
275 unsafe {
276 let f: Box_<F> = Box_::new(f);
277 connect_raw(
278 self.as_ptr() as *mut _,
279 c"notify::nat-height".as_ptr() as *const _,
280 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
281 notify_nat_height_trampoline::<F> as *const (),
282 )),
283 Box_::into_raw(f),
284 )
285 }
286 }
287
288 #[doc(alias = "nat-width")]
289 pub fn connect_nat_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
290 unsafe extern "C" fn notify_nat_width_trampoline<F: Fn(&ConstraintGuide) + 'static>(
291 this: *mut ffi::GtkConstraintGuide,
292 _param_spec: glib::ffi::gpointer,
293 f: glib::ffi::gpointer,
294 ) {
295 let f: &F = &*(f as *const F);
296 f(&from_glib_borrow(this))
297 }
298 unsafe {
299 let f: Box_<F> = Box_::new(f);
300 connect_raw(
301 self.as_ptr() as *mut _,
302 c"notify::nat-width".as_ptr() as *const _,
303 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
304 notify_nat_width_trampoline::<F> as *const (),
305 )),
306 Box_::into_raw(f),
307 )
308 }
309 }
310
311 #[doc(alias = "strength")]
312 pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
313 unsafe extern "C" fn notify_strength_trampoline<F: Fn(&ConstraintGuide) + 'static>(
314 this: *mut ffi::GtkConstraintGuide,
315 _param_spec: glib::ffi::gpointer,
316 f: glib::ffi::gpointer,
317 ) {
318 let f: &F = &*(f as *const F);
319 f(&from_glib_borrow(this))
320 }
321 unsafe {
322 let f: Box_<F> = Box_::new(f);
323 connect_raw(
324 self.as_ptr() as *mut _,
325 c"notify::strength".as_ptr() as *const _,
326 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
327 notify_strength_trampoline::<F> as *const (),
328 )),
329 Box_::into_raw(f),
330 )
331 }
332 }
333}
334
335impl Default for ConstraintGuide {
336 fn default() -> Self {
337 Self::new()
338 }
339}
340
341#[must_use = "The builder must be built to be used"]
346pub struct ConstraintGuideBuilder {
347 builder: glib::object::ObjectBuilder<'static, ConstraintGuide>,
348}
349
350impl ConstraintGuideBuilder {
351 fn new() -> Self {
352 Self {
353 builder: glib::object::Object::builder(),
354 }
355 }
356
357 pub fn max_height(self, max_height: i32) -> Self {
358 Self {
359 builder: self.builder.property("max-height", max_height),
360 }
361 }
362
363 pub fn max_width(self, max_width: i32) -> Self {
364 Self {
365 builder: self.builder.property("max-width", max_width),
366 }
367 }
368
369 pub fn min_height(self, min_height: i32) -> Self {
370 Self {
371 builder: self.builder.property("min-height", min_height),
372 }
373 }
374
375 pub fn min_width(self, min_width: i32) -> Self {
376 Self {
377 builder: self.builder.property("min-width", min_width),
378 }
379 }
380
381 pub fn name(self, name: impl Into<glib::GString>) -> Self {
382 Self {
383 builder: self.builder.property("name", name.into()),
384 }
385 }
386
387 pub fn nat_height(self, nat_height: i32) -> Self {
388 Self {
389 builder: self.builder.property("nat-height", nat_height),
390 }
391 }
392
393 pub fn nat_width(self, nat_width: i32) -> Self {
394 Self {
395 builder: self.builder.property("nat-width", nat_width),
396 }
397 }
398
399 pub fn strength(self, strength: ConstraintStrength) -> Self {
400 Self {
401 builder: self.builder.property("strength", strength),
402 }
403 }
404
405 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
408 pub fn build(self) -> ConstraintGuide {
409 assert_initialized_main_thread!();
410 self.builder.build()
411 }
412}