Skip to main content

freya/
lib.rs

1#![doc(
2    html_logo_url = "https://freyaui.dev/logo.svg",
3    html_favicon_url = "https://freyaui.dev/logo.svg"
4)]
5#![cfg_attr(feature = "docs", feature(doc_cfg))]
6//! # Freya
7//!
8//! **Freya** is a declarative, cross-platform GUI 🦀 Rust library, powered by 🎨 [Skia](https://skia.org/).
9//!
10//! #### Example
11//!
12//! ```rust, no_run
13//! # use freya::prelude::*;
14//! fn main() {
15//!     // *Start* your app with a window and its root component
16//!     launch(LaunchConfig::new().with_window(WindowConfig::new(app)))
17//! }
18//!
19//! fn app() -> impl IntoElement {
20//!     // Define a reactive *state*
21//!     let mut count = use_state(|| 0);
22//!
23//!     // Declare the *UI*
24//!     rect()
25//!         .width(Size::fill())
26//!         .height(Size::fill())
27//!         .background((35, 35, 35))
28//!         .color(Color::WHITE)
29//!         .padding(Gaps::new_all(12.))
30//!         .on_mouse_up(move |_| *count.write() += 1)
31//!         .child(format!("Click to increase -> {}", count.read()))
32//! }
33//! ```
34//!
35//! ### Basics
36//! - [UI and Components](self::_docs::ui_and_components)
37//! - [Elements](self::elements)
38//! - [Hooks](self::_docs::hooks)
39//! - [State](self::_docs::state_management)
40//! - [Remote Data](self::_docs::remote_data)
41//! - [Layers](self::_docs::layers)
42//! - [Platforms](self::_docs::platforms)
43//! - [Development Setup](self::_docs::development_setup)
44//! - [Extending Components](self::_docs::extending_components)
45//!
46//! ### Learn
47//! - [Built-in Components](crate::components)
48//! - [Built-in Components Gallery](crate::components::gallery)
49//! - [i18n](freya_i18n)
50//! - [Animation](freya_animation)
51//! - [Routing](freya_router)
52//! - [Clipboard](freya_clipboard)
53//! - [Icons](freya_icons)
54//! - [Material Design](freya_material_design)
55//! - [Plotters](freya_plotters_backend)
56//! - [Testing](freya_testing)
57//! - [WebView](freya_webview)
58//! - [Terminal](freya_terminal)
59//! - [Tokio Integration](self::_docs::tokio_integration)
60//! - [Devtools](self::_docs::devtools)
61//!
62//! ## Features flags
63//!
64//! - `all`: Enables all the features listed below
65//! - `router`: Reexport [freya_router] under [router]
66//! - `i18n`: Reexport [freya_i18n] under [i18n]
67//! - `remote-asset`: Enables support for **HTTP** asset sources for [ImageViewer](components::ImageViewer) and [GifViewer](components::GifViewer) components.
68//! - `tray`: Enables tray support using the [tray_icon] crate.
69//! - `sdk`: Reexport [freya_sdk] under [sdk].
70//! - `gif`: Enables the [GifViewer](components::GifViewer) component.
71//! - `video`: Enables the [VideoViewer](components::VideoViewer) component.
72//! - `plot`: Reexport of plotters under [plot].
73//! - `material-design`: Reexport [freya_material_design] under [material_design].
74//! - `calendar`: Enables the [Calendar](components::Calendar) component.
75//! - `icons`: Reexport of [freya_icons] under [icons].
76//! - `radio`: Reexport [freya_radio] under [radio].
77//! - `query`: Reexport [freya_query] under [query].
78//! - `markdown`: Enables the [MarkdownViewer](components::MarkdownViewer) component.
79//! - `webview`: Reexport [freya_webview] under [webview].
80//! - `titlebar`: Enables the [TitlebarButton](components::TitlebarButton) component.
81//! - `terminal`: Reexport [freya_terminal] under [terminal].
82//! - `code-editor`: Reexport [freya_code_editor] under [code_editor].
83//!
84//! ## Misc features
85//! - `devtools`: Enables devtools support.
86//! - `performance`: Reexports the performance overlay plugin. The plugin is auto-added in debug builds.
87//! - `vulkan`: Enables Vulkan rendering support.
88//! - `hotpath`: Enables Freya's internal usage of hotpath.
89
90pub mod prelude {
91    pub use freya_core::prelude::*;
92    pub use freya_edit::{
93        Clipboard,
94        ClipboardError,
95    };
96    pub use freya_winit::{
97        WindowDragExt,
98        WinitPlatformExt,
99        config::{
100            CloseDecision,
101            LaunchConfig,
102            WindowConfig,
103        },
104        renderer::{
105            NativeEvent,
106            RendererContext,
107        },
108    };
109
110    pub use crate::components::*;
111
112    pub fn launch(launch_config: LaunchConfig) {
113        #[cfg(feature = "devtools")]
114        let launch_config = launch_config.with_plugin(freya_devtools::DevtoolsPlugin::default());
115        #[cfg(debug_assertions)]
116        let launch_config = launch_config
117            .with_plugin(freya_performance_plugin::PerformanceOverlayPlugin::default());
118        freya_winit::launch(launch_config)
119    }
120
121    #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
122    #[cfg(feature = "router")]
123    pub use freya_router;
124    pub use torin::{
125        alignment::Alignment,
126        content::Content,
127        direction::Direction,
128        gaps::Gaps,
129        geometry::{
130            Area,
131            CursorPoint,
132            Size2D,
133        },
134        position::Position,
135        size::Size,
136        visible_size::VisibleSize,
137    };
138}
139pub mod elements {
140    pub use freya_core::elements::*;
141}
142
143pub mod components {
144    #[cfg_attr(feature = "docs", doc(cfg(feature = "gif")))]
145    #[cfg(feature = "gif")]
146    pub use freya_components::gif_viewer::*;
147    #[cfg_attr(feature = "docs", doc(cfg(feature = "markdown")))]
148    #[cfg(feature = "markdown")]
149    pub use freya_components::markdown::*;
150    #[cfg_attr(feature = "docs", doc(cfg(feature = "video")))]
151    #[cfg(feature = "video")]
152    pub use freya_video::*;
153    cfg_if::cfg_if! {
154        if #[cfg(feature = "router")] {
155            #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
156            pub use freya_components::activable_route::*;
157            pub use freya_components::link::*;
158            pub use freya_components::native_router::*;
159            pub use freya_components::animated_router::*;
160        }
161    }
162    #[cfg_attr(feature = "docs", doc(cfg(feature = "remote-asset")))]
163    #[cfg(feature = "remote-asset")]
164    pub use freya_components::Uri;
165    #[cfg_attr(feature = "docs", doc(cfg(feature = "calendar")))]
166    #[cfg(feature = "calendar")]
167    pub use freya_components::calendar::*;
168    #[cfg(feature = "titlebar")]
169    pub use freya_components::titlebar::*;
170    pub use freya_components::{
171        accordion::*,
172        activable_route_context::*,
173        attached::*,
174        button::*,
175        canvas::*,
176        card::*,
177        checkbox::*,
178        chip::*,
179        color_picker::*,
180        context_menu::*,
181        cursor_area::*,
182        define_theme,
183        drag_drop::*,
184        draggable_canvas::*,
185        element_expansions::*,
186        floating_tab::*,
187        gallery,
188        get_theme,
189        icons::{
190            arrow::*,
191            tick::*,
192        },
193        image_viewer::*,
194        input::*,
195        loader::*,
196        menu::*,
197        overflowed_content::*,
198        popup::*,
199        portal::*,
200        progressbar::*,
201        radio_item::*,
202        resizable_container::*,
203        scrollviews::*,
204        segmented_button::*,
205        select::*,
206        selectable_text::*,
207        sidebar::*,
208        slider::*,
209        switch::*,
210        table::*,
211        theming::{
212            component_themes::{
213                ColorsSheet,
214                Theme,
215            },
216            extensions::*,
217            hooks::*,
218            macros::Preference,
219            themes::*,
220        },
221        tile::*,
222        tooltip::*,
223    };
224}
225
226pub mod text_edit {
227    pub use freya_edit::*;
228}
229
230pub mod clipboard {
231    pub use freya_clipboard::prelude::*;
232}
233
234pub mod animation {
235    pub use freya_animation::prelude::*;
236}
237
238#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
239#[cfg(feature = "plot")]
240pub mod plot {
241    pub use freya_plotters_backend::*;
242    pub use plotters;
243}
244
245#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
246#[cfg(feature = "router")]
247pub mod router {
248    pub use freya_router::prelude::*;
249}
250
251#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
252#[cfg(feature = "i18n")]
253pub mod i18n {
254    pub use freya_i18n::prelude::*;
255}
256
257#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
258#[cfg(feature = "engine")]
259pub mod engine {
260    pub use freya_engine::*;
261}
262
263pub mod winit {
264    pub use freya_winit::winit::*;
265}
266
267pub mod helpers {
268    pub use freya_core::helpers::*;
269}
270
271#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
272#[cfg(feature = "tray")]
273pub mod tray {
274    pub use freya_winit::tray::*;
275}
276
277#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
278#[cfg(feature = "sdk")]
279pub mod sdk {
280    pub use freya_sdk::prelude::*;
281}
282
283#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
284#[cfg(feature = "material-design")]
285pub mod material_design {
286    pub use freya_material_design::prelude::*;
287}
288
289#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
290#[cfg(feature = "icons")]
291pub mod icons {
292    pub use freya_icons::*;
293}
294
295/// Reexport `freya-radio` when the `radio` feature is enabled.
296#[cfg(feature = "radio")]
297#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
298pub mod radio {
299    pub use freya_radio::prelude::*;
300}
301
302/// Reexport `freya-query` when the `query` feature is enabled.
303#[cfg(feature = "query")]
304#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
305pub mod query {
306    pub use freya_query::prelude::*;
307}
308
309/// Reexport `freya-webview` when the `webview` feature is enabled.
310#[cfg(feature = "webview")]
311#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
312pub mod webview {
313    pub use freya_webview::prelude::*;
314}
315
316/// Reexport `freya-terminal` when the `terminal` feature is enabled.
317#[cfg(feature = "terminal")]
318#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
319pub mod terminal {
320    pub use freya_terminal::prelude::*;
321}
322
323/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
324#[cfg(feature = "code-editor")]
325#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
326pub mod code_editor {
327    pub use freya_code_editor::prelude::*;
328}
329
330#[cfg(feature = "performance")]
331#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
332pub mod performance {
333    pub use freya_performance_plugin::*;
334}
335
336#[cfg(target_os = "android")]
337pub mod android {
338    pub use freya_android::*;
339}
340
341#[cfg(doc)]
342pub mod _docs;