Skip to main content

floem/views/
mod.rs

1//! # Floem built-in Views
2//!
3//! This module contains the basic built-in Views of Floem.
4//!
5//! ## Composing Views
6//! The views in this module are the main building blocks for composing UIs in Floem.
7//! There is a collection of different `stacks` and `lists` that can be used to build collections of views.
8//! There are also basic widgets such as [text inputs](text_input::text_input), [labels](label::label), [images](img::img), and [svgs](svg::svg).
9//!
10//! ## Example: Counter
11//! ```rust
12//! use floem::{reactive::*, views::*};
13//!
14//! let mut counter = RwSignal::new(0);
15//!
16//! v_stack((
17//!     label(move || format!("Value: {counter}")),
18//!     h_stack((
19//!         button("Increment").action(move || counter += 1),
20//!         button("Decrement").action(move || counter -= 1),
21//!     )),
22//! ));
23//! ```
24//! Views in Floem can also be easily refactored.
25//! ## Example: Refactored Counter
26//! ```rust
27//! use floem::prelude::*;
28//!
29//! let mut counter = RwSignal::new(0);
30//!
31//! let counter_label = label(move || format!("Value: {counter}"));
32//!
33//! let increment_button = button("Increment").action(move || counter += 1);
34//! let decrement_button = button("Decrement").action(move || counter -= 1);
35//!
36//! let button_stack = (increment_button, decrement_button).h_stack();
37//!
38//! (counter_label, button_stack).v_stack();
39//! ```
40//!
41//!
42//! ### Stacks and Lists
43//! There are a few different stacks and lists that you can use to group your views and each is discussed here.
44//!
45//!
46//! They are:
47//! - basic [stack](stack())
48//!     - static and always contains the same elements in the same order
49//! - [dynamic stack](dyn_stack())
50//!     - can dynamically change the elements in the stack by reactively updating the list of items provided
51//! - [virtual stack](virtual_stack::virtual_stack())
52//!     - can dynamically change the elements in the stack
53//!     - can lazily load the items as they appear in a [scroll view](scroll())
54//!
55//! There is also a basic [list](list()) and a [virtual list](virtual_list::virtual_list()).
56//! Lists are like their stack counterparts but they also have built-in support for the selection of items: up and down using arrow keys, top and bottom control using the home and end keys, and for the "acceptance" of an item using the Enter key.
57//! You could build this manually yourself using stacks but it is common enough that it is built-in as a list.
58//!
59//! ## View Trait
60//! The [`View`](crate::View) trait is the trait that Floem uses to build and display elements.
61//! The trait contains the methods for implementing updates, styling, layout, events, and painting.
62//!
63//! Views are types that implement `View`.
64//! Many of these types will also be built with a child that also implements `View`.
65//! In this way, views can be composed together easily to create complex UIs.
66//! This composition is the most common way to build UIs in Floem.
67//!
68//! Creating a type and manually implementing the View trait is typically only needed for building new widgets and for special cases.
69
70mod label;
71pub use label::*;
72
73mod rich_text;
74pub use rich_text::*;
75
76pub(crate) mod dyn_stack;
77pub use dyn_stack::*;
78
79mod svg;
80pub use svg::*;
81
82mod clip;
83pub use clip::*;
84
85mod container;
86pub use container::*;
87
88mod dyn_container;
89pub use dyn_container::*;
90
91mod dyn_view;
92pub use dyn_view::*;
93
94mod value_container;
95pub use value_container::*;
96
97mod decorator;
98pub use decorator::*;
99
100mod list;
101pub use list::*;
102
103mod navigation_stack;
104pub use navigation_stack::*;
105
106mod virtual_list;
107pub use virtual_list::*;
108
109mod virtual_stack;
110pub use virtual_stack::*;
111
112pub mod scroll;
113pub use scroll::{Scroll, ScrollExt};
114
115mod tab;
116pub use tab::*;
117
118mod tooltip;
119pub use tooltip::*;
120
121mod overlay;
122pub use overlay::*;
123
124mod stack;
125pub use stack::*;
126
127mod text_input;
128pub use text_input::*;
129
130mod empty;
131pub use empty::*;
132
133mod stem;
134pub use stem::Stem;
135
136mod canvas;
137pub use canvas::*;
138
139mod drag_window_area;
140pub use drag_window_area::*;
141
142mod drag_resize_window_area;
143pub use drag_resize_window_area::*;
144
145mod img;
146pub use img::*;
147
148mod button;
149pub use button::*;
150
151#[cfg(feature = "editor")]
152pub mod editor;
153
154#[cfg(feature = "editor")]
155pub mod text_editor;
156
157#[cfg(feature = "editor")]
158pub use text_editor::*;
159
160pub mod dropdown;
161
162pub mod slider;
163
164pub mod resizable;
165
166mod radio_button;
167pub use radio_button::*;
168
169mod checkbox;
170pub use checkbox::*;
171
172mod toggle_button;
173pub use toggle_button::*;
174
175#[cfg(feature = "localization")]
176pub mod localization;