2 Commits 6a49522064 ... 9cd1e3d6df

Author SHA1 Message Date
  arc13 9cd1e3d6df Merge branch 'master' of https://notabug.org/arc13/cpp3ds-template-v2 6 years ago
  arc13 d012b13da2 Updated KeyboardApplet 6 years ago
2 changed files with 17 additions and 12 deletions
  1. 11 6
      src/KeyboardApplet.cpp
  2. 6 6
      src/KeyboardApplet.hpp

+ 11 - 6
src/KeyboardApplet.cpp

@@ -5,7 +5,7 @@ namespace {
 SwkbdCallbackResult callbackUrl(void* user, const char** ppMessage, const char* text, size_t textlen)
 {
 	cpp3ds::String strError;
-	auto kb = reinterpret_cast<Template::KeyboardApplet*>(user);
+	auto kb = reinterpret_cast<Clock::KeyboardApplet*>(user);
 
 	// TODO: Add verification
 	return SWKBD_CALLBACK_OK;
@@ -19,9 +19,9 @@ SwkbdCallbackResult callbackUrl(void* user, const char** ppMessage, const char*
 }
 
 
-namespace Template {
+namespace Clock {
 
-KeyboardApplet::KeyboardApplet(InputType type)
+KeyboardApplet::KeyboardApplet(InputType type, int maxTextLength)
 	: m_type(type)
 	, m_button(SWKBD_BUTTON_NONE)
 	, m_swkbdLearning(nullptr)
@@ -29,16 +29,21 @@ KeyboardApplet::KeyboardApplet(InputType type)
 	switch (type)
 	{
 		case URL:
-			swkbdInit(&m_swkbdState, SWKBD_TYPE_NORMAL, 2, -1);
+			swkbdInit(&m_swkbdState, SWKBD_TYPE_NORMAL, 2, maxTextLength);
 			swkbdSetHintText(&m_swkbdState, "https://");
 			swkbdSetValidation(&m_swkbdState, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
 			swkbdSetFilterCallback(&m_swkbdState, callbackUrl, this);
 			swkbdSetFeatures(&m_swkbdState, SWKBD_PREDICTIVE_INPUT);
 			break;
+		case Number:
+			swkbdInit(&m_swkbdState, SWKBD_TYPE_NUMPAD, 2, maxTextLength);
+			swkbdSetValidation(&m_swkbdState, SWKBD_ANYTHING, 0, 0);
+			swkbdSetFeatures(&m_swkbdState, SWKBD_PREDICTIVE_INPUT);
+			break;
 		case Text:
 			// Fall through
 		default:
-			swkbdInit(&m_swkbdState, SWKBD_TYPE_NORMAL, 2, -1);
+			swkbdInit(&m_swkbdState, SWKBD_TYPE_NORMAL, 2, maxTextLength);
 			swkbdSetValidation(&m_swkbdState, SWKBD_ANYTHING, 0, 0);
 			swkbdSetFeatures(&m_swkbdState, SWKBD_PREDICTIVE_INPUT);
 	}
@@ -81,4 +86,4 @@ void KeyboardApplet::addDictWord(const std::string &typedWord, const std::string
 }
 
 
-} // namespace Template
+} // namespace Clock

+ 6 - 6
src/KeyboardApplet.hpp

@@ -1,11 +1,11 @@
-#ifndef TEMPLATE_KEYBOARDAPPLET_HPP
-#define TEMPLATE_KEYBOARDAPPLET_HPP
+#ifndef CLOCK_KEYBOARDAPPLET_HPP
+#define CLOCK_KEYBOARDAPPLET_HPP
 
 #include <3ds.h>
 #include <cpp3ds/System/String.hpp>
 #include <vector>
 
-namespace Template {
+namespace Clock {
 
 class KeyboardApplet {
 public:
@@ -15,7 +15,7 @@ public:
 		URL,
 	};
 
-	KeyboardApplet(InputType type = Text);
+	KeyboardApplet(InputType type = Text, int maxTextLength = -1);
 	~KeyboardApplet();
 	operator SwkbdState*();
 
@@ -36,6 +36,6 @@ private:
 	std::vector<SwkbdDictWord> m_dictWords;
 };
 
-} // namespace Template
+} // namespace Clock
 
-#endif //TEMPLATE_KEYBOARDAPPLET_HPP
+#endif //CLOCK_KEYBOARDAPPLET_HPP