From df1e9e0b185a98814b612fc4c1ba8185b06e9355 Mon Sep 17 00:00:00 2001 From: Artyom Sinyugin Date: Wed, 15 Jan 2025 19:28:44 +0300 Subject: [PATCH] xilem: docs update for label, button, sized_box. --- xilem/README.md | 2 +- xilem/src/view/button.rs | 45 +++++++++++++++++++++++++++++++++++++ xilem/src/view/label.rs | 23 +++++++++++++++++++ xilem/src/view/sized_box.rs | 19 ++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/xilem/README.md b/xilem/README.md index d0d85a5ad..2f6129aa0 100644 --- a/xilem/README.md +++ b/xilem/README.md @@ -126,7 +126,7 @@ The primitives your [Xilem] app’s view tree will generally be constructed from ## Minimum supported Rust Version (MSRV) -This version of Xilem has been verified to compile with **Rust 1.81** and later. +This version of Xilem has been verified to compile with **Rust 1.82** and later. Future versions of Xilem might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases. diff --git a/xilem/src/view/button.rs b/xilem/src/view/button.rs index 171d1949e..b0fc717a9 100644 --- a/xilem/src/view/button.rs +++ b/xilem/src/view/button.rs @@ -12,6 +12,48 @@ use crate::{Affine, MessageResult, Pod, ViewCtx, ViewId}; use super::Transformable; /// A button which calls `callback` when the primary mouse button (normally left) is pressed. +/// +/// # Examples +/// To use button provide it with a button text and a closure. +/// ```ignore +/// use xilem::view::button; +/// +/// struct State { +/// int: i32, +/// } +/// +/// impl State { +/// fn increase(&mut self) { +/// self.int += 1; +/// } +/// } +/// +/// button("Button", |state: &mut State| { +/// state.increase(); +/// }) +/// ``` +/// +/// Create a `button` with a custom `label`. +/// +/// ```ignore +/// use xilem::view::{button, label}; +/// +/// struct State { +/// int: i32, +/// } +/// +/// impl State { +/// fn increase(&mut self) { +/// self.int += 1; +/// } +/// } +/// +/// let label = label("Button").weight(FontWeight::BOLD); +/// +/// button(label, |state: &mut State| { +/// state.increase(); +/// }) +/// ``` pub fn button( label: impl Into