gtk4/auto/root.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::{Buildable, ConstraintTarget, Native, Widget, ffi};
9use glib::{prelude::*, translate::*};
10
11#[cfg(feature = "v4_10")]
12#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
13glib::wrapper! {
14 /// An interface for widgets that can act as the root of a widget hierarchy.
15 ///
16 /// The root widget takes care of providing the connection to the windowing
17 /// system and manages layout, drawing and event delivery for its widget
18 /// hierarchy.
19 ///
20 /// The obvious example of a [`Root`][crate::Root] is [`Window`][crate::Window].
21 ///
22 /// To get the display to which a [`Root`][crate::Root] belongs, use
23 /// [`RootExt::display()`][crate::prelude::RootExt::display()].
24 ///
25 /// [`Root`][crate::Root] also maintains the location of keyboard focus inside its widget
26 /// hierarchy, with [`RootExt::set_focus()`][crate::prelude::RootExt::set_focus()] and [`RootExt::focus()`][crate::prelude::RootExt::focus()].
27 ///
28 /// # Implements
29 ///
30 /// [`RootExt`][trait@crate::prelude::RootExt], [`NativeExt`][trait@crate::prelude::NativeExt], [`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]
31 #[doc(alias = "GtkRoot")]
32 pub struct Root(Interface<ffi::GtkRoot, ffi::GtkRootInterface>) @requires Native, Widget, Accessible, Buildable, ConstraintTarget;
33
34 match fn {
35 type_ => || ffi::gtk_root_get_type(),
36 }
37}
38
39#[cfg(not(feature = "v4_10"))]
40glib::wrapper! {
41 #[doc(alias = "GtkRoot")]
42 pub struct Root(Interface<ffi::GtkRoot, ffi::GtkRootInterface>) @requires Native, Widget, Buildable, ConstraintTarget;
43
44 match fn {
45 type_ => || ffi::gtk_root_get_type(),
46 }
47}
48
49impl Root {
50 pub const NONE: Option<&'static Root> = None;
51}
52
53/// Trait containing all [`struct@Root`] methods.
54///
55/// # Implementors
56///
57/// [`AboutDialog`][struct@crate::AboutDialog], [`AppChooserDialog`][struct@crate::AppChooserDialog], [`ApplicationWindow`][struct@crate::ApplicationWindow], [`Assistant`][struct@crate::Assistant], [`ColorChooserDialog`][struct@crate::ColorChooserDialog], [`Dialog`][struct@crate::Dialog], [`DragIcon`][struct@crate::DragIcon], [`FileChooserDialog`][struct@crate::FileChooserDialog], [`FontChooserDialog`][struct@crate::FontChooserDialog], [`MessageDialog`][struct@crate::MessageDialog], [`PageSetupUnixDialog`][struct@crate::PageSetupUnixDialog], [`PrintUnixDialog`][struct@crate::PrintUnixDialog], [`Root`][struct@crate::Root], [`ShortcutsWindow`][struct@crate::ShortcutsWindow], [`Window`][struct@crate::Window]
58pub trait RootExt: IsA<Root> + 'static {
59 /// Returns the display that this [`Root`][crate::Root] is on.
60 ///
61 /// # Returns
62 ///
63 /// the display of @root
64 #[doc(alias = "gtk_root_get_display")]
65 #[doc(alias = "get_display")]
66 fn display(&self) -> gdk::Display {
67 unsafe { from_glib_none(ffi::gtk_root_get_display(self.as_ref().to_glib_none().0)) }
68 }
69
70 /// Retrieves the current focused widget within the root.
71 ///
72 /// Note that this is the widget that would have the focus
73 /// if the root is active; if the root is not focused then
74 /// `gtk_widget_has_focus (widget)` will be [`false`] for the
75 /// widget.
76 ///
77 /// # Returns
78 ///
79 /// the currently focused widget
80 #[doc(alias = "gtk_root_get_focus")]
81 #[doc(alias = "get_focus")]
82 fn focus(&self) -> Option<Widget> {
83 unsafe { from_glib_none(ffi::gtk_root_get_focus(self.as_ref().to_glib_none().0)) }
84 }
85
86 /// If @focus is not the current focus widget, and is focusable, sets
87 /// it as the focus widget for the root.
88 ///
89 /// If @focus is [`None`], unsets the focus widget for the root.
90 ///
91 /// To set the focus to a particular widget in the root, it is usually
92 /// more convenient to use [`WidgetExt::grab_focus()`][crate::prelude::WidgetExt::grab_focus()] instead of
93 /// this function.
94 /// ## `focus`
95 /// widget to be the new focus widget, or [`None`]
96 /// to unset the focus widget
97 #[doc(alias = "gtk_root_set_focus")]
98 fn set_focus(&self, focus: Option<&impl IsA<Widget>>) {
99 unsafe {
100 ffi::gtk_root_set_focus(
101 self.as_ref().to_glib_none().0,
102 focus.map(|p| p.as_ref()).to_glib_none().0,
103 );
104 }
105 }
106}
107
108impl<O: IsA<Root>> RootExt for O {}