Pasting text from clipboard

This commit is contained in:
MihailRis 2024-01-05 13:55:15 +03:00
parent 73595cd558
commit 0f1aabf200
4 changed files with 16 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 124 KiB

View File

@ -2,6 +2,7 @@
#include <iostream>
#include "../../window/Events.h"
#include "../../assets/Assets.h"
#include "../../graphics/Batch2D.h"
#include "../../graphics/Font.h"
@ -21,7 +22,9 @@ const uint KEY_BACKSPACE = 259;
using namespace gui;
Label::Label(wstring text, string fontName)
: UINode(vec2(), vec2(text.length() * 8, 15)), text_(text), fontName_(fontName) {
: UINode(vec2(), vec2(text.length() * 8, 15)),
text_(text),
fontName_(fontName) {
}
Label& Label::text(wstring text) {
@ -175,6 +178,13 @@ void TextBox::keyPressed(int key) {
defocus();
break;
}
// Pasting text from clipboard
if (key == keycode::V && Events::pressed(keycode::LEFT_CONTROL)) {
const char* text = Window::getClipboardText();
if (text) {
input += util::str2wstr_utf8(text);
}
}
}
shared_ptr<UINode> TextBox::getAt(vec2 pos, shared_ptr<UINode> self) {

View File

@ -298,6 +298,10 @@ ImageData* Window::takeScreenshot() {
return new ImageData(ImageFormat::rgb888, width, height, data);
}
const char* Window::getClipboardText() {
return glfwGetClipboardString(window);
}
bool Window::tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor) {
glm::ivec4 windowFrame(0);
glm::ivec4 workArea(0);

View File

@ -49,6 +49,7 @@ public:
static void clearDepth();
static void setBgColor(glm::vec3 color);
static double time();
static const char* getClipboardText();
static DisplaySettings* getSettings();
static glm::vec2 size() {