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::Url;
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        svg_viewer::*,
223        switch::*,
224        table::*,
225        theming::{
226            component_themes::{
227                ColorsSheet,
228                Theme,
229            },
230            extensions::*,
231            hooks::*,
232            macros::Preference,
233            themes::*,
234        },
235        tile::*,
236        tooltip::*,
237        typography::*,
238    };
239}
240
241pub mod text_edit {
242    pub use freya_edit::*;
243}
244
245pub mod clipboard {
246    pub use freya_clipboard::prelude::*;
247}
248
249pub mod animation {
250    pub use freya_animation::prelude::*;
251}
252
253#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
254#[cfg(feature = "plot")]
255pub mod plot {
256    pub use freya_plotters_backend::*;
257    pub use plotters;
258}
259
260#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
261#[cfg(feature = "router")]
262pub mod router {
263    pub use freya_router::prelude::*;
264}
265
266#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
267#[cfg(feature = "i18n")]
268pub mod i18n {
269    pub use freya_i18n::prelude::*;
270}
271
272#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
273#[cfg(feature = "engine")]
274pub mod engine {
275    pub use freya_engine::*;
276}
277
278#[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
279#[cfg(feature = "winit")]
280pub mod winit {
281    pub use freya_winit::winit::*;
282}
283
284pub mod helpers {
285    pub use freya_core::helpers::*;
286}
287
288#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
289#[cfg(feature = "tray")]
290pub mod tray {
291    pub use freya_winit::tray::*;
292}
293
294#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
295#[cfg(feature = "sdk")]
296pub mod sdk {
297    pub use freya_sdk::prelude::*;
298}
299
300#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
301#[cfg(feature = "material-design")]
302pub mod material_design {
303    pub use freya_material_design::prelude::*;
304}
305
306#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
307#[cfg(feature = "icons")]
308pub mod icons {
309    pub use freya_icons::*;
310}
311
312/// Reexport `freya-radio` when the `radio` feature is enabled.
313#[cfg(feature = "radio")]
314#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
315pub mod radio {
316    pub use freya_radio::prelude::*;
317}
318
319/// Reexport `freya-query` when the `query` feature is enabled.
320#[cfg(feature = "query")]
321#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
322pub mod query {
323    pub use freya_query::prelude::*;
324}
325
326/// Reexport `freya-webview` when the `webview` feature is enabled.
327#[cfg(feature = "webview")]
328#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
329pub mod webview {
330    pub use freya_webview::prelude::*;
331}
332
333/// Reexport `freya-terminal` when the `terminal` feature is enabled.
334#[cfg(feature = "terminal")]
335#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
336pub mod terminal {
337    pub use freya_terminal::prelude::*;
338}
339
340/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
341#[cfg(feature = "code-editor")]
342#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
343pub mod code_editor {
344    pub use freya_code_editor::prelude::*;
345}
346
347/// Reexport `freya-camera` when the `camera` feature is enabled.
348#[cfg(feature = "camera")]
349#[cfg_attr(feature = "docs", doc(cfg(feature = "camera")))]
350pub mod camera {
351    pub use freya_camera::{
352        init,
353        nokhwa,
354        prelude::*,
355    };
356}
357
358/// Reexport `freya-video` when the `video` feature is enabled.
359#[cfg(feature = "video")]
360#[cfg_attr(feature = "docs", doc(cfg(feature = "video")))]
361pub mod video {
362    pub use freya_video::*;
363}
364
365#[cfg(feature = "performance")]
366#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
367pub mod performance {
368    pub use freya_performance_plugin::*;
369}
370
371/// Reexport `freya-markdown` when the `markdown` feature is enabled.
372#[cfg(feature = "markdown")]
373#[cfg_attr(feature = "docs", doc(cfg(feature = "markdown")))]
374pub mod markdown {
375    pub use freya_markdown::*;
376}
377
378#[cfg(target_os = "android")]
379pub mod android {
380    pub use freya_android::*;
381}
382
383#[cfg(doc)]
384pub mod _docs;