Skip to main content

gtk/auto/
action_bar.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, Bin, Buildable, Container, PackType, ResizeMode, Widget, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// GtkActionBar is designed to present contextual actions. It is
10    /// expected to be displayed below the content and expand horizontally
11    /// to fill the area.
12    ///
13    /// It allows placing children at the start or the end. In addition, it
14    /// contains an internal centered box which is centered with respect to
15    /// the full width of the box, even if the children at either side take
16    /// up different amounts of space.
17    ///
18    /// # CSS nodes
19    ///
20    /// GtkActionBar has a single CSS node with name actionbar.
21    ///
22    /// # Implements
23    ///
24    /// [`ActionBarExt`][trait@crate::prelude::ActionBarExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
25    #[doc(alias = "GtkActionBar")]
26    pub struct ActionBar(Object<ffi::GtkActionBar, ffi::GtkActionBarClass>) @extends Bin, Container, Widget, @implements Buildable;
27
28    match fn {
29        type_ => || ffi::gtk_action_bar_get_type(),
30    }
31}
32
33impl ActionBar {
34    pub const NONE: Option<&'static ActionBar> = None;
35
36    /// Creates a new [`ActionBar`][crate::ActionBar] widget.
37    ///
38    /// # Returns
39    ///
40    /// a new [`ActionBar`][crate::ActionBar]
41    #[doc(alias = "gtk_action_bar_new")]
42    pub fn new() -> ActionBar {
43        assert_initialized_main_thread!();
44        unsafe { Widget::from_glib_none(ffi::gtk_action_bar_new()).unsafe_cast() }
45    }
46
47    // rustdoc-stripper-ignore-next
48    /// Creates a new builder-pattern struct instance to construct [`ActionBar`] objects.
49    ///
50    /// This method returns an instance of [`ActionBarBuilder`](crate::builders::ActionBarBuilder) which can be used to create [`ActionBar`] objects.
51    pub fn builder() -> ActionBarBuilder {
52        ActionBarBuilder::new()
53    }
54}
55
56impl Default for ActionBar {
57    fn default() -> Self {
58        Self::new()
59    }
60}
61
62// rustdoc-stripper-ignore-next
63/// A [builder-pattern] type to construct [`ActionBar`] objects.
64///
65/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
66#[must_use = "The builder must be built to be used"]
67pub struct ActionBarBuilder {
68    builder: glib::object::ObjectBuilder<'static, ActionBar>,
69}
70
71impl ActionBarBuilder {
72    fn new() -> Self {
73        Self {
74            builder: glib::object::Object::builder(),
75        }
76    }
77
78    pub fn border_width(self, border_width: u32) -> Self {
79        Self {
80            builder: self.builder.property("border-width", border_width),
81        }
82    }
83
84    pub fn child(self, child: &impl IsA<Widget>) -> Self {
85        Self {
86            builder: self.builder.property("child", child.clone().upcast()),
87        }
88    }
89
90    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
91        Self {
92            builder: self.builder.property("resize-mode", resize_mode),
93        }
94    }
95
96    pub fn app_paintable(self, app_paintable: bool) -> Self {
97        Self {
98            builder: self.builder.property("app-paintable", app_paintable),
99        }
100    }
101
102    pub fn can_default(self, can_default: bool) -> Self {
103        Self {
104            builder: self.builder.property("can-default", can_default),
105        }
106    }
107
108    pub fn can_focus(self, can_focus: bool) -> Self {
109        Self {
110            builder: self.builder.property("can-focus", can_focus),
111        }
112    }
113
114    pub fn events(self, events: gdk::EventMask) -> Self {
115        Self {
116            builder: self.builder.property("events", events),
117        }
118    }
119
120    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
121    pub fn expand(self, expand: bool) -> Self {
122        Self {
123            builder: self.builder.property("expand", expand),
124        }
125    }
126
127    /// Whether the widget should grab focus when it is clicked with the mouse.
128    ///
129    /// This property is only relevant for widgets that can take focus.
130    ///
131    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
132    /// GtkComboBox) implemented this property individually.
133    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
134        Self {
135            builder: self.builder.property("focus-on-click", focus_on_click),
136        }
137    }
138
139    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
140    pub fn halign(self, halign: Align) -> Self {
141        Self {
142            builder: self.builder.property("halign", halign),
143        }
144    }
145
146    pub fn has_default(self, has_default: bool) -> Self {
147        Self {
148            builder: self.builder.property("has-default", has_default),
149        }
150    }
151
152    pub fn has_focus(self, has_focus: bool) -> Self {
153        Self {
154            builder: self.builder.property("has-focus", has_focus),
155        }
156    }
157
158    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
159    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
160    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
161    /// whether it will provide a tooltip or not.
162    ///
163    /// Note that setting this property to [`true`] for the first time will change
164    /// the event masks of the GdkWindows of this widget to include leave-notify
165    /// and motion-notify events. This cannot and will not be undone when the
166    /// property is set to [`false`] again.
167    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
168        Self {
169            builder: self.builder.property("has-tooltip", has_tooltip),
170        }
171    }
172
173    pub fn height_request(self, height_request: i32) -> Self {
174        Self {
175            builder: self.builder.property("height-request", height_request),
176        }
177    }
178
179    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
180    pub fn hexpand(self, hexpand: bool) -> Self {
181        Self {
182            builder: self.builder.property("hexpand", hexpand),
183        }
184    }
185
186    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
187    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
188        Self {
189            builder: self.builder.property("hexpand-set", hexpand_set),
190        }
191    }
192
193    pub fn is_focus(self, is_focus: bool) -> Self {
194        Self {
195            builder: self.builder.property("is-focus", is_focus),
196        }
197    }
198
199    /// Sets all four sides' margin at once. If read, returns max
200    /// margin on any side.
201    pub fn margin(self, margin: i32) -> Self {
202        Self {
203            builder: self.builder.property("margin", margin),
204        }
205    }
206
207    /// Margin on bottom side of widget.
208    ///
209    /// This property adds margin outside of the widget's normal size
210    /// request, the margin will be added in addition to the size from
211    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
212    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
213        Self {
214            builder: self.builder.property("margin-bottom", margin_bottom),
215        }
216    }
217
218    /// Margin on end of widget, horizontally. This property supports
219    /// left-to-right and right-to-left text directions.
220    ///
221    /// This property adds margin outside of the widget's normal size
222    /// request, the margin will be added in addition to the size from
223    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
224    pub fn margin_end(self, margin_end: i32) -> Self {
225        Self {
226            builder: self.builder.property("margin-end", margin_end),
227        }
228    }
229
230    /// Margin on start of widget, horizontally. This property supports
231    /// left-to-right and right-to-left text directions.
232    ///
233    /// This property adds margin outside of the widget's normal size
234    /// request, the margin will be added in addition to the size from
235    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
236    pub fn margin_start(self, margin_start: i32) -> Self {
237        Self {
238            builder: self.builder.property("margin-start", margin_start),
239        }
240    }
241
242    /// Margin on top side of widget.
243    ///
244    /// This property adds margin outside of the widget's normal size
245    /// request, the margin will be added in addition to the size from
246    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
247    pub fn margin_top(self, margin_top: i32) -> Self {
248        Self {
249            builder: self.builder.property("margin-top", margin_top),
250        }
251    }
252
253    pub fn name(self, name: impl Into<glib::GString>) -> Self {
254        Self {
255            builder: self.builder.property("name", name.into()),
256        }
257    }
258
259    pub fn no_show_all(self, no_show_all: bool) -> Self {
260        Self {
261            builder: self.builder.property("no-show-all", no_show_all),
262        }
263    }
264
265    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
266    /// more details about window opacity.
267    ///
268    /// Before 3.8 this was only available in GtkWindow
269    pub fn opacity(self, opacity: f64) -> Self {
270        Self {
271            builder: self.builder.property("opacity", opacity),
272        }
273    }
274
275    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
276        Self {
277            builder: self.builder.property("parent", parent.clone().upcast()),
278        }
279    }
280
281    pub fn receives_default(self, receives_default: bool) -> Self {
282        Self {
283            builder: self.builder.property("receives-default", receives_default),
284        }
285    }
286
287    pub fn sensitive(self, sensitive: bool) -> Self {
288        Self {
289            builder: self.builder.property("sensitive", sensitive),
290        }
291    }
292
293    /// Sets the text of tooltip to be the given string, which is marked up
294    /// with the [Pango text markup language][PangoMarkupFormat].
295    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
296    ///
297    /// This is a convenience property which will take care of getting the
298    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
299    /// will automatically be set to [`true`] and there will be taken care of
300    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
301    ///
302    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
303    /// are set, the last one wins.
304    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
305        Self {
306            builder: self
307                .builder
308                .property("tooltip-markup", tooltip_markup.into()),
309        }
310    }
311
312    /// Sets the text of tooltip to be the given string.
313    ///
314    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
315    ///
316    /// This is a convenience property which will take care of getting the
317    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
318    /// will automatically be set to [`true`] and there will be taken care of
319    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
320    ///
321    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
322    /// are set, the last one wins.
323    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
324        Self {
325            builder: self.builder.property("tooltip-text", tooltip_text.into()),
326        }
327    }
328
329    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
330    pub fn valign(self, valign: Align) -> Self {
331        Self {
332            builder: self.builder.property("valign", valign),
333        }
334    }
335
336    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
337    pub fn vexpand(self, vexpand: bool) -> Self {
338        Self {
339            builder: self.builder.property("vexpand", vexpand),
340        }
341    }
342
343    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
344    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
345        Self {
346            builder: self.builder.property("vexpand-set", vexpand_set),
347        }
348    }
349
350    pub fn visible(self, visible: bool) -> Self {
351        Self {
352            builder: self.builder.property("visible", visible),
353        }
354    }
355
356    pub fn width_request(self, width_request: i32) -> Self {
357        Self {
358            builder: self.builder.property("width-request", width_request),
359        }
360    }
361
362    // rustdoc-stripper-ignore-next
363    /// Build the [`ActionBar`].
364    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
365    pub fn build(self) -> ActionBar {
366        assert_initialized_main_thread!();
367        self.builder.build()
368    }
369}
370
371/// Trait containing all [`struct@ActionBar`] methods.
372///
373/// # Implementors
374///
375/// [`ActionBar`][struct@crate::ActionBar]
376pub trait ActionBarExt: IsA<ActionBar> + 'static {
377    /// Retrieves the center bar widget of the bar.
378    ///
379    /// # Returns
380    ///
381    /// the center [`Widget`][crate::Widget] or [`None`].
382    #[doc(alias = "gtk_action_bar_get_center_widget")]
383    #[doc(alias = "get_center_widget")]
384    fn center_widget(&self) -> Option<Widget> {
385        unsafe {
386            from_glib_none(ffi::gtk_action_bar_get_center_widget(
387                self.as_ref().to_glib_none().0,
388            ))
389        }
390    }
391
392    /// Adds `child` to `self`, packed with reference to the
393    /// end of the `self`.
394    /// ## `child`
395    /// the [`Widget`][crate::Widget] to be added to `self`
396    #[doc(alias = "gtk_action_bar_pack_end")]
397    fn pack_end(&self, child: &impl IsA<Widget>) {
398        unsafe {
399            ffi::gtk_action_bar_pack_end(
400                self.as_ref().to_glib_none().0,
401                child.as_ref().to_glib_none().0,
402            );
403        }
404    }
405
406    /// Adds `child` to `self`, packed with reference to the
407    /// start of the `self`.
408    /// ## `child`
409    /// the [`Widget`][crate::Widget] to be added to `self`
410    #[doc(alias = "gtk_action_bar_pack_start")]
411    fn pack_start(&self, child: &impl IsA<Widget>) {
412        unsafe {
413            ffi::gtk_action_bar_pack_start(
414                self.as_ref().to_glib_none().0,
415                child.as_ref().to_glib_none().0,
416            );
417        }
418    }
419
420    /// Sets the center widget for the [`ActionBar`][crate::ActionBar].
421    /// ## `center_widget`
422    /// a widget to use for the center
423    #[doc(alias = "gtk_action_bar_set_center_widget")]
424    fn set_center_widget(&self, center_widget: Option<&impl IsA<Widget>>) {
425        unsafe {
426            ffi::gtk_action_bar_set_center_widget(
427                self.as_ref().to_glib_none().0,
428                center_widget.map(|p| p.as_ref()).to_glib_none().0,
429            );
430        }
431    }
432
433    #[doc(alias = "child.pack-type")]
434    fn child_pack_type<T: IsA<crate::Widget>>(&self, item: &T) -> PackType {
435        crate::prelude::ContainerExtManual::child_property(
436            self.as_ref(),
437            &item.clone().upcast(),
438            "pack-type",
439        )
440    }
441
442    #[doc(alias = "child.pack-type")]
443    fn set_child_pack_type<T: IsA<crate::Widget>>(&self, item: &T, pack_type: PackType) {
444        crate::prelude::ContainerExtManual::child_set_property(
445            self.as_ref(),
446            &item.clone().upcast(),
447            "pack-type",
448            &pack_type,
449        )
450    }
451
452    fn child_position<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
453        crate::prelude::ContainerExtManual::child_property(
454            self.as_ref(),
455            &item.clone().upcast(),
456            "position",
457        )
458    }
459
460    fn set_child_position<T: IsA<crate::Widget>>(&self, item: &T, position: i32) {
461        crate::prelude::ContainerExtManual::child_set_property(
462            self.as_ref(),
463            &item.clone().upcast(),
464            "position",
465            &position,
466        )
467    }
468}
469
470impl<O: IsA<ActionBar>> ActionBarExt for O {}