gtk4/auto/fixed.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Accessible;
8use crate::{
9 AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow, Widget, ffi,
10};
11use glib::{prelude::*, translate::*};
12
13#[cfg(feature = "v4_10")]
14#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
15glib::wrapper! {
16 /// t
17 /// do that with [`Fixed`][crate::Fixed]. So if you need to reorder widgets depending on
18 /// the text direction, you would need to manually detect it and adjust child
19 /// positions accordingly.
20 ///
21 /// Finally, fixed positioning makes it kind of annoying to add/remove
22 /// UI elements, since you have to reposition all the other elements. This
23 /// is a long-term maintenance problem for your application.
24 ///
25 /// If you know none of these things are an issue for your application,
26 /// and prefer the simplicity of [`Fixed`][crate::Fixed], by all means use the
27 /// widget. But you should be aware of the tradeoffs.
28 ///
29 /// # Implements
30 ///
31 /// [`FixedExt`][trait@crate::prelude::FixedExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
32 #[doc(alias = "GtkFixed")]
33 pub struct Fixed(Object<ffi::GtkFixed, ffi::GtkFixedClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
34
35 match fn {
36 type_ => || ffi::gtk_fixed_get_type(),
37 }
38}
39
40#[cfg(not(feature = "v4_10"))]
41glib::wrapper! {
42 #[doc(alias = "GtkFixed")]
43 pub struct Fixed(Object<ffi::GtkFixed, ffi::GtkFixedClass>) @extends Widget, @implements Buildable, ConstraintTarget;
44
45 match fn {
46 type_ => || ffi::gtk_fixed_get_type(),
47 }
48}
49
50impl Fixed {
51 pub const NONE: Option<&'static Fixed> = None;
52
53 /// Creates a new [`Fixed`][crate::Fixed].
54 ///
55 /// # Returns
56 ///
57 /// a new [`Fixed`][crate::Fixed].
58 #[doc(alias = "gtk_fixed_new")]
59 pub fn new() -> Fixed {
60 assert_initialized_main_thread!();
61 unsafe { Widget::from_glib_none(ffi::gtk_fixed_new()).unsafe_cast() }
62 }
63
64 // rustdoc-stripper-ignore-next
65 /// Creates a new builder-pattern struct instance to construct [`Fixed`] objects.
66 ///
67 /// This method returns an instance of [`FixedBuilder`](crate::builders::FixedBuilder) which can be used to create [`Fixed`] objects.
68 pub fn builder() -> FixedBuilder {
69 FixedBuilder::new()
70 }
71}
72
73impl Default for Fixed {
74 fn default() -> Self {
75 Self::new()
76 }
77}
78
79// rustdoc-stripper-ignore-next
80/// A [builder-pattern] type to construct [`Fixed`] objects.
81///
82/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
83#[must_use = "The builder must be built to be used"]
84pub struct FixedBuilder {
85 builder: glib::object::ObjectBuilder<'static, Fixed>,
86}
87
88impl FixedBuilder {
89 fn new() -> Self {
90 Self {
91 builder: glib::object::Object::builder(),
92 }
93 }
94
95 /// Whether the widget or any of its descendents can accept
96 /// the input focus.
97 ///
98 /// This property is meant to be set by widget implementations,
99 /// typically in their instance init function.
100 pub fn can_focus(self, can_focus: bool) -> Self {
101 Self {
102 builder: self.builder.property("can-focus", can_focus),
103 }
104 }
105
106 /// Whether the widget can receive pointer events.
107 pub fn can_target(self, can_target: bool) -> Self {
108 Self {
109 builder: self.builder.property("can-target", can_target),
110 }
111 }
112
113 /// A list of css classes applied to this widget.
114 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
115 Self {
116 builder: self.builder.property("css-classes", css_classes.into()),
117 }
118 }
119
120 /// The name of this widget in the CSS tree.
121 ///
122 /// This property is meant to be set by widget implementations,
123 /// typically in their instance init function.
124 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
125 Self {
126 builder: self.builder.property("css-name", css_name.into()),
127 }
128 }
129
130 /// The cursor used by @widget.
131 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
132 Self {
133 builder: self.builder.property("cursor", cursor.clone()),
134 }
135 }
136
137 /// Whether the widget should grab focus when it is clicked with the mouse.
138 ///
139 /// This property is only relevant for widgets that can take focus.
140 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
141 Self {
142 builder: self.builder.property("focus-on-click", focus_on_click),
143 }
144 }
145
146 /// Whether this widget itself will accept the input focus.
147 pub fn focusable(self, focusable: bool) -> Self {
148 Self {
149 builder: self.builder.property("focusable", focusable),
150 }
151 }
152
153 /// How to distribute horizontal space if widget gets extra space.
154 pub fn halign(self, halign: Align) -> Self {
155 Self {
156 builder: self.builder.property("halign", halign),
157 }
158 }
159
160 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
161 /// signal on @widget.
162 ///
163 /// A true value indicates that @widget can have a tooltip, in this case
164 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
165 /// determine whether it will provide a tooltip or not.
166 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
167 Self {
168 builder: self.builder.property("has-tooltip", has_tooltip),
169 }
170 }
171
172 /// Overrides for height request of the widget.
173 ///
174 /// If this is -1, the natural request will be used.
175 pub fn height_request(self, height_request: i32) -> Self {
176 Self {
177 builder: self.builder.property("height-request", height_request),
178 }
179 }
180
181 /// Whether to expand horizontally.
182 pub fn hexpand(self, hexpand: bool) -> Self {
183 Self {
184 builder: self.builder.property("hexpand", hexpand),
185 }
186 }
187
188 /// Whether to use the `hexpand` property.
189 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
190 Self {
191 builder: self.builder.property("hexpand-set", hexpand_set),
192 }
193 }
194
195 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
196 /// the preferred size of the widget, and allocate its children.
197 ///
198 /// This property is meant to be set by widget implementations,
199 /// typically in their instance init function.
200 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
201 Self {
202 builder: self
203 .builder
204 .property("layout-manager", layout_manager.clone().upcast()),
205 }
206 }
207
208 /// Makes this widget act like a modal dialog, with respect to
209 /// event delivery.
210 ///
211 /// Global event controllers will not handle events with targets
212 /// inside the widget, unless they are set up to ignore propagation
213 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
214 #[cfg(feature = "v4_18")]
215 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
216 pub fn limit_events(self, limit_events: bool) -> Self {
217 Self {
218 builder: self.builder.property("limit-events", limit_events),
219 }
220 }
221
222 /// Margin on bottom side of widget.
223 ///
224 /// This property adds margin outside of the widget's normal size
225 /// request, the margin will be added in addition to the size from
226 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
227 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
228 Self {
229 builder: self.builder.property("margin-bottom", margin_bottom),
230 }
231 }
232
233 /// Margin on end of widget, horizontally.
234 ///
235 /// This property supports left-to-right and right-to-left text
236 /// directions.
237 ///
238 /// This property adds margin outside of the widget's normal size
239 /// request, the margin will be added in addition to the size from
240 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
241 pub fn margin_end(self, margin_end: i32) -> Self {
242 Self {
243 builder: self.builder.property("margin-end", margin_end),
244 }
245 }
246
247 /// Margin on start of widget, horizontally.
248 ///
249 /// This property supports left-to-right and right-to-left text
250 /// directions.
251 ///
252 /// This property adds margin outside of the widget's normal size
253 /// request, the margin will be added in addition to the size from
254 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
255 pub fn margin_start(self, margin_start: i32) -> Self {
256 Self {
257 builder: self.builder.property("margin-start", margin_start),
258 }
259 }
260
261 /// Margin on top side of widget.
262 ///
263 /// This property adds margin outside of the widget's normal size
264 /// request, the margin will be added in addition to the size from
265 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
266 pub fn margin_top(self, margin_top: i32) -> Self {
267 Self {
268 builder: self.builder.property("margin-top", margin_top),
269 }
270 }
271
272 /// The name of the widget.
273 pub fn name(self, name: impl Into<glib::GString>) -> Self {
274 Self {
275 builder: self.builder.property("name", name.into()),
276 }
277 }
278
279 /// The requested opacity of the widget.
280 pub fn opacity(self, opacity: f64) -> Self {
281 Self {
282 builder: self.builder.property("opacity", opacity),
283 }
284 }
285
286 /// How content outside the widget's content area is treated.
287 ///
288 /// This property is meant to be set by widget implementations,
289 /// typically in their instance init function.
290 pub fn overflow(self, overflow: Overflow) -> Self {
291 Self {
292 builder: self.builder.property("overflow", overflow),
293 }
294 }
295
296 /// Whether the widget will receive the default action when it is focused.
297 pub fn receives_default(self, receives_default: bool) -> Self {
298 Self {
299 builder: self.builder.property("receives-default", receives_default),
300 }
301 }
302
303 /// Whether the widget responds to input.
304 pub fn sensitive(self, sensitive: bool) -> Self {
305 Self {
306 builder: self.builder.property("sensitive", sensitive),
307 }
308 }
309
310 /// Sets the text of tooltip to be the given string, which is marked up
311 /// with Pango markup.
312 ///
313 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
314 ///
315 /// This is a convenience property which will take care of getting the
316 /// tooltip shown if the given string is not `NULL`:
317 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
318 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
319 /// the default signal handler.
320 ///
321 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
322 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
323 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
324 Self {
325 builder: self
326 .builder
327 .property("tooltip-markup", tooltip_markup.into()),
328 }
329 }
330
331 /// Sets the text of tooltip to be the given string.
332 ///
333 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
334 ///
335 /// This is a convenience property which will take care of getting the
336 /// tooltip shown if the given string is not `NULL`:
337 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
338 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
339 /// the default signal handler.
340 ///
341 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
342 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
343 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
344 Self {
345 builder: self.builder.property("tooltip-text", tooltip_text.into()),
346 }
347 }
348
349 /// How to distribute vertical space if widget gets extra space.
350 pub fn valign(self, valign: Align) -> Self {
351 Self {
352 builder: self.builder.property("valign", valign),
353 }
354 }
355
356 /// Whether to expand vertically.
357 pub fn vexpand(self, vexpand: bool) -> Self {
358 Self {
359 builder: self.builder.property("vexpand", vexpand),
360 }
361 }
362
363 /// Whether to use the `vexpand` property.
364 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
365 Self {
366 builder: self.builder.property("vexpand-set", vexpand_set),
367 }
368 }
369
370 /// Whether the widget is visible.
371 pub fn visible(self, visible: bool) -> Self {
372 Self {
373 builder: self.builder.property("visible", visible),
374 }
375 }
376
377 /// Overrides for width request of the widget.
378 ///
379 /// If this is -1, the natural request will be used.
380 pub fn width_request(self, width_request: i32) -> Self {
381 Self {
382 builder: self.builder.property("width-request", width_request),
383 }
384 }
385
386 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
387 ///
388 /// The accessible role cannot be changed once set.
389 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
390 Self {
391 builder: self.builder.property("accessible-role", accessible_role),
392 }
393 }
394
395 // rustdoc-stripper-ignore-next
396 /// Build the [`Fixed`].
397 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
398 pub fn build(self) -> Fixed {
399 assert_initialized_main_thread!();
400 self.builder.build()
401 }
402}
403
404/// Trait containing all [`struct@Fixed`] methods.
405///
406/// # Implementors
407///
408/// [`Fixed`][struct@crate::Fixed]
409pub trait FixedExt: IsA<Fixed> + 'static {
410 /// Retrieves the translation transformation of the
411 /// given child [`Widget`][crate::Widget] in the [`Fixed`][crate::Fixed].
412 ///
413 /// See also: [`child_transform()`][Self::child_transform()].
414 /// ## `widget`
415 /// a child of @self
416 ///
417 /// # Returns
418 ///
419 ///
420 /// ## `x`
421 /// the horizontal position of the @widget
422 ///
423 /// ## `y`
424 /// the vertical position of the @widget
425 #[doc(alias = "gtk_fixed_get_child_position")]
426 #[doc(alias = "get_child_position")]
427 fn child_position(&self, widget: &impl IsA<Widget>) -> (f64, f64) {
428 unsafe {
429 let mut x = std::mem::MaybeUninit::uninit();
430 let mut y = std::mem::MaybeUninit::uninit();
431 ffi::gtk_fixed_get_child_position(
432 self.as_ref().to_glib_none().0,
433 widget.as_ref().to_glib_none().0,
434 x.as_mut_ptr(),
435 y.as_mut_ptr(),
436 );
437 (x.assume_init(), y.assume_init())
438 }
439 }
440
441 /// Retrieves the transformation for @widget set using
442 /// gtk_fixed_set_child_transform().
443 /// ## `widget`
444 /// a [`Widget`][crate::Widget], child of @self
445 ///
446 /// # Returns
447 ///
448 /// a [`gsk::Transform`][crate::gsk::Transform]
449 #[doc(alias = "gtk_fixed_get_child_transform")]
450 #[doc(alias = "get_child_transform")]
451 fn child_transform(&self, widget: &impl IsA<Widget>) -> Option<gsk::Transform> {
452 unsafe {
453 from_glib_none(ffi::gtk_fixed_get_child_transform(
454 self.as_ref().to_glib_none().0,
455 widget.as_ref().to_glib_none().0,
456 ))
457 }
458 }
459
460 /// Sets a translation transformation to the given @x and @y
461 /// coordinates to the child @widget of the [`Fixed`][crate::Fixed].
462 /// ## `widget`
463 /// the child widget
464 /// ## `x`
465 /// the horizontal position to move the widget to
466 /// ## `y`
467 /// the vertical position to move the widget to
468 #[doc(alias = "gtk_fixed_move")]
469 #[doc(alias = "move")]
470 fn move_(&self, widget: &impl IsA<Widget>, x: f64, y: f64) {
471 unsafe {
472 ffi::gtk_fixed_move(
473 self.as_ref().to_glib_none().0,
474 widget.as_ref().to_glib_none().0,
475 x,
476 y,
477 );
478 }
479 }
480
481 /// Adds a widget to a [`Fixed`][crate::Fixed] at the given position.
482 /// ## `widget`
483 /// the widget to add
484 /// ## `x`
485 /// the horizontal position to place the widget at
486 /// ## `y`
487 /// the vertical position to place the widget at
488 #[doc(alias = "gtk_fixed_put")]
489 fn put(&self, widget: &impl IsA<Widget>, x: f64, y: f64) {
490 unsafe {
491 ffi::gtk_fixed_put(
492 self.as_ref().to_glib_none().0,
493 widget.as_ref().to_glib_none().0,
494 x,
495 y,
496 );
497 }
498 }
499
500 /// Removes a child from @self.
501 /// ## `widget`
502 /// the child widget to remove
503 #[doc(alias = "gtk_fixed_remove")]
504 fn remove(&self, widget: &impl IsA<Widget>) {
505 unsafe {
506 ffi::gtk_fixed_remove(
507 self.as_ref().to_glib_none().0,
508 widget.as_ref().to_glib_none().0,
509 );
510 }
511 }
512
513 /// Sets the transformation for @widget.
514 ///
515 /// This is a convenience function that retrieves the
516 /// [`FixedLayoutChild`][crate::FixedLayoutChild] instance associated to
517 /// @widget and calls [`FixedLayoutChild::set_transform()`][crate::FixedLayoutChild::set_transform()].
518 /// ## `widget`
519 /// a [`Widget`][crate::Widget], child of @self
520 /// ## `transform`
521 /// the transformation assigned to @widget
522 /// to reset @widget's transform
523 #[doc(alias = "gtk_fixed_set_child_transform")]
524 fn set_child_transform(&self, widget: &impl IsA<Widget>, transform: Option<&gsk::Transform>) {
525 unsafe {
526 ffi::gtk_fixed_set_child_transform(
527 self.as_ref().to_glib_none().0,
528 widget.as_ref().to_glib_none().0,
529 transform.to_glib_none().0,
530 );
531 }
532 }
533}
534
535impl<O: IsA<Fixed>> FixedExt for O {}