14#include <lagrange/ui/api.h>
15#include <lagrange/ui/types/GLContext.h>
35class LA_UI_API Keybinds
38 enum class KeyState { NONE, PRESSED, DOWN, RELEASED };
47 struct LA_UI_API Keybind
49 Keybind(ImGuiKey btn,
const std::vector<ImGuiKey>& modifier_keys = {});
50 ImGuiKey button = ImGuiKey_None;
51 int modifier_count = 0;
52 KeyState previous_state = KeyState::NONE;
53 KeyState current_state = KeyState::NONE;
54 std::array<ImGuiKey, 6> modifiers = {
66 using MapType = std::map<std::string, std::vector<Keybind>>;
93 add(
const std::string& action, ImGuiKey button,
const std::vector<ImGuiKey>& modifiers = {});
102 const std::string& action,
104 const std::vector<ImGuiKey>& modifiers = {})
const;
113 void add(
const std::string& action,
const Keybind& keybind);
118 const MapType& get()
const;
124 bool remove(
const std::string& action);
130 bool unregister_action(
const std::string& action);
136 bool register_action(
const std::string& action);
142 bool is_pressed(
const std::string& action)
const;
147 inline bool is_pressed(ImGuiKey key_code)
const {
return ImGui::IsKeyPressed(key_code); }
152 bool is_down(
const std::string& action)
const;
157 inline bool is_down(ImGuiKey key_code)
const {
return ImGui::IsKeyDown(key_code); }
162 bool is_released(
const std::string& action)
const;
167 inline bool is_released(ImGuiKey key_code)
const {
return ImGui::IsKeyReleased(key_code); }
172 bool save(std::ostream& out)
const;
179 bool load(std::istream& in,
bool append =
false);
186 void enable(
bool enabled);
189 bool is_enabled()
const;
193 static std::string to_string(
const Keybind& keybind);
196 static std::string to_string(ImGuiKey key);
199 std::string to_string(
const std::string& action,
int limit = 1)
const;
203 bool m_enabled =
true;
204 std::vector<std::string> m_context_stack;
206 bool is_action_in_state(
const std::string& action, KeyState state)
const;
std::map< std::string, std::vector< Keybind > > MapType
Internal map type.
Definition Keybinds.h:66
void add(const std::string &action, ImGuiKey button, const std::vector< ImGuiKey > &modifiers={})
Adds a key binding for given action.
Definition Keybinds.cpp:143
bool is_pressed(ImGuiKey key_code) const
Returns true if key was just pressed.
Definition Keybinds.h:147
bool is_released(ImGuiKey key_code) const
Returns true if key was just released.
Definition Keybinds.h:167
void update()
Updating key states.
Definition Keybinds.cpp:25
void pop_context()
Pops the last pushed context.
Definition Keybinds.cpp:133
bool is_down(ImGuiKey key_code) const
Returns true if key is held down.
Definition Keybinds.h:157
void push_context(const std::string &context)
Changes current context.
Definition Keybinds.cpp:128
Lagrange UI Viewer and mini 3D engine.
Definition AcceleratedPicking.h:23
Main namespace for Lagrange.