diff --git a/src/binding.rs b/src/binding.rs index acfc7a16..393c1e73 100644 --- a/src/binding.rs +++ b/src/binding.rs @@ -91,6 +91,37 @@ where } } +/// Generates a lens to a struct field +/// +/// Parameters: +/// - `lens_name` - name of the resulting lens struct +/// - `from` - type for which the lens is implemented +/// - `to` - type of the field +/// - `field` - name of the field +/// +/// Usage: +/// ```no_run +/// use rui::*; +/// +/// #[derive(Default)] +/// struct MyState { +/// value: f32, +/// } +/// +/// make_lens!(ValueLens, MyState, f32, value); +/// +/// fn my_view() -> impl View { +/// state(MyState::default, |state, cx| { +/// vstack(( +/// cx[state].value.font_size(10).padding(Auto), +/// hslider(bind(state, ValueLens {})) +/// .thumb_color(RED_HIGHLIGHT) +/// .padding(Auto), +/// )) +/// }) +/// } +/// ``` + #[macro_export] macro_rules! make_lens { ($lens_name: ident, $from: ty, $to: ty, $field: ident) => { diff --git a/src/views/anyview.rs b/src/views/anyview.rs index 58f3d8d8..ee3b4993 100644 --- a/src/views/anyview.rs +++ b/src/views/anyview.rs @@ -73,7 +73,24 @@ impl View for AnyView { } } -/// Switches between views according to a boolean. +/// Erases the underlying view type, allowing +/// the function to return multiple different view types +/// +/// Usage: +/// ```no_run +/// use rui::*; +/// +/// fn main() { +/// rui(list(vec![7, 42], |i| { +/// if *i == 7 { +/// any_view(circle()) +/// } else { +/// any_view(rectangle()) +/// } +/// .padding(Auto) +/// })); +/// } +/// ``` pub fn any_view(view: impl View) -> AnyView { AnyView { child: Box::new(view), diff --git a/src/views/canvas.rs b/src/views/canvas.rs index 95d38e74..d3c5e284 100644 --- a/src/views/canvas.rs +++ b/src/views/canvas.rs @@ -49,7 +49,7 @@ where } } -/// Canvas for GPU drawing with Vger. See https://github.com/audulus/vger-rs. +/// Canvas for GPU drawing with Vger. See . pub fn canvas(f: F) -> impl View { Canvas { func: f } } diff --git a/src/views/map.rs b/src/views/map.rs index c8417e72..02e8517d 100644 --- a/src/views/map.rs +++ b/src/views/map.rs @@ -90,10 +90,14 @@ where impl private::Sealed for MapView {} -/// Maps state into local state. -/// -/// For example: +/// Creates local derived state with a setter. /// +/// Arguments: +/// - `value` - local state value +/// - `set_value` - a function that will run each time the local state changes +/// - `func` - view function using the local state +/// +/// Usage: /// ```no_run /// # use rui::*; ///