.. index:: pair: class; EE::UI::UICommand .. _doxid-class_e_e_1_1_u_i_1_1_u_i_command: class EE::UI::UICommand ======================= .. toctree:: :hidden: struct_EE_UI_UICommand_SourceConnection.rst struct_EE_UI_UICommand_SourceConnectionBase.rst struct_EE_UI_UICommand_State.rst Overview ~~~~~~~~ One action shared by :ref:`UI ` endpoints and keyboard shortcuts. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class UICommand { public: // structs template struct :ref:`SourceConnection`; struct :ref:`SourceConnectionBase`; struct :ref:`State`; // construction :ref:`UICommand`(std::function execute); template :ref:`UICommand`(std::function execute, Source& enabled); :target:`UICommand`(const UICommand&); :target:`UICommand`(UICommand&&); // methods UICommand& :target:`operator=`(const UICommand&); UICommand& :target:`operator=`(UICommand&&); bool :ref:`execute`(); :ref:`ObservableValue`& :ref:`enabled`(); }; .. _details-class_e_e_1_1_u_i_1_1_u_i_command: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ One action shared by :ref:`UI ` endpoints and keyboard shortcuts. .. ref-code-block:: cpp 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 ------------ .. index:: pair: function; UICommand .. _doxid-class_e_e_1_1_u_i_1_1_u_i_command_1a16f145373567ff14e3fc349e96ab564c: .. ref-code-block:: cpp :class: doxyrest-title-code-block UICommand(std::function execute) Creates an always-enabled command that invokes ``execute``. .. index:: pair: function; UICommand .. _doxid-class_e_e_1_1_u_i_1_1_u_i_command_1a84c25f9e2a4d3ba33cb422f138bf475d: .. ref-code-block:: cpp :class: doxyrest-title-code-block template UICommand(std::function 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 ------- .. index:: pair: function; execute .. _doxid-class_e_e_1_1_u_i_1_1_u_i_command_1a8d84a96c0587e1883a06604806da1c21: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool execute() Attempts to run the action. .. rubric:: Returns: true when it ran, or false when disabled or already executing. .. index:: pair: function; enabled .. _doxid-class_e_e_1_1_u_i_1_1_u_i_command_1ac706b1fd99694d46bd67501a0fcbe912: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`ObservableValue`& enabled() .. rubric:: Returns: Observable enabled state shared by every endpoint bound to this command.