Skip to main content

Module wizard

Module wizard 

Source
Expand description

Wizard widget and related types.

By default the Wizard! widget presents the traditional multi-step dialog/form experience, but it is highly customizable. The widget is composed of four panels: header, footer, side and content, each panel can be customized using contextual properties.

The Page type defines widget builders for the content of each panel when the page is open. It also defines variables that control how navigation works to and from the page.

use zng::focus::{TabIndex, tab_index};
use zng::prelude::*;
use zng::wizard::{self, Wizard};

let wizard_id = WidgetId::new_unique();

// basic page with defaults depending on page index
let basic_page = wizard::Page::new(
    "Header",
    "Description of what this pages is asking or doing",
    wgt_fn!(|_| {
        Text! {
            txt = "Custom page content.";
        }
    }),
);

// more customized page, with wizard commands control
let can_cancel = var(true);
let can_finish = var(true);
let mut page = wizard::Page::new(
    "Commands",
    "What wizard commands are enabled?",
    wgt_fn!(can_cancel, can_finish, |args: wizard::PageArgs| {
        Stack! {
            // on enter page
            widget::on_init = hn!(can_cancel, |_| {
                can_cancel.set(false);
            });
            // on exit page
            widget::on_deinit = hn!(can_cancel, |_| {
                can_cancel.set(true);
            });
            direction = StackDirection::top_to_bottom();
            spacing = 5;
            toggle::style_fn = style_fn!(|_| toggle::CheckStyle!());
            children = ui_vec![
                Text!("Select what wizard commands are enabled:"),
                Toggle! {
                    checked = can_cancel.clone();
                    child = Text!("CANCEL_CMD");
                },
                Toggle! {
                    checked = can_finish.clone();
                    child = Text!("FINISH_CMD");
                },
                Text!("Also wizard navigation commands:"),
                Toggle! {
                    checked = args.can_back;
                    child = Text!("BACK_CMD");
                },
            ];
        }
    }),
);
// by default the last page only has BACK and FINISH buttons
page.footer = wgt_fn!(|_| {
    ui_vec![
        Button! {
            cmd = wizard::BACK_CMD.scoped(wizard_id);
            tab_index = TabIndex::FIRST - 1;
        },
        Button! {
            cmd = wizard::FINISH_CMD.scoped(wizard_id);
            tab_index = TabIndex::FIRST;
            style_fn = style_fn!(|_| zng::button::PrimaryStyle!());
        },
        Button! {
            cmd = wizard::CANCEL_CMD.scoped(wizard_id);
            tab_index = TabIndex::FIRST - 2;
        },
    ]
    .into_node()
});

Wizard! {
    id = wizard_id;
    // side_background_fn = wgt_fn!(|_| flood(colors::RED));
    // header_background_fn = wgt_fn!(|_| flood(colors::BLUE));
    pages = vec![basic_page, page];
    can_cancel;
    on_cancel = hn!(|a| {
        println!("Cancel!");
        WINDOW.close();
    });
    finish_cmd_name = "Apply";
    can_finish;
    on_finish = hn!(|a| {
        println!("Finish!");
        WINDOW.close();
    });
}

Structs§

ContentFnArgs
Arguments for a wizard main content container builder.
FooterFnArgs
Arguments for a wizard footer container builder.
HeaderFnArgs
Arguments for a wizard header container builder.
Page
Represents a page builder for Wizard!.
PageArgs
Arguments for Page builders.
PanelFnArgs
Arguments for the wizard root panel builder.
SideFnArgs
Arguments for a wizard side container builder.
Wizard
W Paginated widget that

Statics§

BACK_CMD
Return to previous page.
CANCEL_CMD
Cancel wizard operation.
FINISH_CMD
Finish wizard operation.
NEXT_CMD
Advance to next page.

Functions§

content_fn
P Widget function that converts a ContentFnArgs into a page main content container container widget.
footer_extra_fn
P Widget function that converts PageArgs to extra footer content.
footer_fn
P Widget function that converts a FooterFnArgs into a page side container widget.
header_background_fn
P Widget function that makes a background visual for the page header container widget.
header_fn
P Widget function that converts a HeaderFnArgs into a page header container widget.
panel_fn
P Widget function that converts a PanelFnArgs into a wizard.
side_background_fn
P Widget function that makes a background visual for the page side container widget.
side_extra_fn
P Widget function that converts PageArgs to extra side panel content.
side_fn
P Widget function that converts a SideFnArgs into a page side container widget.