Skip to main content

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