MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / triggerToDict

Function triggerToDict

src/python/lfs/py_keymap.cpp:24–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23 namespace {
24 nb::dict triggerToDict(const InputTrigger& trigger) {
25 nb::dict result;
26 std::visit(
27 [&result](const auto& t) {
28 using T = std::decay_t<decltype(t)>;
29 if constexpr (std::is_same_v<T, KeyTrigger>) {
30 result["type"] = "key";
31 result["key"] = t.key;
32 result["modifiers"] = t.modifiers;
33 } else if constexpr (std::is_same_v<T, MouseButtonTrigger>) {
34 result["type"] = "mouse_button";
35 result["button"] = static_cast<int>(t.button);
36 result["modifiers"] = t.modifiers;
37 result["double_click"] = t.double_click;
38 } else if constexpr (std::is_same_v<T, MouseScrollTrigger>) {
39 result["type"] = "scroll";
40 result["modifiers"] = t.modifiers;
41 if (t.chord_key.has_value()) {
42 result["chord_key"] = *t.chord_key;
43 }
44 } else if constexpr (std::is_same_v<T, MouseDragTrigger>) {
45 result["type"] = "drag";
46 result["button"] = static_cast<int>(t.button);
47 result["modifiers"] = t.modifiers;
48 if (t.chord_key.has_value()) {
49 result["chord_key"] = *t.chord_key;
50 }
51 }
52 },
53 trigger);
54 return result;
55 }
56
57 std::optional<InputTrigger> triggerFromDict(const nb::dict& d) {
58 if (!d.contains("type")) {

Callers 1

register_keymapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected