Skip to main content

mottes_floem_components/
lib.rs

1//! # Floem components
2//!
3//! `floem-components` is a component crate for [floem](https://lap.dev/floem/).
4//! It is split into multiple modules:
5//! 1. `theme` for color theming
6//! 2. `views` for standard floem views
7//! 3. `classes` for floem classes
8//!
9//! ## Quickstart
10//!
11//! ```no_run
12//! use floem::{
13//!     peniko::Color,
14//!     reactive::create_signal,
15//!     views::{button, label, Decorators},
16//!     IntoView,
17//! };
18//! use mottes_floem_components::classes::{construct_theme, Button, Label};
19//! use mottes_floem_components::theme::Theme;
20//!
21//! fn app_view() -> impl IntoView {
22//!     let (counter, mut set_counter) = create_signal(0);
23//!
24//!     (
25//!         label(move || format!("Value: {counter}")).class(Label),
26//!         (
27//!             button("Increment")
28//!                 .action(move || set_counter += 1)
29//!                 .class(Button),
30//!             button("Decrement")
31//!                 .action(move || set_counter -= 1)
32//!                 .class(Button),
33//!         ),
34//!     )
35//!         .style(|_| {
36//!             construct_theme(Theme::dark())
37//!                 .flex_col()
38//!                 .width_full()
39//!                 .height_full()
40//!                 .background(Color::parse(Theme::dark().base00).unwrap())
41//!         })
42//! }
43//!
44//! fn main() {
45//!     floem::launch(app_view);
46//! }
47//! ```
48//!
49//! If you want to see all components in action, look at the [gallery
50//! example](https://codeberg.org/motte/floem-components/src/branch/main/examples/gallery.rs).
51
52use floem::peniko::Color;
53
54pub mod classes;
55pub mod theme;
56pub mod views;
57
58const BORDER_RADIUS: f32 = 7.5;
59
60fn parse_color(color: &str) -> Color {
61    #[allow(clippy::expect_fun_call)]
62    Color::parse(color).expect(format!("failed to parse {color}").as_str())
63}