Lagrange
|
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 MapType & | get () 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. | |
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
void update | ( | ) |
Updating key states.
Updates keybinds state based on key states
void push_context | ( | const std::string & | context | ) |
Changes current context.
context | context name |
void pop_context | ( | ) |
Pops the last pushed context.
context | context name |
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
action | string identifier |
button | which button |
modifiers | modifier buttons |
bool has | ( | const std::string & | action, |
ImGuiKey | button, | ||
const std::vector< ImGuiKey > & | modifiers = {} |
||
) | const |
Checks if an exact keybinding exists for given action.
action | string identifier |
button | which button |
modifiers | modifier buttons |
void add | ( | const std::string & | action, |
const Keybind & | keybind | ||
) |
Adds a key binding for given action.
Registers action if it doesn't exist
action | string identifier |
keybind |
const Keybinds::MapType & get | ( | ) | const |
All keybinds for all actions.
bool remove | ( | const std::string & | action | ) |
Removes all key bindings for given action.
action |
bool unregister_action | ( | const std::string & | action | ) |
Unregisters action and removes all its key binds.
action |
bool register_action | ( | const std::string & | action | ) |
Register an action with no keybinds.
action | string identifier |
bool is_pressed | ( | const std::string & | action | ) | const |
Returns true if action was just pressed.
action | string identifier |
|
inline |
Returns true if key was just pressed.
key_code | ImGui key code |
bool is_down | ( | const std::string & | action | ) | const |
Returns true if action is held down.
action | string identifier |
|
inline |
Returns true if key is held down.
key_code | ImGui key code |
bool is_released | ( | const std::string & | action | ) | const |
Returns true if action was just released.
action | string identifier |
|
inline |
Returns true if key was just released.
key_code | ImGui key code |
bool save | ( | std::ostream & | out | ) | const |
Saves to output stream using JSON.
out | any std output stream |
bool load | ( | std::istream & | in, |
bool | append = false |
||
) |
Loads JSON from input stream.
in | any std input stream |
append | if true, will append keybinds from file to current keybinds |
void enable | ( | bool | enabled | ) |
Toggles processing of keybinds.
Use when creating new keybinds
enabled |