From 72e80227f4ad7cae10dbe067597330896011dfb4 Mon Sep 17 00:00:00 2001 From: jrmoulton Date: Fri, 1 Nov 2024 12:01:43 -0600 Subject: [PATCH] update checkbox --- examples/widget-gallery/src/checkbox.rs | 2 +- src/views/checkbox.rs | 33 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/examples/widget-gallery/src/checkbox.rs b/examples/widget-gallery/src/checkbox.rs index 91595486..8193f993 100644 --- a/examples/widget-gallery/src/checkbox.rs +++ b/examples/widget-gallery/src/checkbox.rs @@ -20,7 +20,7 @@ pub fn checkbox_view() -> impl IntoView { .disabled(|| true) }), form_item("Labelled Checkbox:".to_string(), width, move || { - Checkbox::new_labeled_rw(is_checked, || "Check me!") + Checkbox::labeled_rw(is_checked, || "Check me!") }), form_item( "Disabled Labelled Checkbox:".to_string(), diff --git a/src/views/checkbox.rs b/src/views/checkbox.rs index 69927195..2a5b4b65 100644 --- a/src/views/checkbox.rs +++ b/src/views/checkbox.rs @@ -1,3 +1,6 @@ +#![deny(missing_docs)] +//! A checkbox view for boolean selection. + use crate::{ style_class, view::IntoView, @@ -9,9 +12,15 @@ use crate::{ use floem_reactive::{SignalGet, SignalUpdate}; use std::fmt::Display; -style_class!(pub CheckboxClass); +style_class!( + /// The style class that is applied to the checkbox. + pub CheckboxClass +); -style_class!(pub LabeledCheckboxClass); +style_class!( + /// The style class that is applied to the labeled checkbox stack. + pub LabeledCheckboxClass +); fn checkbox_svg(checked: impl SignalGet + 'static) -> impl IntoView { const CHECKBOX_SVG: &str = r#""#; @@ -22,11 +31,13 @@ fn checkbox_svg(checked: impl SignalGet + 'static) -> impl IntoView { .keyboard_navigable() } -/// The `Checkbox` struct provides various methods to create and manage checkboxes. +/// # A customizable checkbox view for boolean selection. +/// +/// The `Checkbox` struct provides several constructors, each offering different levels of +/// customization and ease of use. The simplest is the [Checkbox::new_rw] constructor, which gets direct access to a signal and will update it when the checkbox is clicked. /// -/// # Related Functions -/// - [`checkbox`] -/// - [`labeled_checkbox`] +/// Choose the constructor that best fits your needs based on whether you require labeling +/// and how you prefer to manage the checkbox's state (via closure or direct signal manipulation). pub struct Checkbox; impl Checkbox { @@ -65,7 +76,7 @@ impl Checkbox { /// /// This method is useful when you want a labeled checkbox whose state is determined by a closure. /// The label is also provided by a closure, allowing for dynamic updates. - pub fn new_labeled( + pub fn labeled( checked: impl Fn() -> bool + 'static, label: impl Fn() -> S + 'static, ) -> ValueContainer { @@ -90,7 +101,7 @@ impl Checkbox { /// /// This method is ideal when you need a labeled checkbox that not only reflects a signal's state but also updates it. /// Clicking the checkbox will toggle its state and update the signal accordingly. - pub fn new_labeled_rw( + pub fn labeled_rw( checked: impl SignalGet + SignalUpdate + Copy + 'static, label: impl Fn() -> S + 'static, ) -> impl IntoView { @@ -103,15 +114,15 @@ impl Checkbox { } } -/// Renders a checkbox the provided checked signal. +/// Renders a checkbox the provided checked signal. See also [`Checkbox::new`] and [`Checkbox::new_rw`]. pub fn checkbox(checked: impl Fn() -> bool + 'static) -> ValueContainer { Checkbox::new(checked) } -/// Renders a checkbox using the provided checked signal. +/// Renders a checkbox using the provided checked signal. See also [`Checkbox::labeled`] and [`Checkbox::labeled_rw`]. pub fn labeled_checkbox( checked: impl Fn() -> bool + 'static, label: impl Fn() -> S + 'static, ) -> ValueContainer { - Checkbox::new_labeled(checked, label) + Checkbox::labeled(checked, label) }