Skip to content

ui::CommandHandler

Header: winui/ui/Command.hpp.

What the command does, given the invoking control's CommandParameter. Takes a callable of either void() or void(std::string_view parameter), so a handler with no use for the parameter may leave it out of its signature. Move-only, like ui::Callback.

Example:

// Reads the invoking control's `.command_parameter`:
ui::Command remove{
    .text    = "Remove",
    .icon    = ui::Symbol::Remove,
    .execute = [&](std::string_view item) { remove_item(item); },
};
// Has no use for it, so leaves it out:
ui::Command refresh{
    .text    = "Refresh",
    .icon    = ui::Symbol::Refresh,
    .execute = [&] { reload_list(); },
};

window.set_content(ui::CommandBar{
    .primary = {
        ui::AppBarButton{.command = remove, .command_parameter = "List item 3"}, // remove_item("List item 3")
        ui::AppBarButton{.command = refresh},
    },
});

CommandHandler

CommandHandler() = default

An empty handler: calling it does nothing and it converts to false.

CommandHandler

template <typename F>
CommandHandler(F handler)
    requires std::invocable<F&> || std::invocable<F&, std::string_view>

Wraps handler, a callable of void() or void(std::string_view); a mutable lambda may keep state between runs.

operator()

void operator()(std::string_view parameter = {}) const

Runs the handler with parameter; a no-op when empty.

operator bool

operator bool() const

True when a handler was given.