JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
jngl
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
14
namespace
jngl
{
15
16
namespace
internal
{
17
void
feedTextInput(
const
std::string
& utf8);
18
void
reapplyTextInputSession();
19
void
reapplyTextInputArea();
20
void
ensureLegacyTextInputStarted();
21
}
// namespace internal
22
27
enum class
TextInputType
: uint8_t {
28
Text
,
29
Password,
30
Number,
31
Email,
32
};
33
71
class
TextInputSession
{
72
public
:
73
explicit
TextInputSession
(
TextInputType
type = TextInputType::Text);
74
75
TextInputSession
(
const
TextInputSession
&) =
delete
;
76
TextInputSession
& operator=(
const
TextInputSession
&) =
delete
;
77
TextInputSession
(
TextInputSession
&&)
noexcept
;
78
TextInputSession
& operator=(
TextInputSession
&&)
noexcept
;
79
~TextInputSession
();
80
87
std::string
take
();
88
99
void
setInputArea
(
Rect
area,
double
cursor = 0);
100
101
private
:
102
struct
Impl;
103
std::unique_ptr<Impl>
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
Rect.hpp
Contains jngl::Rect class.
std::string
jngl::TextInputSession
RAII handle representing a text input field that currently wants to receive typed characters.
Definition
TextInputSession.hpp:71
jngl::TextInputSession::setInputArea
void setInputArea(Rect area, double cursor=0)
Tells the OS/IME where on screen this field is, in JNGL Screen coordinates (i.e.
jngl::TextInputSession::take
std::string take()
Returns the UTF-8 characters typed since the last call to take() and clears them.
jngl::Text
Rectangle shaped text block.
Definition
text.hpp:39
cstdint
std::internal
T internal(T... args)
memory
jngl
JNGL's main namespace.
Definition
Achievement.hpp:10
jngl::TextInputType
TextInputType
What kind of text a TextInputSession is used for.
Definition
TextInputSession.hpp:27
string
jngl::Rect
Simple struct for a rectangle, can be use with jngl::contains.
Definition
Rect.hpp:13
std::unique_ptr
vector