diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index 3e68f392..1328b4dc 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -361,10 +361,18 @@ std::wstring TextBox::getText() const { return input; } -void TextBox::setText(std::wstring value) { +void TextBox::setText(const std::wstring value) { this->input = value; } +std::wstring TextBox::getPlaceholder() const { + return placeholder; +} + +void TextBox::setPlaceholder(const std::wstring& placeholder) { + this->placeholder = placeholder; +} + // ============================== InputBindBox ================================ InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding) : Panel(glm::vec2(100,32), padding, 0), diff --git a/src/frontend/gui/controls.h b/src/frontend/gui/controls.h index fd62f0db..1d0cb1ea 100644 --- a/src/frontend/gui/controls.h +++ b/src/frontend/gui/controls.h @@ -122,6 +122,8 @@ namespace gui { virtual std::wstring getText() const; /* Set TextBox content text */ virtual void setText(std::wstring value); + virtual std::wstring getPlaceholder() const; + virtual void setPlaceholder(const std::wstring&); virtual bool validate(); virtual void setValid(bool valid); virtual bool isValid() const; diff --git a/src/lighting/Lightmap.h b/src/lighting/Lightmap.h index 16a273dd..12d2b586 100644 --- a/src/lighting/Lightmap.h +++ b/src/lighting/Lightmap.h @@ -73,11 +73,11 @@ public: return map; } - static inline light_t combine(int r, int g, int b, int s) { + static constexpr light_t combine(int r, int g, int b, int s) { return r | (g << 4) | (b << 8) | (s << 12); } - static inline light_t extract(light_t light, ubyte channel) { + static constexpr light_t extract(light_t light, ubyte channel) { return (light >> (channel << 2)) & 0xF; } diff --git a/src/logic/scripting/lua/libgui.cpp b/src/logic/scripting/lua/libgui.cpp index cdcc6561..d83c57f9 100644 --- a/src/logic/scripting/lua/libgui.cpp +++ b/src/logic/scripting/lua/libgui.cpp @@ -103,6 +103,29 @@ static bool getattr(lua_State* L, gui::FullCheckBox* box, const std::string& att return false; } +static bool getattr(lua_State* L, gui::TextBox* box, const std::string& attr) { + if (box == nullptr) + return false; + if (attr == "text") { + lua_pushstring(L, util::wstr2str_utf8(box->getText()).c_str()); + return true; + } else if (attr == "placeholder") { + lua_pushstring(L, util::wstr2str_utf8(box->getPlaceholder()).c_str()); + return true; + } + return false; +} + +static bool setattr(lua_State* L, gui::FullCheckBox* box, const std::string& attr) { + if (box == nullptr) + return false; + if (attr == "checked") { + box->setChecked(lua_toboolean(L, 4)); + return true; + } + return false; +} + static bool setattr(lua_State* L, gui::Button* button, const std::string& attr) { if (button == nullptr) return false; @@ -115,11 +138,14 @@ static bool setattr(lua_State* L, gui::Button* button, const std::string& attr) return false; } -static bool setattr(lua_State* L, gui::FullCheckBox* box, const std::string& attr) { +static bool setattr(lua_State* L, gui::TextBox* box, const std::string& attr) { if (box == nullptr) return false; - if (attr == "checked") { - box->setChecked(lua_toboolean(L, 4)); + if (attr == "text") { + box->setText(util::str2wstr_utf8(lua_tostring(L, 4))); + return true; + } else if (attr == "placeholder") { + box->setPlaceholder(util::str2wstr_utf8(lua_tostring(L, 4))); return true; } return false; @@ -161,6 +187,8 @@ int l_gui_getattr(lua_State* L) { return 1; if (getattr(L, dynamic_cast(node), attr)) return 1; + if (getattr(L, dynamic_cast(node), attr)) + return 1; if (getattr(L, dynamic_cast(node), attr)) return 1; if (getattr(L, dynamic_cast(node), attr)) @@ -197,6 +225,8 @@ int l_gui_setattr(lua_State* L) { return 0; if (setattr(L, dynamic_cast(node), attr)) return 0; + if (setattr(L, dynamic_cast(node), attr)) + return 0; if (setattr(L, dynamic_cast(node), attr)) return 0; if (setattr(L, dynamic_cast(node), attr)) diff --git a/src/window/Window.h b/src/window/Window.h index 751c2058..9712c588 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -9,9 +9,9 @@ #include -class GLFWwindow; class ImageData; struct DisplaySettings; +struct GLFWwindow; struct GLFWmonitor; enum class blendmode {