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//! - [Events](self::_docs::events)
39//! - [Hooks](self::_docs::hooks)
40//! - [State](self::_docs::state_management)
41//! - [Async](self::_docs::_async)
42//! - [Layers](self::_docs::layers)
43//! - [Platforms](self::_docs::platforms)
44//! - [Development Setup](self::_docs::development_setup)
45//! - [Extending Components](self::_docs::extending_components)
46//!
47//! ### Learn
48//! - [Built-in Components](crate::components)
49//! - [Built-in Components Gallery](crate::components::gallery)
50//! - [i18n](freya_i18n)
51//! - [Animation](freya_animation)
52//! - [Routing](freya_router)
53//! - [Clipboard](freya_clipboard)
54//! - [Icons](freya_icons)
55//! - [Material Design](freya_material_design)
56//! - [Plotters](freya_plotters_backend)
57//! - [Testing](freya_testing)
58//! - [WebView](freya_webview)
59//! - [Terminal](freya_terminal)
60//! - [Camera](freya_camera)
61//! - [Freya Query](freya_query)
62//! - [Tokio Integration](self::_docs::tokio_integration)
63//! - [Devtools](self::_docs::devtools)
64//! - [Hot Reload](self::_docs::hot_reload)
65//!
66//! ## Features flags
67//!
68//! - `all`: Enables all the features listed below
69//! - `winit`: Reexports [freya_winit] and enables the launch entrypoint. Enabled by default.
70//! - `router`: Reexport [freya_router] under [router]
71//! - `i18n`: Reexport [freya_i18n] under [i18n]
72//! - `remote-asset`: Enables support for **HTTP** asset sources for [ImageViewer](components::ImageViewer) and [GifViewer](components::GifViewer) components.
73//! - `tray`: Enables tray support using the [tray_icon] crate.
74//! - `sdk`: Reexport [freya_sdk] under [sdk].
75//! - `gif`: Enables the [GifViewer](components::GifViewer) component.
76//! - `plot`: Reexport of plotters under [plot].
77//! - `material-design`: Reexport [freya_material_design] under [material_design].
78//! - `calendar`: Enables the [Calendar](components::Calendar) component.
79//! - `icons`: Reexport of [freya_icons] under [icons].
80//! - `radio`: Reexport [freya_radio] under [radio].
81//! - `query`: Reexport [freya_query] under [query].
82//! - `markdown`: Enables the [MarkdownViewer](components::MarkdownViewer) component.
83//! - `webview`: Reexport [freya_webview] under [webview].
84//! - `titlebar`: Enables the [TitlebarButton](components::TitlebarButton) component.
85//! - `terminal`: Reexport [freya_terminal] under [terminal].
86//! - `code-editor`: Reexport [freya_code_editor] under [code_editor].
87//! - `camera`: Reexport [freya_camera] under [camera].
88//!
89//! ## Misc features
90//! - `devtools`: Enables devtools support.
91//! - `performance`: Reexports the performance overlay plugin. The plugin is auto-added in debug builds.
92//! - `vulkan`: Enables Vulkan rendering support.
93//! - `hotpath`: Enables Freya's internal usage of hotpath.
94//! - `hotreload`: Enables hot reload support via the `dx` CLI from `dioxus-cli`. See [Hot Reload](self::_docs::hot_reload).
95//! - `zoom-shortcuts`: Enables `Ctrl`/`Cmd` + `+`/`-`/`0` to zoom the app.
96
97pub mod prelude {
98    pub use freya_core::prelude::*;
99    pub use freya_edit::{
100        Clipboard,
101        ClipboardError,
102    };
103    #[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
104    #[cfg(feature = "winit")]
105    pub use freya_winit::{
106        WindowDragExt,
107        WinitPlatformExt,
108        config::{
109            CloseDecision,
110            LaunchConfig,
111            WindowConfig,
112        },
113        renderer::{
114            NativeEvent,
115            RendererContext,
116        },
117    };
118
119    pub use crate::components::*;
120
121    #[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
122    #[cfg(feature = "winit")]
123    pub fn launch(launch_config: LaunchConfig) {
124        #[cfg(feature = "devtools")]
125        let launch_config = launch_config.with_plugin(freya_devtools::DevtoolsPlugin::default());
126        #[cfg(debug_assertions)]
127        let launch_config = launch_config
128            .with_plugin(freya_performance_plugin::PerformanceOverlayPlugin::default());
129        freya_winit::launch(launch_config)
130    }
131
132    #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
133    #[cfg(feature = "router")]
134    pub use freya_router;
135    pub use torin::{
136        alignment::Alignment,
137        content::Content,
138        direction::Direction,
139        gaps::Gaps,
140        geometry::{
141            Area,
142            CursorPoint,
143            Size2D,
144        },
145        position::Position,
146        size::Size,
147        visible_size::VisibleSize,
148    };
149}
150pub mod elements {
151    pub use freya_core::elements::*;
152}
153
154pub mod components {
155    #[cfg_attr(feature = "docs", doc(cfg(feature = "gif")))]
156    #[cfg(feature = "gif")]
157    pub use freya_components::gif_viewer::*;
158    #[cfg_attr(feature = "docs", doc(cfg(feature = "markdown")))]
159    #[cfg(feature = "markdown")]
160    pub use freya_components::markdown::*;
161    cfg_if::cfg_if! {
162        if #[cfg(feature = "router")] {
163            #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
164            pub use freya_components::activable_route::*;
165            pub use freya_components::link::*;
166            pub use freya_components::native_router::*;
167            pub use freya_components::animated_router::*;
168        }
169    }
170    #[cfg_attr(feature = "docs", doc(cfg(feature = "remote-asset")))]
171    #[cfg(feature = "remote-asset")]
172    pub use freya_components::Uri;
173    #[cfg_attr(feature = "docs", doc(cfg(feature = "calendar")))]
174    #[cfg(feature = "calendar")]
175    pub use freya_components::calendar::*;
176    #[cfg(feature = "titlebar")]
177    pub use freya_components::titlebar::*;
178    pub use freya_components::{
179        accordion::*,
180        activable::*,
181        activable_context::*,
182        attached::*,
183        button::*,
184        canvas::*,
185        card::*,
186        checkbox::*,
187        chip::*,
188        color_picker::*,
189        context_menu::*,
190        cursor_area::*,
191        define_theme,
192        drag_drop::*,
193        draggable_canvas::*,
194        element_expansions::*,
195        floating_tab::*,
196        gallery,
197        get_theme,
198        icons::{
199            arrow::*,
200            tick::*,
201        },
202        image_viewer::*,
203        input::*,
204        loader::*,
205        menu::*,
206        overflowed_content::*,
207        popup::*,
208        portal::*,
209        progressbar::*,
210        radio_item::*,
211        resizable_container::*,
212        scrollviews::*,
213        segmented_button::*,
214        select::*,
215        selectable_text::*,
216        sidebar::*,
217        skeleton::*,
218        slider::*,
219        switch::*,
220        table::*,
221        theming::{
222            component_themes::{
223                ColorsSheet,
224                Theme,
225            },
226            extensions::*,
227            hooks::*,
228            macros::Preference,
229            themes::*,
230        },
231        tile::*,
232        tooltip::*,
233        typography::*,
234    };
235}
236
237pub mod text_edit {
238    pub use freya_edit::*;
239}
240
241pub mod clipboard {
242    pub use freya_clipboard::prelude::*;
243}
244
245pub mod animation {
246    pub use freya_animation::prelude::*;
247}
248
249#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
250#[cfg(feature = "plot")]
251pub mod plot {
252    pub use freya_plotters_backend::*;
253    pub use plotters;
254}
255
256#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
257#[cfg(feature = "router")]
258pub mod router {
259    pub use freya_router::prelude::*;
260}
261
262#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
263#[cfg(feature = "i18n")]
264pub mod i18n {
265    pub use freya_i18n::prelude::*;
266}
267
268#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
269#[cfg(feature = "engine")]
270pub mod engine {
271    pub use freya_engine::*;
272}
273
274#[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
275#[cfg(feature = "winit")]
276pub mod winit {
277    pub use freya_winit::winit::*;
278}
279
280pub mod helpers {
281    pub use freya_core::helpers::*;
282}
283
284#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
285#[cfg(feature = "tray")]
286pub mod tray {
287    pub use freya_winit::tray::*;
288}
289
290#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
291#[cfg(feature = "sdk")]
292pub mod sdk {
293    pub use freya_sdk::prelude::*;
294}
295
296#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
297#[cfg(feature = "material-design")]
298pub mod material_design {
299    pub use freya_material_design::prelude::*;
300}
301
302#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
303#[cfg(feature = "icons")]
304pub mod icons {
305    pub use freya_icons::*;
306}
307
308/// Reexport `freya-radio` when the `radio` feature is enabled.
309#[cfg(feature = "radio")]
310#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
311pub mod radio {
312    pub use freya_radio::prelude::*;
313}
314
315/// Reexport `freya-query` when the `query` feature is enabled.
316#[cfg(feature = "query")]
317#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
318pub mod query {
319    pub use freya_query::prelude::*;
320}
321
322/// Reexport `freya-webview` when the `webview` feature is enabled.
323#[cfg(feature = "webview")]
324#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
325pub mod webview {
326    pub use freya_webview::prelude::*;
327}
328
329/// Reexport `freya-terminal` when the `terminal` feature is enabled.
330#[cfg(feature = "terminal")]
331#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
332pub mod terminal {
333    pub use freya_terminal::prelude::*;
334}
335
336/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
337#[cfg(feature = "code-editor")]
338#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
339pub mod code_editor {
340    pub use freya_code_editor::prelude::*;
341}
342
343/// Reexport `freya-camera` when the `camera` feature is enabled.
344#[cfg(feature = "camera")]
345#[cfg_attr(feature = "docs", doc(cfg(feature = "camera")))]
346pub mod camera {
347    pub use freya_camera::{
348        init,
349        nokhwa,
350        prelude::*,
351    };
352}
353
354#[cfg(feature = "performance")]
355#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
356pub mod performance {
357    pub use freya_performance_plugin::*;
358}
359
360#[cfg(target_os = "android")]
361pub mod android {
362    pub use freya_android::*;
363}
364
365#[cfg(doc)]
366pub mod _docs;