Lagrange
Keybinds Class Reference

Stores keybinds for actions. More...

#include <lagrange/ui/types/Keybinds.h>

Classes

struct  Keybind
 Key/mouse shortcut. More...
 

Public Types

enum class  KeyState { NONE , PRESSED , DOWN , RELEASED }
 
using MapType = std::map< std::string, std::vector< Keybind > >
 Internal map type.
 

Public Member Functions

void update ()
 Updating key states. More...
 
void push_context (const std::string &context)
 Changes current context. More...
 
void pop_context ()
 Pops the last pushed context. More...
 
void reset_context ()
 
void add (const std::string &action, ImGuiKey button, const std::vector< ImGuiKey > &modifiers={})
 Adds a key binding for given action. More...
 
bool has (const std::string &action, ImGuiKey button, const std::vector< ImGuiKey > &modifiers={}) const
 Checks if an exact keybinding exists for given action. More...
 
void add (const std::string &action, const Keybind &keybind)
 Adds a key binding for given action. More...
 
const MapTypeget () const
 All keybinds for all actions. More...
 
bool remove (const std::string &action)
 Removes all key bindings for given action. More...
 
bool unregister_action (const std::string &action)
 Unregisters action and removes all its key binds. More...
 
bool register_action (const std::string &action)
 Register an action with no keybinds. More...
 
bool is_pressed (const std::string &action) const
 Returns true if action was just pressed. More...
 
bool is_pressed (ImGuiKey key_code) const
 Returns true if key was just pressed. More...
 
bool is_down (const std::string &action) const
 Returns true if action is held down. More...
 
bool is_down (ImGuiKey key_code) const
 Returns true if key is held down. More...
 
bool is_released (const std::string &action) const
 Returns true if action was just released. More...
 
bool is_released (ImGuiKey key_code) const
 Returns true if key was just released. More...
 
bool save (std::ostream &out) const
 Saves to output stream using JSON. More...
 
bool load (std::istream &in, bool append=false)
 Loads JSON from input stream. More...
 
void enable (bool enabled)
 Toggles processing of keybinds. More...
 
bool is_enabled () const
 Is keybind processing enabled.
 
std::string to_string (const std::string &action, int limit=1) const
 Creates a string with keybinds for given action, up to a limit.
 

Static Public Member Functions

static std::string to_string (const Keybind &keybind)
 Converts keybind to string.
 
static std::string to_string (ImGuiKey key)
 Converts ImGui key to string.
 

Detailed Description

Stores keybinds for actions.

Actions are identified using strings Use syntax "context.optional_category.action", e.g. "viewport.camera.pan" Use "global" context for keybinds to be available everywhere

Member Function Documentation

◆ update()

void update ( )

Updating key states.

Updates keybinds state based on key states

◆ push_context()

void push_context ( const std::string &  context)

Changes current context.

Parameters
contextcontext name

◆ pop_context()

void pop_context ( )

Pops the last pushed context.

Parameters
contextcontext name

◆ add() [1/2]

void add ( const std::string &  action,
ImGuiKey  button,
const std::vector< ImGuiKey > &  modifiers = {} 
)

Adds a key binding for given action.

Registers action if it doesn't exist

Parameters
actionstring identifier
buttonwhich button
modifiersmodifier buttons

◆ has()

bool has ( const std::string &  action,
ImGuiKey  button,
const std::vector< ImGuiKey > &  modifiers = {} 
) const

Checks if an exact keybinding exists for given action.

Parameters
actionstring identifier
buttonwhich button
modifiersmodifier buttons

◆ add() [2/2]

void add ( const std::string &  action,
const Keybind keybind 
)

Adds a key binding for given action.

Registers action if it doesn't exist

Parameters
actionstring identifier
keybind

◆ get()

const Keybinds::MapType & get ( ) const

All keybinds for all actions.

Returns
const MapType reference

◆ remove()

bool remove ( const std::string &  action)

Removes all key bindings for given action.

Parameters
action
Returns
true if any keybinds were removed

◆ unregister_action()

bool unregister_action ( const std::string &  action)

Unregisters action and removes all its key binds.

Parameters
action
Returns
true if action existed

◆ register_action()

bool register_action ( const std::string &  action)

Register an action with no keybinds.

Parameters
actionstring identifier
Returns
true if action did not exist before

◆ is_pressed() [1/2]

bool is_pressed ( const std::string &  action) const

Returns true if action was just pressed.

Parameters
actionstring identifier
Returns
true if pressed

◆ is_pressed() [2/2]

bool is_pressed ( ImGuiKey  key_code) const
inline

Returns true if key was just pressed.

Parameters
key_codeImGui key code
Returns
true if pressed

◆ is_down() [1/2]

bool is_down ( const std::string &  action) const

Returns true if action is held down.

Parameters
actionstring identifier
Returns
true if down or pressed

◆ is_down() [2/2]

bool is_down ( ImGuiKey  key_code) const
inline

Returns true if key is held down.

Parameters
key_codeImGui key code
Returns
true if down or pressed

◆ is_released() [1/2]

bool is_released ( const std::string &  action) const

Returns true if action was just released.

Parameters
actionstring identifier
Returns
true if pressed

◆ is_released() [2/2]

bool is_released ( ImGuiKey  key_code) const
inline

Returns true if key was just released.

Parameters
key_codeImGui key code
Returns
true if pressed

◆ save()

bool save ( std::ostream &  out) const

Saves to output stream using JSON.

Parameters
outany std output stream
Returns
successfully saved

◆ load()

bool load ( std::istream &  in,
bool  append = false 
)

Loads JSON from input stream.

Parameters
inany std input stream
appendif true, will append keybinds from file to current keybinds
Returns
succesfully loaded

◆ enable()

void enable ( bool  enabled)

Toggles processing of keybinds.

Use when creating new keybinds

Parameters
enabled

The documentation for this class was generated from the following files: