2026-03-27 09:51:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
#include "Element.hpp"
|
|
|
|
|
#include "../../RichText/TextBox.hpp"
|
|
|
|
|
#include <limits>
|
|
|
|
|
#include <modules/skparagraph/include/TextStyle.h>
|
|
|
|
|
#include "../../FontData.hpp"
|
|
|
|
|
#include "../../InputManager.hpp"
|
2026-04-03 23:02:33 +03:00
|
|
|
#include "../../RichTextUserInput.hpp"
|
2026-03-27 09:51:53 +03:00
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
|
|
|
|
template <typename T> struct TextBoxData {
|
|
|
|
|
T* data = nullptr;
|
|
|
|
|
std::function<std::optional<T>(const std::string&)> fromStr;
|
|
|
|
|
std::function<std::string(const T&)> toStr;
|
|
|
|
|
bool singleLine = true;
|
2026-04-07 19:15:58 +03:00
|
|
|
bool updateEveryEdit = true;
|
2026-03-27 09:51:53 +03:00
|
|
|
bool immutable = false;
|
|
|
|
|
InputManager::TextInputProperties textInputProps;
|
|
|
|
|
std::function<void()> onEdit;
|
|
|
|
|
std::function<void()> onEnter;
|
2026-04-04 17:52:43 +03:00
|
|
|
std::function<void()> onSelect;
|
|
|
|
|
std::function<void()> onDeselect;
|
2026-03-27 09:51:53 +03:00
|
|
|
};
|
|
|
|
|
|
2026-04-03 23:02:33 +03:00
|
|
|
|
|
|
|
|
struct TextEditData {
|
2026-04-04 17:52:43 +03:00
|
|
|
TextEditData(unsigned initTextboxInputID, const std::shared_ptr<RichText::TextBox>& initTextBox, const std::shared_ptr<RichText::TextBox::Cursor>& initCursor):
|
2026-04-03 23:02:33 +03:00
|
|
|
textboxInputID(initTextboxInputID),
|
2026-04-04 17:52:43 +03:00
|
|
|
userInput(initTextBox, initCursor, nullptr)
|
2026-04-03 23:02:33 +03:00
|
|
|
{}
|
|
|
|
|
unsigned textboxInputID;
|
|
|
|
|
RichTextUserInput userInput;
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
template <typename T> class TextBox : public Element {
|
|
|
|
|
public:
|
|
|
|
|
TextBox(GUIManager& gui);
|
|
|
|
|
|
2026-03-31 17:33:09 +03:00
|
|
|
void layout(const Clay_ElementId& id, const TextBoxData<T>& userInfo);
|
2026-03-27 09:51:53 +03:00
|
|
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
2026-04-04 17:52:43 +03:00
|
|
|
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste) override;
|
2026-04-03 23:02:33 +03:00
|
|
|
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
2026-04-04 17:52:43 +03:00
|
|
|
virtual void input_text_callback(const InputManager::TextCallbackArgs& text) override;
|
2026-04-02 21:57:26 +03:00
|
|
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
|
|
|
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
2026-03-27 09:51:53 +03:00
|
|
|
~TextBox();
|
|
|
|
|
private:
|
2026-04-04 17:52:43 +03:00
|
|
|
void after_text_input_callback();
|
2026-04-01 21:49:44 +03:00
|
|
|
void init_textbox(UpdateInputData& io);
|
|
|
|
|
void reset_textbox_text();
|
2026-03-27 09:51:53 +03:00
|
|
|
bool update_data();
|
2026-04-03 23:02:33 +03:00
|
|
|
bool is_selected() const;
|
|
|
|
|
|
2026-04-04 22:28:33 +03:00
|
|
|
bool isHeld = false;
|
2026-04-03 23:02:33 +03:00
|
|
|
std::optional<TextEditData> edit;
|
2026-03-27 09:51:53 +03:00
|
|
|
|
2026-04-01 18:40:52 +03:00
|
|
|
std::optional<T> oldData;
|
2026-03-27 09:51:53 +03:00
|
|
|
TextBoxData<T> userInfo;
|
|
|
|
|
std::shared_ptr<RichText::TextBox> textbox;
|
|
|
|
|
std::shared_ptr<RichText::TextBox::Cursor> cur;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|