mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 09:17:23 +01:00
[code] Keyboard events translation, for script or command edition.
For instance, the "power" event should insert "**" in the text, not "^". Added a universal i18n file in apps/code. Change-Id: I5d067b0c5b86590af95aa98856522d54e42acba6
This commit is contained in:
46
apps/code/helpers.cpp
Normal file
46
apps/code/helpers.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "helpers.h"
|
||||
|
||||
namespace Code {
|
||||
namespace Helpers {
|
||||
|
||||
class EventTextPair {
|
||||
public:
|
||||
constexpr EventTextPair(Ion::Events::Event event, const char * text) : m_event(event), m_text(text) {}
|
||||
Ion::Events::Event event() const { return m_event; }
|
||||
const char * text() const { return m_text; }
|
||||
private:
|
||||
const Ion::Events::Event m_event;
|
||||
const char * m_text;
|
||||
};
|
||||
|
||||
static constexpr EventTextPair sEventTextMap[] = {
|
||||
EventTextPair(Ion::Events::XNT, "x"),
|
||||
EventTextPair(Ion::Events::Exp, "exp()"),
|
||||
EventTextPair(Ion::Events::Ln, "log()"),
|
||||
EventTextPair(Ion::Events::Log, "log10()"),
|
||||
EventTextPair(Ion::Events::Sine, "sin()"),
|
||||
EventTextPair(Ion::Events::Cosine, "cos()"),
|
||||
EventTextPair(Ion::Events::Tangent, "tan()"),
|
||||
EventTextPair(Ion::Events::Imaginary, "1j"),
|
||||
EventTextPair(Ion::Events::Power, "**"),
|
||||
EventTextPair(Ion::Events::Pi, "pi"),
|
||||
EventTextPair(Ion::Events::Sqrt, "sqrt()"),
|
||||
EventTextPair(Ion::Events::Square, "**2"),
|
||||
EventTextPair(Ion::Events::Multiplication, "*"),
|
||||
EventTextPair(Ion::Events::EE, "e"),
|
||||
EventTextPair(Ion::Events::Arcsine, "asin()"),
|
||||
EventTextPair(Ion::Events::Arccosine, "acos()"),
|
||||
EventTextPair(Ion::Events::Arctangent, "atan()")
|
||||
};
|
||||
|
||||
const char * PythonTextForEvent(Ion::Events::Event event) {
|
||||
for (int i=0; i<sizeof(sEventTextMap)/sizeof(sEventTextMap[0]); i++) {
|
||||
if (event == sEventTextMap[i].event()) {
|
||||
return sEventTextMap[i].text();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user