From cfef2383fe64c4247f4c1df3d3b5466fc30b1814 Mon Sep 17 00:00:00 2001 From: Matt Hunzinger Date: Sun, 17 Nov 2024 22:46:42 -0500 Subject: [PATCH] Add example to root docs --- src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c94cd0a..7332fe3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,41 @@ //! # Actuate //! Actuate is a native, declarative, and friendly user-interface (UI) framework. //! +//! ```no_run +//! use actuate::prelude::*; +//! +//! #[derive(Data)] +//! struct Counter { +//! start: i32, +//! } +//! +//! impl Compose for Counter { +//! fn compose(cx: Scope) -> impl Compose { +//! let count = use_mut(&cx, || cx.me().start); +//! +//! Window::new(( +//! Text::new(format!("High five count: {}", *count)) +//! .font(GenericFamily::Cursive) +//! .font_size(60.), +//! Text::new("Up high") +//! .on_click(move || count.update(|x| *x += 1)) +//! .background_color(Color::BLUE), +//! Text::new("Down low") +//! .on_click(move || count.update(|x| *x -= 1)) +//! .background_color(Color::RED), +//! if *count == 0 { +//! Some(Text::new("Gimme five!")) +//! } else { +//! None +//! }, +//! )) +//! .font_size(40.) +//! } +//! } +//! +//! actuate::run(Counter { start: 0 }) +//! ``` +//! //! ## Hooks //! Functions that begin with `use_` are called `hooks` in Actuate. //! Hooks are used to manage state and side effects in composables.