From b966367bc3b7dd9e136e4740a77ac6cea1b9927c Mon Sep 17 00:00:00 2001 From: "Ralph J. Steinhagen" Date: Thu, 27 Jul 2023 13:39:53 +0200 Subject: [PATCH] refactored InputKeypad for mobile<->desktop compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * improved compatibility for mobile devices and desktop * adjusted and re-use for larger font using existing App definitions * re-layout largely following common numeric keyboard layout (ISO/IEC 9995-1) * added support for scientific notation * added support for portrait- and landscape keypad-layout * added support for directly editing display field (i.e. if used on a desktop, N.B. yes, the InputKeypad is equally usable also with a keyboard, added missing mouse-button<->key mappings) * derive button labels directly from enum (via toString(..)) function that should fail if new/unmapped enum values are added. possible improvement: use compile-time-reflection) * broke-up functions into popup-handling, drawing keypad (x2), and handling key/input logic * added dual-function Backspace button: double-clicking clears the whole field * added function that entering the first number clears the previous field value (N.B. field is still only committed if it parses correctly) * added alt '2nd' and inverse function 'Inv' overloading of some buttons to switch e.g. between 'sinh'<->'asinh', 'sin'<->'asin', 'x^2' <-> 'x^3', 'Log'<->'Ln', ... * N.B. not all functions are (yet) enabled in the backing calculator implementation (-> future improvement/PR) as this PR focuses primarily on the UL layout * general improvements/changes: * refactored & renamed according to coding-style guidelines: https://github.com/fair-acc/opencmw-cpp/blob/main/README.developers.md * added type-safe structures where possible/applicable * added merging of fonts to the font loader to allow transplanting characters -- usually extended ascii-ranges -- fonts to receiving fonts that do not have definitions for these (e.g. frames, x², ... to xkcd). Could be further generalised (thinking of combining normal ascii Characters with FontAwesome font) Signed-off-by: Ralph J. Steinhagen --- src/ui/imguiutils.cpp | 1086 +++++++++++++++++++++++++++++------------ src/ui/main.cpp | 61 ++- 2 files changed, 822 insertions(+), 325 deletions(-) diff --git a/src/ui/imguiutils.cpp b/src/ui/imguiutils.cpp index 832c2fdf..21206856 100644 --- a/src/ui/imguiutils.cpp +++ b/src/ui/imguiutils.cpp @@ -1,43 +1,52 @@ -#include "imguiutils.h" -#include "app.h" -#include "flowgraph.h" - +#include +#include +#include #include +#include +#include +#include +#include +#include "app.h" #include "calculator.h" +#include "flowgraph.h" #include "flowgraph/datasink.h" -#include -#include -#include +#include "imguiutils.h" namespace ImGuiUtils { + +template class InputKeypad { static inline constexpr const char *keypad_name = "KeypadX"; - static inline constexpr size_t buffer_size = 64; - bool visible = true; - size_t parenthesi = 0; - std::string edit_buffer; - std::any prev_value; + // + bool _visible = true; + bool _altMode = false; + bool _invMode = false; + bool _firstUpdate = true; + size_t _parentheses = 0; + std::string _editBuffer; + std::any _prevValue; + Token _lastToken; - Token last_token; - -private: enum class ReturnState { None, Change, Accept, - Discard = -1 + Discard }; enum class Button { NoButton, - Dot, + Period, + E_scientific, Sign, AC, Backspace, Enter, Escape, + Alt_2nd, + Alt_Inv, POpen = '(', PClose = ')', @@ -59,29 +68,143 @@ class InputKeypad { Percent, Rcp, + Sqr, Sqrt, + Cube, + CubeRoot, Sin, Cos, Tan, + ASin, + ACos, + ATan, Sinh, Cosh, Tanh, + ASinh, + ACosh, + ATanh, Pow = '^', + Log, + Ln, + Pow10, + PowE + // , NewEnumValue // for testing the static_assert in the toString member }; - template