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