JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
TextInputSession.hpp
Go to the documentation of this file.
1// Copyright 2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Rect.hpp"
8
9#include <cstdint>
10#include <memory>
11#include <string>
12#include <vector>
13
14namespace jngl {
15
16namespace internal {
17void feedTextInput(const std::string& utf8);
18void reapplyTextInputSession();
19void reapplyTextInputArea();
20void ensureLegacyTextInputStarted();
21} // namespace internal
22
27enum class TextInputType : uint8_t {
28 Text,
29 Password,
30 Number,
31 Email,
32};
33
72public:
73 explicit TextInputSession(TextInputType type = TextInputType::Text);
74
75 TextInputSession(const TextInputSession&) = delete;
76 TextInputSession& operator=(const TextInputSession&) = delete;
78 TextInputSession& operator=(TextInputSession&&) noexcept;
80
88
99 void setInputArea(Rect area, double cursor = 0);
100
101private:
102 struct Impl;
104
108 static void applyActive();
109
112 static void applyArea();
113
114 static std::vector<Impl*> stack;
115 static bool legacyStarted;
116
117 friend void internal::feedTextInput(const std::string&);
118 friend void internal::reapplyTextInputSession();
119 friend void internal::reapplyTextInputArea();
120 friend void internal::ensureLegacyTextInputStarted();
121};
122
123} // namespace jngl
Contains jngl::Rect class.
RAII handle representing a text input field that currently wants to receive typed characters.
void setInputArea(Rect area, double cursor=0)
Tells the OS/IME where on screen this field is, in JNGL Screen coordinates (i.e.
std::string take()
Returns the UTF-8 characters typed since the last call to take() and clears them.
Rectangle shaped text block.
Definition text.hpp:39
T internal(T... args)
JNGL's main namespace.
TextInputType
What kind of text a TextInputSession is used for.
Simple struct for a rectangle, can be use with jngl::contains.
Definition Rect.hpp:13