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