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        skeleton::*,
205        slider::*,
206        switch::*,
207        table::*,
208        theming::{
209            component_themes::{
210                ColorsSheet,
211                Theme,
212            },
213            extensions::*,
214            hooks::*,
215            macros::Preference,
216            themes::*,
217        },
218        tile::*,
219        tooltip::*,
220    };
221}
222
223pub mod text_edit {
224    pub use freya_edit::*;
225}
226
227pub mod clipboard {
228    pub use freya_clipboard::prelude::*;
229}
230
231pub mod animation {
232    pub use freya_animation::prelude::*;
233}
234
235#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
236#[cfg(feature = "plot")]
237pub mod plot {
238    pub use freya_plotters_backend::*;
239    pub use plotters;
240}
241
242#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
243#[cfg(feature = "router")]
244pub mod router {
245    pub use freya_router::prelude::*;
246}
247
248#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
249#[cfg(feature = "i18n")]
250pub mod i18n {
251    pub use freya_i18n::prelude::*;
252}
253
254#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
255#[cfg(feature = "engine")]
256pub mod engine {
257    pub use freya_engine::*;
258}
259
260pub mod winit {
261    pub use freya_winit::winit::*;
262}
263
264pub mod helpers {
265    pub use freya_core::helpers::*;
266}
267
268#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
269#[cfg(feature = "tray")]
270pub mod tray {
271    pub use freya_winit::tray::*;
272}
273
274#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
275#[cfg(feature = "sdk")]
276pub mod sdk {
277    pub use freya_sdk::prelude::*;
278}
279
280#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
281#[cfg(feature = "material-design")]
282pub mod material_design {
283    pub use freya_material_design::prelude::*;
284}
285
286#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
287#[cfg(feature = "icons")]
288pub mod icons {
289    pub use freya_icons::*;
290}
291
292/// Reexport `freya-radio` when the `radio` feature is enabled.
293#[cfg(feature = "radio")]
294#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
295pub mod radio {
296    pub use freya_radio::prelude::*;
297}
298
299/// Reexport `freya-query` when the `query` feature is enabled.
300#[cfg(feature = "query")]
301#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
302pub mod query {
303    pub use freya_query::prelude::*;
304}
305
306/// Reexport `freya-webview` when the `webview` feature is enabled.
307#[cfg(feature = "webview")]
308#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
309pub mod webview {
310    pub use freya_webview::prelude::*;
311}
312
313/// Reexport `freya-terminal` when the `terminal` feature is enabled.
314#[cfg(feature = "terminal")]
315#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
316pub mod terminal {
317    pub use freya_terminal::prelude::*;
318}
319
320/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
321#[cfg(feature = "code-editor")]
322#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
323pub mod code_editor {
324    pub use freya_code_editor::prelude::*;
325}
326
327#[cfg(feature = "performance")]
328#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
329pub mod performance {
330    pub use freya_performance_plugin::*;
331}
332
333#[cfg(target_os = "android")]
334pub mod android {
335    pub use freya_android::*;
336}
337
338#[cfg(doc)]
339pub mod _docs;