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