class EE::UI::UICommand¶
Overview¶
One action shared by UI endpoints and keyboard shortcuts. More…
#include <uicommand.hpp> class UICommand { public: // structs template <typename Connection> struct SourceConnection; struct SourceConnectionBase; struct State; // construction UICommand(std::function<void()> execute); template <typename Source> UICommand(std::function<void()> execute, Source& enabled); UICommand(const UICommand&); UICommand(UICommand&&); // methods UICommand& operator=(const UICommand&); UICommand& operator=(UICommand&&); bool execute(); ObservableValue<bool>& enabled(); };
Detailed Documentation¶
One action shared by UI endpoints and keyboard shortcuts.
auto save = bindCommand( [&] { saveDocument(); }, canSave, *saveButton, *uiScene, { KEY_S, KeyMod::getDefaultModifier() } );
For a single button with no other representation, an ordinary onClick() callback remains the clearer choice.
Construction¶
UICommand(std::function<void()> execute)
Creates an always-enabled command that invokes execute.
template <typename Source> UICommand(std::function<void()> execute, Source& enabled)
Creates a command whose enabled state follows enabled.
The source must expose get() and observe() for bool values and must outlive the command if further enabled-state updates are expected.
Methods¶
bool execute()
Attempts to run the action.
Returns:
true when it ran, or false when disabled or already executing.
ObservableValue<bool>& enabled()
Returns:
Observable enabled state shared by every endpoint bound to this command.