freya 0.4.0

Cross-platform and non-web GUI Library powered by Skia.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#![doc(
    html_logo_url = "https://freyaui.dev/logo.svg",
    html_favicon_url = "https://freyaui.dev/logo.svg"
)]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
//! # Freya
//!
//! **Freya** is a declarative, cross-platform GUI 🦀 Rust library, powered by 🎨 [Skia](https://skia.org/).
//!
//! #### Example
//!
//! ```rust, no_run
//! # use freya::prelude::*;
//! fn main() {
//!     // *Start* your app with a window and its root component
//!     launch(LaunchConfig::new().with_window(WindowConfig::new(app)))
//! }
//!
//! fn app() -> impl IntoElement {
//!     // Define a reactive *state*
//!     let mut count = use_state(|| 0);
//!
//!     // Declare the *UI*
//!     rect()
//!         .width(Size::fill())
//!         .height(Size::fill())
//!         .background((35, 35, 35))
//!         .color(Color::WHITE)
//!         .padding(Gaps::new_all(12.))
//!         .on_mouse_up(move |_| *count.write() += 1)
//!         .child(format!("Click to increase -> {}", count.read()))
//! }
//! ```
//!
//! ### Basics
//! - [UI and Components](self::_docs::ui_and_components)
//! - [Elements](self::elements)
//! - [Events](self::_docs::events)
//! - [Hooks](self::_docs::hooks)
//! - [State](self::_docs::state_management)
//! - [Async](self::_docs::_async)
//! - [Layers](self::_docs::layers)
//! - [Platforms](self::_docs::platforms)
//! - [Development Setup](self::_docs::development_setup)
//! - [Extending Components](self::_docs::extending_components)
//!
//! ### Learn
//! - [Built-in Components](crate::components)
//! - [Built-in Components Gallery](crate::components::gallery)
//! - [i18n](freya_i18n)
//! - [Animation](freya_animation)
//! - [Routing](freya_router)
//! - [Clipboard](freya_clipboard)
//! - [Icons](freya_icons)
//! - [Material Design](freya_material_design)
//! - [Plotters](freya_plotters_backend)
//! - [Testing](freya_testing)
//! - [WebView](freya_webview)
//! - [Terminal](freya_terminal)
//! - [Camera](freya_camera)
//! - [Video](freya_video)
//! - [Freya Query](freya_query)
//! - [Tokio Integration](self::_docs::tokio_integration)
//! - [Devtools](self::_docs::devtools)
//! - [Hot Reload](self::_docs::hot_reload)
//!
//! ## Features flags
//!
//! - `all`: Enables all the features listed below
//! - `winit`: Reexports [freya_winit] and enables the launch entrypoint. Enabled by default.
//! - `router`: Reexport [freya_router] under [router]
//! - `i18n`: Reexport [freya_i18n] under [i18n]
//! - `remote-asset`: Enables support for **HTTP** asset sources for [ImageViewer](components::ImageViewer) and [GifViewer](components::GifViewer) components.
//! - `tray`: Enables tray support using the [tray_icon] crate.
//! - `sdk`: Reexport [freya_sdk] under [sdk].
//! - `gif`: Enables the [GifViewer](components::GifViewer) component.
//! - `video`: Reexport [freya_video] under [video].
//! - `plot`: Reexport of plotters under [plot].
//! - `material-design`: Reexport [freya_material_design] under [material_design].
//! - `calendar`: Enables the [Calendar](components::Calendar) component.
//! - `icons`: Reexport of [freya_icons] under [icons].
//! - `radio`: Reexport [freya_radio] under [radio].
//! - `query`: Reexport [freya_query] under [query].
//! - `markdown`: Reexport [freya_markdown] under [markdown].
//! - `webview`: Reexport [freya_webview] under [webview].
//! - `titlebar`: Enables the [TitlebarButton](components::TitlebarButton) component.
//! - `terminal`: Reexport [freya_terminal] under [terminal].
//! - `code-editor`: Reexport [freya_code_editor] under [code_editor].
//! - `camera`: Reexport [freya_camera] under [camera].
//!
//! ## Misc features
//! - `devtools`: Enables devtools support.
//! - `performance`: Reexports the performance overlay plugin. The plugin is auto-added in debug builds.
//! - `vulkan`: Enables Vulkan rendering support.
//! - `hotpath`: Enables Freya's internal usage of hotpath.
//! - `hotreload`: Enables hot reload support via the `dx` CLI from `dioxus-cli`. See [Hot Reload](self::_docs::hot_reload).
//! - `zoom-shortcuts`: Enables `Ctrl`/`Cmd` + `+`/`-`/`0` to zoom the app.

/// Common imports to build Freya apps, use it with `use freya::prelude::*;`.
pub mod prelude {
    pub use freya_core::prelude::*;
    pub use freya_edit::{
        Clipboard,
        ClipboardError,
    };
    #[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
    #[cfg(feature = "winit")]
    pub use freya_winit::{
        WindowDragExt,
        WinitPlatformExt,
        config::{
            CloseDecision,
            LaunchConfig,
            WindowConfig,
        },
        renderer::{
            NativeEvent,
            RendererContext,
        },
    };

    pub use crate::components::*;
    #[cfg_attr(feature = "docs", doc(cfg(feature = "markdown")))]
    #[cfg(feature = "markdown")]
    pub use crate::markdown::*;

    #[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
    #[cfg(feature = "winit")]
    pub fn launch(launch_config: LaunchConfig) {
        #[cfg(feature = "devtools")]
        let launch_config = launch_config.with_plugin(freya_devtools::DevtoolsPlugin::default());
        #[cfg(debug_assertions)]
        let launch_config = launch_config
            .with_plugin(freya_performance_plugin::PerformanceOverlayPlugin::default());
        freya_winit::launch(launch_config)
    }

    #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
    #[cfg(feature = "router")]
    pub use freya_router;
    pub use torin::{
        alignment::Alignment,
        content::Content,
        direction::Direction,
        gaps::Gaps,
        geometry::{
            Area,
            CursorPoint,
            Size2D,
        },
        position::Position,
        size::Size,
        visible_size::VisibleSize,
    };
}
/// Built-in elements like `rect`, `label` or `paragraph`.
pub mod elements {
    pub use freya_core::elements::*;
}

/// Built-in components like `Button`, `Input` or `ScrollView`.
pub mod components {
    #[cfg_attr(feature = "docs", doc(cfg(feature = "gif")))]
    #[cfg(feature = "gif")]
    pub use freya_components::gif_viewer::*;
    cfg_if::cfg_if! {
        if #[cfg(feature = "router")] {
            #[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
            pub use freya_components::activable_route::*;
            pub use freya_components::link::*;
            pub use freya_components::native_router::*;
            pub use freya_components::animated_router::*;
        }
    }
    #[cfg_attr(feature = "docs", doc(cfg(feature = "remote-asset")))]
    #[cfg(feature = "remote-asset")]
    pub use freya_components::Url;
    #[cfg_attr(feature = "docs", doc(cfg(feature = "calendar")))]
    #[cfg(feature = "calendar")]
    pub use freya_components::calendar::*;
    #[cfg(feature = "titlebar")]
    pub use freya_components::titlebar::*;
    pub use freya_components::{
        accordion::*,
        activable::*,
        activable_context::*,
        attached::*,
        button::*,
        canvas::*,
        card::*,
        checkbox::*,
        chip::*,
        color_picker::*,
        context_menu::*,
        cursor_area::*,
        define_theme,
        docking::*,
        drag_drop::*,
        draggable_canvas::*,
        element_expansions::*,
        floating_tab::*,
        gallery,
        get_theme,
        icons::{
            arrow::*,
            tick::*,
        },
        image_viewer::*,
        input::*,
        loader::*,
        menu::*,
        overflowed_content::*,
        popup::*,
        portal::*,
        progressbar::*,
        radio_item::*,
        resizable_container::*,
        scrollviews::*,
        segmented_button::*,
        select::*,
        selectable_text::*,
        sidebar::*,
        skeleton::*,
        slider::*,
        svg_viewer::*,
        switch::*,
        table::*,
        theming::{
            component_themes::{
                ColorsSheet,
                Theme,
            },
            extensions::*,
            hooks::*,
            macros::Preference,
            themes::*,
        },
        tile::*,
        tooltip::*,
        typography::*,
    };
}

/// Reexport `freya-edit`, the text editing APIs.
pub mod text_edit {
    pub use freya_edit::*;
}

/// Reexport `freya-clipboard`.
pub mod clipboard {
    pub use freya_clipboard::prelude::*;
}

/// Reexport `freya-animation`.
pub mod animation {
    pub use freya_animation::prelude::*;
}

/// Reexport `freya-plotters-backend` and `plotters` when the `plot` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
#[cfg(feature = "plot")]
pub mod plot {
    pub use freya_plotters_backend::*;
    pub use plotters;
}

/// Reexport `freya-router` when the `router` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
#[cfg(feature = "router")]
pub mod router {
    pub use freya_router::prelude::*;
}

/// Reexport `freya-i18n` when the `i18n` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
#[cfg(feature = "i18n")]
pub mod i18n {
    pub use freya_i18n::prelude::*;
}

/// Reexport `freya-engine` when the `engine` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
#[cfg(feature = "engine")]
pub mod engine {
    pub use freya_engine::*;
}

/// Reexport `winit` when the `winit` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "winit")))]
#[cfg(feature = "winit")]
pub mod winit {
    pub use freya_winit::winit::*;
}

/// Helpers to build elements out of plain functions.
pub mod helpers {
    pub use freya_core::helpers::*;
}

/// Reexport `tray-icon` when the `tray` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
#[cfg(feature = "tray")]
pub mod tray {
    pub use freya_winit::tray::*;
}

/// Reexport `freya-sdk` when the `sdk` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
#[cfg(feature = "sdk")]
pub mod sdk {
    pub use freya_sdk::prelude::*;
}

/// Reexport `freya-material-design` when the `material-design` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
#[cfg(feature = "material-design")]
pub mod material_design {
    pub use freya_material_design::prelude::*;
}

/// Reexport `freya-icons` when the `icons` feature is enabled.
#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
#[cfg(feature = "icons")]
pub mod icons {
    pub use freya_icons::*;
}

/// Reexport `freya-radio` when the `radio` feature is enabled.
#[cfg(feature = "radio")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
pub mod radio {
    pub use freya_radio::prelude::*;
}

/// Reexport `freya-query` when the `query` feature is enabled.
#[cfg(feature = "query")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
pub mod query {
    pub use freya_query::prelude::*;
}

/// Reexport `freya-webview` when the `webview` feature is enabled.
#[cfg(feature = "webview")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
pub mod webview {
    pub use freya_webview::prelude::*;
}

/// Reexport `freya-terminal` when the `terminal` feature is enabled.
#[cfg(feature = "terminal")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
pub mod terminal {
    pub use freya_terminal::prelude::*;
}

/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
#[cfg(feature = "code-editor")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
pub mod code_editor {
    pub use freya_code_editor::prelude::*;
}

/// Reexport `freya-camera` when the `camera` feature is enabled.
#[cfg(feature = "camera")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "camera")))]
pub mod camera {
    pub use freya_camera::{
        init,
        nokhwa,
        prelude::*,
    };
}

/// Reexport `freya-video` when the `video` feature is enabled.
#[cfg(feature = "video")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "video")))]
pub mod video {
    pub use freya_video::*;
}

/// Reexport `freya-performance-plugin` when the `performance` feature is enabled.
#[cfg(feature = "performance")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
pub mod performance {
    pub use freya_performance_plugin::*;
}

/// Reexport `freya-markdown` when the `markdown` feature is enabled.
#[cfg(feature = "markdown")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "markdown")))]
pub mod markdown {
    pub use freya_markdown::*;
}

/// Reexport `freya-android` when targeting Android.
#[cfg(target_os = "android")]
pub mod android {
    pub use freya_android::*;
}

/// Freya guides.
#[cfg(doc)]
pub mod _docs;