freya/_docs/
ui.rs

1//! # UI
2//!
3//! Freya uses a [declarative](https://en.wikipedia.org/wiki/Declarative_programming) model for the UI.
4//!
5//! For example, this is how the app component would look like in Freya:
6//!
7//! ```rust, no_run
8//! # use freya::prelude::*;
9//! fn app() -> impl IntoElement {
10//!     rect()
11//!         .background((255, 0, 0))
12//!         .width(Size::fill())
13//!         .height(Size::px(100.))
14//!         .on_mouse_up(|_| println!("Clicked!"))
15//! }
16//! ```
17//!
18//! Notice that the `app` component is returning an [`Element`](freya_core::prelude::Element), this is because `rect()` gives you a [`Rect`](freya_core::elements::rect::Rect) which implements `Into<Element>`. So, in other words, the [`Element`](freya_core::prelude::Element) contains the UI of that component.
19//! Every time the component function reruns a new UI is created and later diffed by Freya internally.