libadwaita/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![allow(clippy::needless_doctest_main)]
3#![doc(
4    html_logo_url = "https://gitlab.gnome.org/GNOME/libadwaita/-/raw/main/doc/libadwaita.svg",
5    html_favicon_url = "https://gitlab.gnome.org/GNOME/libadwaita/-/raw/main/demo/data/org.gnome.Adwaita1.Demo-symbolic.svg"
6)]
7//! # Rust Adwaita bindings
8//!
9//! This library contains safe Rust bindings for [Adwaita](https://gitlab.gnome.org/GNOME/libadwaita), a library that offers
10//! building blocks for modern GNOME applications.
11//!
12//! See also
13//!
14//! - [GTK 4 Rust bindings documentation](mod@gtk)
15//! - [Libadwaita documentation](https://gnome.pages.gitlab.gnome.org/libadwaita/)
16//! - [gtk-rs project overview](https://gtk-rs.org/)
17//! - [Report bindings related issues](https://gitlab.gnome.org/World/Rust/libadwaita-rs)
18//! - [Report upstream libadwaita issues](https://gitlab.gnome.org/GNOME/libadwaita/)
19//!
20//! # Example
21//!
22//! Adwaita needs to be initialized before use.
23//! This can be done by either:
24//! - using [`adw::Application`](struct@Application) instead of [`gtk::Application`](struct@gtk::Application), or by
25//! - calling [`fn@init`] on [`startup`](fn@gio::prelude::ApplicationExt::connect_startup).
26//!
27//! The [`libadwaita`](mod@crate) crate is usually renamed to `adw`. You can
28//! do this globally in your `Cargo.toml` file:
29//!
30//! ```toml
31//! [dependencies.adw]
32//! package = "libadwaita"
33//! version = "0.x.y"
34//! ```
35//!
36//! ```no_run
37//! # use libadwaita as adw;
38//! use adw::prelude::*;
39//!
40//! use adw::{ActionRow, Application, ApplicationWindow, HeaderBar};
41//! use gtk::{Box, ListBox, Orientation, SelectionMode};
42//!
43//! fn main() {
44//!     let application = Application::builder()
45//!         .application_id("com.example.FirstAdwaitaApp")
46//!         .build();
47//!
48//!     application.connect_activate(|app| {
49//!         // ActionRows are only available in Adwaita
50//!         let row = ActionRow::builder()
51//!             .activatable(true)
52//!             .title("Click me")
53//!             .build();
54//!         row.connect_activated(|_| {
55//!             eprintln!("Clicked!");
56//!         });
57//!
58//!         let list = ListBox::builder()
59//!             .margin_top(32)
60//!             .margin_end(32)
61//!             .margin_bottom(32)
62//!             .margin_start(32)
63//!             .selection_mode(SelectionMode::None)
64//!             // makes the list look nicer
65//!             .css_classes(vec![String::from("boxed-list")])
66//!             .build();
67//!         list.append(&row);
68//!
69//!         // Combine the content in a box
70//!         let content = Box::new(Orientation::Vertical, 0);
71//!         // Adwaitas' ApplicationWindow does not include a HeaderBar
72//!         content.append(&HeaderBar::new());
73//!         content.append(&list);
74//!
75//!         let window = ApplicationWindow::builder()
76//!             .application(app)
77//!             .title("First App")
78//!             .default_width(350)
79//!             // add content to window
80//!             .content(&content)
81//!             .build();
82//!         window.present();
83//!     });
84//!
85//!     application.run();
86//! }
87//! ```
88
89// Re-export the -sys bindings
90pub use ffi;
91pub use gdk;
92pub use gio;
93pub use glib;
94pub use gtk;
95
96/// Asserts that this is the main thread and `gtk::init` has been called.
97macro_rules! assert_initialized_main_thread {
98    () => {
99        if !::gtk::is_initialized_main_thread() {
100            if ::gtk::is_initialized() {
101                panic!("libadwaita may only be used from the main thread.");
102            } else {
103                panic!("Gtk has to be initialized before using libadwaita.");
104            }
105        }
106    };
107}
108
109macro_rules! skip_assert_initialized {
110    () => {};
111}
112
113#[allow(unused_imports)]
114#[allow(clippy::let_and_return)]
115#[allow(clippy::type_complexity)]
116mod auto;
117
118#[cfg(feature = "v1_5")]
119#[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
120mod alert_dialog;
121mod application;
122#[cfg(feature = "v1_4")]
123#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
124mod breakpoint;
125mod carousel;
126mod functions;
127#[cfg(feature = "v1_2")]
128#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
129mod message_dialog;
130#[cfg(feature = "v1_9")]
131#[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
132mod sidebar;
133#[cfg(feature = "v1_9")]
134#[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
135mod sidebar_section;
136#[cfg(feature = "v1_4")]
137#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
138mod spin_row;
139mod tab_bar;
140#[cfg(feature = "v1_3")]
141#[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
142mod tab_overview;
143mod tab_view;
144mod toast;
145
146pub use auto::functions::*;
147pub use auto::*;
148pub use functions::*;
149
150pub mod builders;
151pub mod prelude;
152pub mod subclass;