#pragma once #include "Helpers/ConvertVec.hpp" #include #include "../../TimePoint.hpp" #include #include #include #include #include #include #include #include #include "../../RichTextBox/RichTextBox.hpp" using namespace Eigen; namespace GUIStuff { // Taken from https://github.com/TimothyHoytBSME/ClayMan (rewritten to be a separate struct, and use templates to change size) template class StringArena { public: StringArena() { stringArena = std::vector(S); } void reset() { stringArenaIndex = 0; } const char* insert_string_into_arena(const std::string& str) { size_t strSize = str.size(); if(stringArenaIndex + strSize + 1 > S) throw std::overflow_error("[StringArena::insert_string_into_arena] Not enough space to insert string"); char* startPtr = &stringArena[stringArenaIndex]; for(size_t i = 0; i < strSize; i++) stringArena[stringArenaIndex++] = str[i]; stringArena[stringArenaIndex++] = ' '; return startPtr; } Clay_String std_str_to_clay_str(const std::string& str) { return Clay_String{.length = static_cast(str.size()), .chars = insert_string_into_arena(str)}; } private: std::vector stringArena; size_t stringArenaIndex; }; typedef StringArena<4000000> DefaultStringArena; SkFont get_setup_skfont(); struct Theme { SkColor4f fillColor1 = {0.8f, 0.785f, 1.0f, 1.0f}; SkColor4f fillColor2 = {0.3f, 0.3f, 0.477f, 1.0f}; SkColor4f backColor1 = {0.0f, 0.0f, 0.0f, 1.0f}; SkColor4f backColor2 = {1.0f, 1.0f, 1.0f, 1.0f}; SkColor4f frontColor1 = {1.0f, 1.0f, 1.0f, 1.0f}; SkColor4f frontColor2 = {0.9f, 0.9f, 0.9f, 1.0f}; SkColor4f errorColor = {1.0f, 0.0f, 0.0f, 1.0f}; SkColor4f warningColor = {1.0f, 1.0f, 0.0f, 1.0f}; float hoverExpandTime = 0.1f; uint16_t childGap1 = 10; uint16_t padding1 = 8; float windowCorners1 = 8; uint16_t windowBorders1 = 0; NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Theme, fillColor1, fillColor2, backColor1, backColor2, frontColor1, frontColor2, hoverExpandTime, childGap1, padding1, windowCorners1, windowBorders1) }; std::shared_ptr get_default_dark_mode(); struct UpdateInputData { struct { int leftClick = 0; int rightClick = 0; bool leftDoubleClick = false; bool leftHeld = false; bool rightHeld = false; Vector2f globalPos{0, 0}; Vector2f pos{0, 0}; // Position relative to window Vector2f scroll; } mouse; struct { bool left = false; bool right = false; bool up = false; bool down = false; bool leftShift = false; bool leftCtrl = false; bool home = false; bool del = false; bool backspace = false; bool enter = false; bool selectAll = false; bool copy = false; bool paste = false; bool cut = false; bool escape = false; } key; struct { std::function textInFunc; std::optional textOut; } clipboard; std::function, std::shared_ptr)> richTextBoxEdit; SkFont get_font(float fSize) const; uint16_t fontSize = 16; sk_sp textTypeface; sk_sp fontCollection; std::string textInput; bool hoverObstructed = false; bool acceptingTextInput = false; float deltaTime = 0.0f; sk_sp textFontMgr; DefaultStringArena* strArena; std::shared_ptr theme; std::unordered_map> svgData; }; class SelectionHelper { public: void update(bool isHovering, bool isLeftClick, bool isLeftHeld); bool held = false; bool hovered = false; bool selected = false; bool clicked = false; bool justUnselected = false; }; class Element { public: virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command) = 0; virtual ~Element() = default; protected: static SCollision::AABB get_bb(Clay_RenderCommand* command); }; }