Skip to main content

libadwaita/
lib.rs

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