Skip to content

Commit

Permalink
add viewswitcher example (#1822)
Browse files Browse the repository at this point in the history
  • Loading branch information
arifd authored Jun 19, 2021
1 parent f19ddf1 commit dfd105e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions druid/src/widget/view_switcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ impl<T: Data, U: Data> ViewSwitcher<T, U> {
///
/// The `child_builder` closure creates a new child widget based on
/// the value passed to it.
///
/// # Examples
/// ```
/// use druid::{
/// widget::{Label, ViewSwitcher},
/// Data, Widget,
/// };
///
/// #[derive(Clone, PartialEq, Data)]
/// enum Foo {
/// A,
/// B,
/// C,
/// }
///
/// fn ui() -> impl Widget<Foo> {
/// ViewSwitcher::new(
/// |data: &Foo, _env| data.clone(),
/// |selector, _data, _env| match selector {
/// Foo::A => Box::new(Label::new("A")),
/// _ => Box::new(Label::new("Not A")),
/// },
/// )
/// }
/// ```
pub fn new(
child_picker: impl Fn(&T, &Env) -> U + 'static,
child_builder: impl Fn(&U, &T, &Env) -> Box<dyn Widget<T>> + 'static,
Expand Down

0 comments on commit dfd105e

Please sign in to comment.