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        drag_drop::*,
178        draggable_canvas::*,
179        element_expansions::*,
180        floating_tab::*,
181        gallery,
182        get_theme,
183        icons::{
184            arrow::*,
185            tick::*,
186        },
187        image_viewer::*,
188        input::*,
189        loader::*,
190        menu::*,
191        overflowed_content::*,
192        popup::*,
193        portal::*,
194        progressbar::*,
195        radio_item::*,
196        resizable_container::*,
197        scrollviews::*,
198        segmented_button::*,
199        select::*,
200        selectable_text::*,
201        sidebar::*,
202        slider::*,
203        switch::*,
204        table::*,
205        theming::{
206            component_themes::*,
207            extensions::*,
208            hooks::*,
209            macros::Preference,
210            themes::*,
211        },
212        tile::*,
213        tooltip::*,
214    };
215}
216
217pub mod text_edit {
218    pub use freya_edit::*;
219}
220
221pub mod clipboard {
222    pub use freya_clipboard::prelude::*;
223}
224
225pub mod animation {
226    pub use freya_animation::prelude::*;
227}
228
229#[cfg_attr(feature = "docs", doc(cfg(feature = "plot")))]
230#[cfg(feature = "plot")]
231pub mod plot {
232    pub use freya_plotters_backend::*;
233    pub use plotters;
234}
235
236#[cfg_attr(feature = "docs", doc(cfg(feature = "router")))]
237#[cfg(feature = "router")]
238pub mod router {
239    pub use freya_router::prelude::*;
240}
241
242#[cfg_attr(feature = "docs", doc(cfg(feature = "i18n")))]
243#[cfg(feature = "i18n")]
244pub mod i18n {
245    pub use freya_i18n::prelude::*;
246}
247
248#[cfg_attr(feature = "docs", doc(cfg(feature = "engine")))]
249#[cfg(feature = "engine")]
250pub mod engine {
251    pub use freya_engine::*;
252}
253
254pub mod winit {
255    pub use freya_winit::winit::*;
256}
257
258pub mod helpers {
259    pub use freya_core::helpers::*;
260}
261
262#[cfg_attr(feature = "docs", doc(cfg(feature = "tray")))]
263#[cfg(feature = "tray")]
264pub mod tray {
265    pub use freya_winit::tray::*;
266}
267
268#[cfg_attr(feature = "docs", doc(cfg(feature = "sdk")))]
269#[cfg(feature = "sdk")]
270pub mod sdk {
271    pub use freya_sdk::prelude::*;
272}
273
274#[cfg_attr(feature = "docs", doc(cfg(feature = "material-design")))]
275#[cfg(feature = "material-design")]
276pub mod material_design {
277    pub use freya_material_design::prelude::*;
278}
279
280#[cfg_attr(feature = "docs", doc(cfg(feature = "icons")))]
281#[cfg(feature = "icons")]
282pub mod icons {
283    pub use freya_icons::*;
284}
285
286/// Reexport `freya-radio` when the `radio` feature is enabled.
287#[cfg(feature = "radio")]
288#[cfg_attr(feature = "docs", doc(cfg(feature = "radio")))]
289pub mod radio {
290    pub use freya_radio::prelude::*;
291}
292
293/// Reexport `freya-query` when the `query` feature is enabled.
294#[cfg(feature = "query")]
295#[cfg_attr(feature = "docs", doc(cfg(feature = "query")))]
296pub mod query {
297    pub use freya_query::prelude::*;
298}
299
300/// Reexport `freya-webview` when the `webview` feature is enabled.
301#[cfg(feature = "webview")]
302#[cfg_attr(feature = "docs", doc(cfg(feature = "webview")))]
303pub mod webview {
304    pub use freya_webview::prelude::*;
305}
306
307/// Reexport `freya-terminal` when the `terminal` feature is enabled.
308#[cfg(feature = "terminal")]
309#[cfg_attr(feature = "docs", doc(cfg(feature = "terminal")))]
310pub mod terminal {
311    pub use freya_terminal::prelude::*;
312}
313
314/// Reexport `freya-code-editor` when the `code-editor` feature is enabled.
315#[cfg(feature = "code-editor")]
316#[cfg_attr(feature = "docs", doc(cfg(feature = "code-editor")))]
317pub mod code_editor {
318    pub use freya_code_editor::prelude::*;
319}
320
321#[cfg(feature = "performance")]
322#[cfg_attr(feature = "docs", doc(cfg(feature = "performance")))]
323pub mod performance {
324    pub use freya_performance_plugin::*;
325}
326
327#[cfg(doc)]
328pub mod _docs;