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