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