25#ifndef TGUI_KEYBOARD_HPP
26#define TGUI_KEYBOARD_HPP
30#include <TGUI/Config.hpp>
32#include <TGUI/Backend/Window/Backend.hpp>
33#include <TGUI/Backend/Window/BackendGui.hpp>
35#include <TGUI/Container.hpp>
36#include <TGUI/Event.hpp>
37#include <TGUI/Widgets/ScrollablePanel.hpp>
41namespace tgui::keyboard
43#ifndef TGUI_REMOVE_DEPRECATED_CODE
44 TGUI_DEPRECATED(
"Use BackendGui::startTextInput instead")
45 inline
void openVirtualKeyboard(const Widget* requestingWidget, FloatRect inputRect)
47 TGUI_ASSERT(requestingWidget !=
nullptr,
"requestingWidget must not be nullptr");
48 if (!requestingWidget)
51 const Widget* widget = requestingWidget;
54 const bool defaultOrigin = (widget->getOrigin().x == 0) && (widget->getOrigin().y == 0);
55 const bool scaledOrRotated = (widget->getScale().x != 1) || (widget->getScale().y != 1) || (widget->getRotation() != 0);
56 if (defaultOrigin && !scaledOrRotated)
57 inputRect.setPosition(inputRect.getPosition() + widget->getPosition());
60 const Vector2f origin{widget->getOrigin().x * widget->getSize().x, widget->getOrigin().y * widget->getSize().y};
62 inputRect.setPosition(inputRect.getPosition() + widget->getPosition() - origin);
65 const Vector2f rotOrigin{widget->getRotationOrigin().x * widget->getSize().x,
66 widget->getRotationOrigin().y * widget->getSize().y};
67 const Vector2f scaleOrigin{widget->getScaleOrigin().x * widget->getSize().x,
68 widget->getScaleOrigin().y * widget->getSize().y};
71 transform.translate(widget->getPosition() - origin);
72 transform.rotate(widget->getRotation(), rotOrigin);
73 transform.scale(widget->getScale(), scaleOrigin);
74 inputRect = transform.transformRect(inputRect);
78 const Container* parent = widget->getParent();
81 inputRect.setPosition(inputRect.getPosition() + parent->getChildWidgetsOffset());
83 const auto* panel =
dynamic_cast<const ScrollablePanel*
>(parent);
85 inputRect.setPosition(inputRect.getPosition() - panel->getContentOffset());
91 const auto* gui = requestingWidget->getParentGui();
94 const Vector2f topLeftPos = gui->mapCoordsToPixel(inputRect.getPosition());
95 const Vector2f bottomRightPos = gui->mapCoordsToPixel(inputRect.getPosition() + inputRect.getSize());
96 inputRect = {topLeftPos, bottomRightPos - topLeftPos};
99 TGUI_IGNORE_DEPRECATED_WARNINGS_START
101 TGUI_IGNORE_DEPRECATED_WARNINGS_END
106 [[nodiscard]]
inline bool isShiftPressed(
const Event::KeyEvent& event)
112#ifndef TGUI_REMOVE_DEPRECATED_CODE
113 TGUI_DEPRECATED(
"Use isShiftPressed(gui) instead") [[nodiscard]]
inline bool isShiftPressed()
115 TGUI_IGNORE_DEPRECATED_WARNINGS_START
116 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Shift);
117 TGUI_IGNORE_DEPRECATED_WARNINGS_END
122 [[nodiscard]]
inline bool isShiftPressed(
const BackendGui* gui)
124 return gui->isKeyboardModifierPressed(Event::KeyModifier::Shift);
128#ifndef TGUI_REMOVE_DEPRECATED_CODE
129 TGUI_DEPRECATED(
"Use BackendGui::stopTextInput instead") inline
void closeVirtualKeyboard()
131 TGUI_IGNORE_DEPRECATED_WARNINGS_START
133 TGUI_IGNORE_DEPRECATED_WARNINGS_END
138 [[nodiscard]]
inline bool isMultiselectModifierPressed(
const Event::KeyEvent& event)
140#ifdef TGUI_SYSTEM_MACOS
143 return event.control;
148#ifndef TGUI_REMOVE_DEPRECATED_CODE
149 TGUI_DEPRECATED(
"Use isMultiselectModifierPressed(gui) instead") [[nodiscard]]
inline bool isMultiselectModifierPressed()
151 TGUI_IGNORE_DEPRECATED_WARNINGS_START
152 #ifdef TGUI_SYSTEM_MACOS
153 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::System);
155 return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Control);
157 TGUI_IGNORE_DEPRECATED_WARNINGS_END
162 [[nodiscard]]
inline bool isMultiselectModifierPressed(
const BackendGui* gui)
164#ifdef TGUI_SYSTEM_MACOS
165 return gui->isKeyboardModifierPressed(Event::KeyModifier::System);
167 return gui->isKeyboardModifierPressed(Event::KeyModifier::Control);
173 [[nodiscard]]
inline bool isKeyPressCopy(
const Event::KeyEvent& event)
175#ifdef TGUI_SYSTEM_MACOS
176 return (event.code ==
Event::KeyboardKey::C) && !
event.control && !
event.alt && !
event.shift &&
event.system;
178 return (event.code ==
Event::KeyboardKey::C) &&
event.control && !
event.alt && !
event.shift && !
event.system;
184 [[nodiscard]]
inline bool isKeyPressCut(
const Event::KeyEvent& event)
186#ifdef TGUI_SYSTEM_MACOS
187 return (event.code ==
Event::KeyboardKey::X) && !
event.control && !
event.alt && !
event.shift &&
event.system;
189 return (event.code ==
Event::KeyboardKey::X) &&
event.control && !
event.alt && !
event.shift && !
event.system;
195 [[nodiscard]]
inline bool isKeyPressPaste(
const Event::KeyEvent& event)
197#ifdef TGUI_SYSTEM_MACOS
198 return (event.code ==
Event::KeyboardKey::V) && !
event.control && !
event.alt && !
event.shift &&
event.system;
200 return (event.code ==
Event::KeyboardKey::V) &&
event.control && !
event.alt && !
event.shift && !
event.system;
206 [[nodiscard]]
inline bool isKeyPressSelectAll(
const Event::KeyEvent& event)
208#ifdef TGUI_SYSTEM_MACOS
209 return (event.code ==
Event::KeyboardKey::A) && !
event.control && !
event.alt && !
event.shift &&
event.system;
211 return (event.code ==
Event::KeyboardKey::A) &&
event.control && !
event.alt && !
event.shift && !
event.system;
217 [[nodiscard]]
inline bool isKeyPressMoveCaretLeft(
const Event::KeyEvent& event)
224 [[nodiscard]]
inline bool isKeyPressMoveCaretRight(
const Event::KeyEvent& event)
231 [[nodiscard]]
inline bool isKeyPressMoveCaretWordBegin(
const Event::KeyEvent& event)
233#ifdef TGUI_SYSTEM_MACOS
242 [[nodiscard]]
inline bool isKeyPressMoveCaretWordEnd(
const Event::KeyEvent& event)
244#ifdef TGUI_SYSTEM_MACOS
253 [[nodiscard]]
inline bool isKeyPressMoveCaretUp(
const Event::KeyEvent& event)
255#ifdef TGUI_SYSTEM_MACOS
265 [[nodiscard]]
inline bool isKeyPressMoveCaretDown(
const Event::KeyEvent& event)
267#ifdef TGUI_SYSTEM_MACOS
277 [[nodiscard]]
inline bool isKeyPressMoveCaretLineStart(
const Event::KeyEvent& event)
279#ifdef TGUI_SYSTEM_MACOS
288 [[nodiscard]]
inline bool isKeyPressMoveCaretLineEnd(
const Event::KeyEvent& event)
290#ifdef TGUI_SYSTEM_MACOS
299 [[nodiscard]]
inline bool isKeyPressMoveCaretDocumentBegin(
const Event::KeyEvent& event)
301#ifdef TGUI_SYSTEM_MACOS
311 [[nodiscard]]
inline bool isKeyPressMoveCaretDocumentEnd(
const Event::KeyEvent& event)
313#ifdef TGUI_SYSTEM_MACOS
323 [[nodiscard]]
inline bool isKeyPressDeleteWordLeft(
const Event::KeyEvent& event)
325#ifdef TGUI_SYSTEM_MACOS
334 [[nodiscard]]
inline bool isKeyPressDeleteWordRight(
const Event::KeyEvent& event)
336#ifdef TGUI_SYSTEM_MACOS
TGUI_API std::shared_ptr< Backend > getBackend()
Returns the global backend.
@ X
The X key.
Definition Event.hpp:65
@ Down
Down arrow.
Definition Event.hpp:116
@ C
The C key.
Definition Event.hpp:44
@ Up
Up arrow.
Definition Event.hpp:115
@ V
The V key.
Definition Event.hpp:63
@ A
The A key.
Definition Event.hpp:42
@ End
The End key.
Definition Event.hpp:105
@ Home
The Home key.
Definition Event.hpp:106
@ Right
Right arrow.
Definition Event.hpp:114
@ Left
Left arrow.
Definition Event.hpp:113
@ Backspace
The Backspace key.
Definition Event.hpp:101
@ Delete
The Delete key.
Definition Event.hpp:108