2017-11-23 13:54:27 +01:00
|
|
|
#pragma once
|
|
|
|
#include "ui-input.hh"
|
|
|
|
|
|
|
|
|
|
|
|
/*= COMMON ACTION DEFINITIONS ================================================*/
|
|
|
|
|
|
|
|
struct T_KeyboardShortcut
|
|
|
|
{
|
|
|
|
char character;
|
2017-11-24 11:48:08 +01:00
|
|
|
T_KbdMods modifiers;
|
2017-11-23 13:54:27 +01:00
|
|
|
|
|
|
|
explicit constexpr T_KeyboardShortcut(
|
|
|
|
char character ,
|
2017-11-24 11:48:08 +01:00
|
|
|
T_KbdMods modifiers = { } ) noexcept
|
2017-11-23 13:54:27 +01:00
|
|
|
: character{ character } , modifiers{ modifiers }
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Writes the keyboard shortcut to a buffer
|
|
|
|
void toString( char* buffer , size_t size ) const noexcept;
|
2017-11-24 11:34:17 +01:00
|
|
|
|
|
|
|
// Equality operators
|
|
|
|
bool operator ==( T_KeyboardShortcut const& other ) const noexcept
|
|
|
|
{ return other.character == character && other.modifiers == modifiers; }
|
|
|
|
bool operator !=( T_KeyboardShortcut const& other ) const noexcept
|
|
|
|
{ return other.character != character || other.modifiers != modifiers; }
|
2017-11-23 13:54:27 +01:00
|
|
|
};
|
2017-11-24 11:34:17 +01:00
|
|
|
namespace ebcl { M_DECLARE_HASH( T_KeyboardShortcut ); }
|
2017-11-23 13:54:27 +01:00
|
|
|
|
|
|
|
struct T_UIAction
|
|
|
|
{
|
|
|
|
// Function to call when the action is executed
|
|
|
|
using F_ActionHandler = std::function< void( void ) >;
|
|
|
|
// Function that checks whether the action is enabled
|
|
|
|
using F_ActionChecker = std::function< bool( void ) >;
|
|
|
|
|
|
|
|
T_String id;
|
|
|
|
T_String text; // Text, if different from the identifier
|
|
|
|
char const* icon{ nullptr };
|
|
|
|
T_Optional< T_KeyboardShortcut > shortcut;
|
|
|
|
F_ActionHandler handler;
|
|
|
|
F_ActionChecker enabled;
|
|
|
|
|
|
|
|
T_UIAction( char const* id ,
|
|
|
|
F_ActionHandler handler ) noexcept
|
|
|
|
: id( T_String::Pooled( id ) ) ,
|
|
|
|
handler( std::move( handler ) )
|
|
|
|
{ assert( this->handler ); }
|
|
|
|
T_UIAction( T_String const& id ,
|
|
|
|
F_ActionHandler handler ) noexcept
|
|
|
|
: id( id ) , handler( std::move( handler ) )
|
|
|
|
{ assert( this->handler ); }
|
|
|
|
|
|
|
|
T_UIAction& setShortcut( const T_KeyboardShortcut sc ) noexcept
|
|
|
|
{ shortcut = sc; return *this; }
|
|
|
|
T_UIAction& setText( T_String const& t ) noexcept
|
|
|
|
{ text = t; return *this; }
|
|
|
|
T_UIAction& setIcon( char const* const i ) noexcept
|
|
|
|
{ icon = i; return *this; }
|
|
|
|
T_UIAction& setEnabledCheck( F_ActionChecker check ) noexcept
|
|
|
|
{ enabled = std::move( check ); return *this; }
|
|
|
|
|
|
|
|
void menuItem( ) const noexcept;
|
|
|
|
void tbButton( ) const noexcept;
|
|
|
|
};
|