infinipaint/src/GUIStuff/Elements/TextBox.decl.hpp

46 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include "Element.hpp"
#include "../../RichText/TextBox.hpp"
#include <limits>
#include <modules/skparagraph/include/TextStyle.h>
#include "../../FontData.hpp"
#include "../../InputManager.hpp"
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;
bool updateEveryEdit = false;
bool immutable = false;
InputManager::TextInputProperties textInputProps;
std::function<void()> onEdit;
std::function<void()> onEnter;
};
template <typename T> class TextBox : public Element {
public:
TextBox(GUIManager& gui);
void layout(const Clay_ElementId& id, const TextBoxData<T>& userInfo);
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
~TextBox();
private:
2026-04-01 18:40:52 +03:00
void init_textbox(UpdateInputData& io, bool forceTextUpdate);
bool update_data();
2026-04-01 18:40:52 +03:00
std::optional<T> oldData;
bool isSelected = false;
TextBoxData<T> userInfo;
std::shared_ptr<RichText::TextBox> textbox;
std::shared_ptr<RichText::TextBox::Cursor> cur;
std::shared_ptr<SCollision::AABB<float>> rect;
};
}