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