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//! - [Async](self::_docs::_async)
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//! - [Freya Query](freya_query)
60//! - [Tokio Integration](self::_docs::tokio_integration)
61//! - [Devtools](self::_docs::devtools)
62//! - [Hot Reload](self::_docs::hot_reload)
63//!
64//! ## Features flags
65//!
66//! - `all`: Enables all the features listed below
67//! - `router`: Reexport [freya_router] under [router]
68//! - `i18n`: Reexport [freya_i18n] under [i18n]
69//! - `remote-asset`: Enables support for **HTTP** asset sources for [ImageViewer](components::ImageViewer) and [GifViewer](components::GifViewer) components.
70//! - `tray`: Enables tray support using the [tray_icon] crate.
71//! - `sdk`: Reexport [freya_sdk] under [sdk].
72//! - `gif`: Enables the [GifViewer](components::GifViewer) component.
73//! - `plot`: Reexport of plotters under [plot].
74//! - `material-design`: Reexport [freya_material_design] under [material_design].
75//! - `calendar`: Enables the [Calendar](components::Calendar) component.
76//! - `icons`: Reexport of [freya_icons] under [icons].
77//! - `radio`: Reexport [freya_radio] under [radio].
78//! - `query`: Reexport [freya_query] under [query].
79//! - `markdown`: Enables the [MarkdownViewer](components::MarkdownViewer) component.
80//! - `webview`: Reexport [freya_webview] under [webview].
81//! - `titlebar`: Enables the [TitlebarButton](components::TitlebarButton) component.
82//! - `terminal`: Reexport [freya_terminal] under [terminal].
83//! - `code-editor`: Reexport [freya_code_editor] under [code_editor].
84//!
85//! ## Misc features
86//! - `devtools`: Enables devtools support.
87//! - `performance`: Reexports the performance overlay plugin. The plugin is auto-added in debug builds.
88//! - `vulkan`: Enables Vulkan rendering support.
89//! - `hotpath`: Enables Freya's internal usage of hotpath.
90//! - `hotreload`: Enables hot reload support via the `dx` CLI from `dioxus-cli`. See [Hot Reload](self::_docs::hot_reload).
91
92pub mod prelude {
93    pub use freya_core::prelude::*;
94    pub use freya_edit::{
95        Clipboard,
96        ClipboardError,
97    };
98    pub use freya_winit::{
99        WindowDragExt,
100        WinitPlatformExt,
101        config::{
102            CloseDecision,
103            LaunchConfig,
104            WindowConfig,
105        },
106        renderer::{
107            NativeEvent,
108            RendererContext,
109        },
110    };
111
112    pub use crate::components::*;
113
114    pub fn launch(launch_config: LaunchConfig) {
115        #[cfg(feature = "devtools")]
116        let launch_config = launch_config.with_plugin(freya_devtools::DevtoolsPlugin::default());
117        #[cfg(debug_assertions)]
118        let launch_config = launch_config
119            .with_plugin(freya_performance_plugin::PerformanceOverlayPlugin::default());
120        freya_winit::launch(launch_config)
121    }
122
123    #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
124    #[cfg(feature = "router")]
125    pub use freya_router;
126    pub use torin::{
127        alignment::Alignment,
128        content::Content,
129        direction::Direction,
130        gaps::Gaps,
131        geometry::{
132            Area,
133            CursorPoint,
134            Size2D,
135        },
136        position::Position,
137        size::Size,
138        visible_size::VisibleSize,
139    };
140}
141pub mod elements {
142    pub use freya_core::elements::*;
143}
144
145pub mod components {
146    #[cfg_attr(feature = "docs", doc(cfg(feature = "gif")))]
147    #[cfg(feature = "gif")]
148    pub use freya_components::gif_viewer::*;
149    #[cfg_attr(feature = "docs", doc(cfg(feature = "markdown")))]
150    #[cfg(feature = "markdown")]
151    pub use freya_components::markdown::*;
152    cfg_if::cfg_if! {
153        if #[cfg(feature = "router")] {
154            #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
155            pub use freya_components::activable_route::*;
156            pub use freya_components::link::*;
157            pub use freya_components::native_router::*;
158            pub use freya_components::animated_router::*;
159        }
160    }
161    #[cfg_attr(feature = "docs", doc(cfg(feature = "remote-asset")))]
162    #[cfg(feature = "remote-asset")]
163    pub use freya_components::Uri;
164    #[cfg_attr(feature = "docs", doc(cfg(feature = "calendar")))]
165    #[cfg(feature = "calendar")]
166    pub use freya_components::calendar::*;
167    #[cfg(feature = "titlebar")]
168    pub use freya_components::titlebar::*;
169    pub use freya_components::{
170        accordion::*,
171        activable_route_context::*,
172        attached::*,
173        button::*,
174        canvas::*,
175        card::*,
176        checkbox::*,
177        chip::*,
178        color_picker::*,
179        context_menu::*,
180        cursor_area::*,
181        define_theme,
182        drag_drop::*,
183        draggable_canvas::*,
184        element_expansions::*,
185        floating_tab::*,
186        gallery,
187        get_theme,
188        icons::{
189            arrow::*,
190            tick::*,
191        },
192        image_viewer::*,
193        input::*,
194        loader::*,
195        menu::*,
196        overflowed_content::*,
197        popup::*,
198        portal::*,
199        progressbar::*,
200        radio_item::*,
201        resizable_container::*,
202        scrollviews::*,
203        segmented_button::*,
204        select::*,
205        selectable_text::*,
206        sidebar::*,
207        skeleton::*,
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;