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>>;
92 add(
const std::string& action, ImGuiKey button,
const std::vector<ImGuiKey>& modifiers = {});
101 const std::string& action,
103 const std::vector<ImGuiKey>& modifiers = {})
const;
112 void add(
const std::string& action,
const Keybind& keybind);
117 const MapType& get()
const;
123 bool remove(
const std::string& action);
129 bool unregister_action(
const std::string& action);
135 bool register_action(
const std::string& action);
141 bool is_pressed(
const std::string& action)
const;
146 inline bool is_pressed(ImGuiKey key_code)
const {
return ImGui::IsKeyPressed(key_code); }
151 bool is_down(
const std::string& action)
const;
156 inline bool is_down(ImGuiKey key_code)
const {
return ImGui::IsKeyDown(key_code); }
161 bool is_released(
const std::string& action)
const;
166 inline bool is_released(ImGuiKey key_code)
const {
return ImGui::IsKeyReleased(key_code); }
171 bool save(std::ostream& out)
const;
178 bool load(std::istream& in,
bool append =
false);
185 void enable(
bool enabled);
188 bool is_enabled()
const;
192 static std::string to_string(
const Keybind& keybind);
195 static std::string to_string(ImGuiKey key);
198 std::string to_string(
const std::string& action,
int limit = 1)
const;
202 bool m_enabled =
true;
203 std::vector<std::string> m_context_stack;
205 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:146
bool is_released(ImGuiKey key_code) const
Returns true if key was just released.
Definition Keybinds.h:166
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:156
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.