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        docking::*,
193        drag_drop::*,
194        draggable_canvas::*,
195        element_expansions::*,
196        floating_tab::*,
197        gallery,
198        get_theme,
199        icons::{
200            arrow::*,
201            tick::*,
202        },
203        image_viewer::*,
204        input::*,
205        loader::*,
206        menu::*,
207        overflowed_content::*,
208        popup::*,
209        portal::*,
210        progressbar::*,
211        radio_item::*,
212        resizable_container::*,
213        scrollviews::*,
214        segmented_button::*,
215        select::*,
216        selectable_text::*,
217        sidebar::*,
218        skeleton::*,
219        slider::*,
220        switch::*,
221        table::*,
222        theming::{
223            component_themes::{
224                ColorsSheet,
225                Theme,
226            },
227            extensions::*,
228            hooks::*,
229            macros::Preference,
230            themes::*,
231        },
232        tile::*,
233        tooltip::*,
234        typography::*,
235    };
236}
237
238pub mod text_edit {
239    pub use freya_edit::*;
240}
241
242pub mod clipboard {
243    pub use freya_clipboard::prelude::*;
244}
245
246pub mod animation {
247    pub use freya_animation::prelude::*;
248}
249
250#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
251#[cfg(feature = "plot")]
252pub mod plot {
253    pub use freya_plotters_backend::*;
254    pub use plotters;
255}
256
257#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
258#[cfg(feature = "router")]
259pub mod router {
260    pub use freya_router::prelude::*;
261}
262
263#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
264#[cfg(feature = "i18n")]
265pub mod i18n {
266    pub use freya_i18n::prelude::*;
267}
268
269#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
270#[cfg(feature = "engine")]
271pub mod engine {
272    pub use freya_engine::*;
273}
274
275#[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
276#[cfg(feature = "winit")]
277pub mod winit {
278    pub use freya_winit::winit::*;
279}
280
281pub mod helpers {
282    pub use freya_core::helpers::*;
283}
284
285#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
286#[cfg(feature = "tray")]
287pub mod tray {
288    pub use freya_winit::tray::*;
289}
290
291#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
292#[cfg(feature = "sdk")]
293pub mod sdk {
294    pub use freya_sdk::prelude::*;
295}
296
297#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
298#[cfg(feature = "material-design")]
299pub mod material_design {
300    pub use freya_material_design::prelude::*;
301}
302
303#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
304#[cfg(feature = "icons")]
305pub mod icons {
306    pub use freya_icons::*;
307}
308
309/// Reexport `freya-radio` when the `radio` feature is enabled.
310#[cfg(feature = "radio")]
311#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
312pub mod radio {
313    pub use freya_radio::prelude::*;
314}
315
316/// Reexport `freya-query` when the `query` feature is enabled.
317#[cfg(feature = "query")]
318#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
319pub mod query {
320    pub use freya_query::prelude::*;
321}
322
323/// Reexport `freya-webview` when the `webview` feature is enabled.
324#[cfg(feature = "webview")]
325#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
326pub mod webview {
327    pub use freya_webview::prelude::*;
328}
329
330/// Reexport `freya-terminal` when the `terminal` feature is enabled.
331#[cfg(feature = "terminal")]
332#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
333pub mod terminal {
334    pub use freya_terminal::prelude::*;
335}
336
337/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
338#[cfg(feature = "code-editor")]
339#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
340pub mod code_editor {
341    pub use freya_code_editor::prelude::*;
342}
343
344/// Reexport `freya-camera` when the `camera` feature is enabled.
345#[cfg(feature = "camera")]
346#[cfg_attr(feature = "docs", doc(cfg(feature = "camera")))]
347pub mod camera {
348    pub use freya_camera::{
349        init,
350        nokhwa,
351        prelude::*,
352    };
353}
354
355#[cfg(feature = "performance")]
356#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
357pub mod performance {
358    pub use freya_performance_plugin::*;
359}
360
361#[cfg(target_os = "android")]
362pub mod android {
363    pub use freya_android::*;
364}
365
366#[cfg(doc)]
367pub mod _docs;