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