Skip to main content

gtk/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::{Align, Buildable, Container, ResizeMode, Widget, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// The [`Fixed`][crate::Fixed] widget is a container which can place child widgets
10    /// at fixed positions and with fixed sizes, given in pixels. [`Fixed`][crate::Fixed]
11    /// performs no automatic layout management.
12    ///
13    /// For most applications, you should not use this container! It keeps
14    /// you from having to learn about the other GTK+ containers, but it
15    /// results in broken applications. With [`Fixed`][crate::Fixed], the following
16    /// things will result in truncated text, overlapping widgets, and
17    /// other display bugs:
18    ///
19    /// - Themes, which may change widget sizes.
20    ///
21    /// - Fonts other than the one you used to write the app will of course
22    ///  change the size of widgets containing text; keep in mind that
23    ///  users may use a larger font because of difficulty reading the
24    ///  default, or they may be using a different OS that provides different fonts.
25    ///
26    /// - Translation of text into other languages changes its size. Also,
27    ///  display of non-English text will use a different font in many
28    ///  cases.
29    ///
30    /// In addition, [`Fixed`][crate::Fixed] does not pay attention to text direction and thus may
31    /// produce unwanted results if your app is run under right-to-left languages
32    /// such as Hebrew or Arabic. That is: normally GTK+ will order containers
33    /// appropriately for the text direction, e.g. to put labels to the right of the
34    /// thing they label when using an RTL language, but it can’t do that with
35    /// [`Fixed`][crate::Fixed]. So if you need to reorder widgets depending on the text direction,
36    /// you would need to manually detect it and adjust child positions accordingly.
37    ///
38    /// Finally, fixed positioning makes it kind of annoying to add/remove
39    /// GUI elements, since you have to reposition all the other
40    /// elements. This is a long-term maintenance problem for your
41    /// application.
42    ///
43    /// If you know none of these things are an issue for your application,
44    /// and prefer the simplicity of [`Fixed`][crate::Fixed], by all means use the
45    /// widget. But you should be aware of the tradeoffs.
46    ///
47    /// See also [`Layout`][crate::Layout], which shares the ability to perform fixed positioning
48    /// of child widgets and additionally adds custom drawing and scrollability.
49    ///
50    /// # Implements
51    ///
52    /// [`FixedExt`][trait@crate::prelude::FixedExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`FixedExtManual`][trait@crate::prelude::FixedExtManual], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
53    #[doc(alias = "GtkFixed")]
54    pub struct Fixed(Object<ffi::GtkFixed, ffi::GtkFixedClass>) @extends Container, Widget, @implements Buildable;
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    pub fn border_width(self, border_width: u32) -> Self {
107        Self {
108            builder: self.builder.property("border-width", border_width),
109        }
110    }
111
112    pub fn child(self, child: &impl IsA<Widget>) -> Self {
113        Self {
114            builder: self.builder.property("child", child.clone().upcast()),
115        }
116    }
117
118    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
119        Self {
120            builder: self.builder.property("resize-mode", resize_mode),
121        }
122    }
123
124    pub fn app_paintable(self, app_paintable: bool) -> Self {
125        Self {
126            builder: self.builder.property("app-paintable", app_paintable),
127        }
128    }
129
130    pub fn can_default(self, can_default: bool) -> Self {
131        Self {
132            builder: self.builder.property("can-default", can_default),
133        }
134    }
135
136    pub fn can_focus(self, can_focus: bool) -> Self {
137        Self {
138            builder: self.builder.property("can-focus", can_focus),
139        }
140    }
141
142    pub fn events(self, events: gdk::EventMask) -> Self {
143        Self {
144            builder: self.builder.property("events", events),
145        }
146    }
147
148    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
149    pub fn expand(self, expand: bool) -> Self {
150        Self {
151            builder: self.builder.property("expand", expand),
152        }
153    }
154
155    /// Whether the widget should grab focus when it is clicked with the mouse.
156    ///
157    /// This property is only relevant for widgets that can take focus.
158    ///
159    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
160    /// GtkComboBox) implemented this property individually.
161    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
162        Self {
163            builder: self.builder.property("focus-on-click", focus_on_click),
164        }
165    }
166
167    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
168    pub fn halign(self, halign: Align) -> Self {
169        Self {
170            builder: self.builder.property("halign", halign),
171        }
172    }
173
174    pub fn has_default(self, has_default: bool) -> Self {
175        Self {
176            builder: self.builder.property("has-default", has_default),
177        }
178    }
179
180    pub fn has_focus(self, has_focus: bool) -> Self {
181        Self {
182            builder: self.builder.property("has-focus", has_focus),
183        }
184    }
185
186    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
187    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
188    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
189    /// whether it will provide a tooltip or not.
190    ///
191    /// Note that setting this property to [`true`] for the first time will change
192    /// the event masks of the GdkWindows of this widget to include leave-notify
193    /// and motion-notify events. This cannot and will not be undone when the
194    /// property is set to [`false`] again.
195    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
196        Self {
197            builder: self.builder.property("has-tooltip", has_tooltip),
198        }
199    }
200
201    pub fn height_request(self, height_request: i32) -> Self {
202        Self {
203            builder: self.builder.property("height-request", height_request),
204        }
205    }
206
207    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
208    pub fn hexpand(self, hexpand: bool) -> Self {
209        Self {
210            builder: self.builder.property("hexpand", hexpand),
211        }
212    }
213
214    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
215    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
216        Self {
217            builder: self.builder.property("hexpand-set", hexpand_set),
218        }
219    }
220
221    pub fn is_focus(self, is_focus: bool) -> Self {
222        Self {
223            builder: self.builder.property("is-focus", is_focus),
224        }
225    }
226
227    /// Sets all four sides' margin at once. If read, returns max
228    /// margin on any side.
229    pub fn margin(self, margin: i32) -> Self {
230        Self {
231            builder: self.builder.property("margin", margin),
232        }
233    }
234
235    /// Margin on bottom side of widget.
236    ///
237    /// This property adds margin outside of the widget's normal size
238    /// request, the margin will be added in addition to the size from
239    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
240    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
241        Self {
242            builder: self.builder.property("margin-bottom", margin_bottom),
243        }
244    }
245
246    /// Margin on end of widget, horizontally. This property supports
247    /// left-to-right and right-to-left text 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. This property supports
259    /// left-to-right and right-to-left text directions.
260    ///
261    /// This property adds margin outside of the widget's normal size
262    /// request, the margin will be added in addition to the size from
263    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
264    pub fn margin_start(self, margin_start: i32) -> Self {
265        Self {
266            builder: self.builder.property("margin-start", margin_start),
267        }
268    }
269
270    /// Margin on top side of widget.
271    ///
272    /// This property adds margin outside of the widget's normal size
273    /// request, the margin will be added in addition to the size from
274    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
275    pub fn margin_top(self, margin_top: i32) -> Self {
276        Self {
277            builder: self.builder.property("margin-top", margin_top),
278        }
279    }
280
281    pub fn name(self, name: impl Into<glib::GString>) -> Self {
282        Self {
283            builder: self.builder.property("name", name.into()),
284        }
285    }
286
287    pub fn no_show_all(self, no_show_all: bool) -> Self {
288        Self {
289            builder: self.builder.property("no-show-all", no_show_all),
290        }
291    }
292
293    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
294    /// more details about window opacity.
295    ///
296    /// Before 3.8 this was only available in GtkWindow
297    pub fn opacity(self, opacity: f64) -> Self {
298        Self {
299            builder: self.builder.property("opacity", opacity),
300        }
301    }
302
303    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
304        Self {
305            builder: self.builder.property("parent", parent.clone().upcast()),
306        }
307    }
308
309    pub fn receives_default(self, receives_default: bool) -> Self {
310        Self {
311            builder: self.builder.property("receives-default", receives_default),
312        }
313    }
314
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 the [Pango text markup language][PangoMarkupFormat].
323    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
324    ///
325    /// This is a convenience property which will take care of getting the
326    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
327    /// will automatically be set to [`true`] and there will be taken care of
328    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
329    ///
330    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
331    /// are set, the last one wins.
332    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
333        Self {
334            builder: self
335                .builder
336                .property("tooltip-markup", tooltip_markup.into()),
337        }
338    }
339
340    /// Sets the text of tooltip to be the given string.
341    ///
342    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
343    ///
344    /// This is a convenience property which will take care of getting the
345    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
346    /// will automatically be set to [`true`] and there will be taken care of
347    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
348    ///
349    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
350    /// are set, the last one wins.
351    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
352        Self {
353            builder: self.builder.property("tooltip-text", tooltip_text.into()),
354        }
355    }
356
357    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
358    pub fn valign(self, valign: Align) -> Self {
359        Self {
360            builder: self.builder.property("valign", valign),
361        }
362    }
363
364    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
365    pub fn vexpand(self, vexpand: bool) -> Self {
366        Self {
367            builder: self.builder.property("vexpand", vexpand),
368        }
369    }
370
371    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
372    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
373        Self {
374            builder: self.builder.property("vexpand-set", vexpand_set),
375        }
376    }
377
378    pub fn visible(self, visible: bool) -> Self {
379        Self {
380            builder: self.builder.property("visible", visible),
381        }
382    }
383
384    pub fn width_request(self, width_request: i32) -> Self {
385        Self {
386            builder: self.builder.property("width-request", width_request),
387        }
388    }
389
390    // rustdoc-stripper-ignore-next
391    /// Build the [`Fixed`].
392    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
393    pub fn build(self) -> Fixed {
394        assert_initialized_main_thread!();
395        self.builder.build()
396    }
397}
398
399/// Trait containing all [`struct@Fixed`] methods.
400///
401/// # Implementors
402///
403/// [`Fixed`][struct@crate::Fixed]
404pub trait FixedExt: IsA<Fixed> + 'static {
405    /// Moves a child of a [`Fixed`][crate::Fixed] container to the given position.
406    /// ## `widget`
407    /// the child widget.
408    /// ## `x`
409    /// the horizontal position to move the widget to.
410    /// ## `y`
411    /// the vertical position to move the widget to.
412    #[doc(alias = "gtk_fixed_move")]
413    #[doc(alias = "move")]
414    fn move_(&self, widget: &impl IsA<Widget>, x: i32, y: i32) {
415        unsafe {
416            ffi::gtk_fixed_move(
417                self.as_ref().to_glib_none().0,
418                widget.as_ref().to_glib_none().0,
419                x,
420                y,
421            );
422        }
423    }
424
425    /// Adds a widget to a [`Fixed`][crate::Fixed] container at the given position.
426    /// ## `widget`
427    /// the widget to add.
428    /// ## `x`
429    /// the horizontal position to place the widget at.
430    /// ## `y`
431    /// the vertical position to place the widget at.
432    #[doc(alias = "gtk_fixed_put")]
433    fn put(&self, widget: &impl IsA<Widget>, x: i32, y: i32) {
434        unsafe {
435            ffi::gtk_fixed_put(
436                self.as_ref().to_glib_none().0,
437                widget.as_ref().to_glib_none().0,
438                x,
439                y,
440            );
441        }
442    }
443}
444
445impl<O: IsA<Fixed>> FixedExt for O {}