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