Browse Source

text input binding is more dynamic

Kajetan Johannes Hammerle 3 years ago
parent
commit
18c11759be
3 changed files with 12 additions and 7 deletions
  1. 1 1
      input/TextInput.h
  2. 9 4
      rendering/Window.cpp
  3. 2 2
      rendering/Window.h

+ 1 - 1
input/TextInput.h

@@ -17,7 +17,7 @@ public:
     void onCharEvent(unsigned int codepoint);
 
     template<int N>
-    void getInput(StringBuffer<N>& s) const {
+    void toString(StringBuffer<N>& s) const {
         for(unsigned int c : input) {
             s.appendUnicode(c);
         }

+ 9 - 4
rendering/Window.cpp

@@ -2,7 +2,7 @@
 
 #include "rendering/Window.h"
 
-Window::Window(TextInput& textInput, const WindowOptions& options)
+Window::Window(TextInput*& textInput, const WindowOptions& options)
     : textInput(textInput), window(nullptr) {
     glfwDefaultWindowHints();
     glfwWindowHint(GLFW_VISIBLE, 0);
@@ -89,13 +89,18 @@ void Window::keyCallback(GLFWwindow* w, int key, int scancode, int action,
                          int mods) {
     void* p = glfwGetWindowUserPointer(w);
     if(p != nullptr) {
-        static_cast<Window*>(p)->textInput.onKeyEvent(key, scancode, action,
-                                                      mods);
+        TextInput* input = static_cast<Window*>(p)->textInput;
+        if(input != nullptr) {
+            input->onKeyEvent(key, scancode, action, mods);
+        }
     }
 }
 void Window::charCallback(GLFWwindow* w, unsigned int codepoint) {
     void* p = glfwGetWindowUserPointer(w);
     if(p != nullptr) {
-        static_cast<Window*>(p)->textInput.onCharEvent(codepoint);
+        TextInput* input = static_cast<Window*>(p)->textInput;
+        if(input != nullptr) {
+            input->onCharEvent(codepoint);
+        }
     }
 }

+ 2 - 2
rendering/Window.h

@@ -8,11 +8,11 @@
 #include "rendering/WindowOptions.h"
 
 class Window final {
-    TextInput& textInput;
+    TextInput*& textInput;
     GLFWwindow* window;
 
 public:
-    Window(TextInput& textInput, const WindowOptions& options);
+    Window(TextInput*& textInput, const WindowOptions& options);
     ~Window();
 
     Window(const Window&) = delete;