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