diff --git a/doc/en/scripting/ui.md b/doc/en/scripting/ui.md index 4f132462..c1bf5768 100644 --- a/doc/en/scripting/ui.md +++ b/doc/en/scripting/ui.md @@ -82,6 +82,8 @@ Properties: | textWrap | bool | yes | yes | automatic text wrapping (only with multiline: "true") | | valid | bool | yes | no | is the entered text correct | | textColor | vec4 | yes | yes | text color | +| syntax | string | yes | yes | syntax highlighting ("lua" - Lua) | +| markup | string | yes | yes | text markup language ("md" - Markdown) | Methods: @@ -139,9 +141,10 @@ Properties: Properties: -| Title | Type | Read | Write | Description | -| ----- | ------ | ---- | ----- | ----------- | -| text | string | yes | yes | label text | +| Title | Type | Read | Write | Description | +| ------ | ------ | ---- | ----- | -------------------------------------- | +| text | string | yes | yes | label text | +| markup | string | yes | yes | text markup language ("md" - Markdown) | ## Image diff --git a/doc/ru/scripting/ui.md b/doc/ru/scripting/ui.md index 4d244210..07d93013 100644 --- a/doc/ru/scripting/ui.md +++ b/doc/ru/scripting/ui.md @@ -82,6 +82,8 @@ document["worlds-panel"]:clear() | textWrap | bool | да | да | автоматический перенос текста (только при multiline: "true") | | valid | bool | да | нет | является ли введенный текст корректным | | textColor | vec4 | да | да | цвет текста | +| syntax | string | да | да | подсветка синтаксиса ("lua" - Lua) | +| markup | string | да | да | язык разметки текста ("md" - Markdown) | Методы: @@ -139,9 +141,10 @@ document["worlds-panel"]:clear() Свойства: -| Название | Тип | Чтение | Запись | Описание | -| -------- | ------ | ------ | ------ | ----------- | -| text | string | да | да | текст метки | +| Название | Тип | Чтение | Запись | Описание | +| -------- | ------ | ------ | ------ | -------------------------------------- | +| text | string | да | да | текст метки | +| markup | string | да | да | язык разметки текста ("md" - Markdown) | ## Изображение (image) diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index e55e1c5b..fb24c7e8 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -859,6 +859,10 @@ void TextBox::setSyntax(std::string_view lang) { } } +const std::string& TextBox::getSyntax() const { + return syntax; +} + void TextBox::setMarkup(std::string_view lang) { markup = lang; } diff --git a/src/graphics/ui/elements/TextBox.hpp b/src/graphics/ui/elements/TextBox.hpp index 0b89b21b..be459b89 100644 --- a/src/graphics/ui/elements/TextBox.hpp +++ b/src/graphics/ui/elements/TextBox.hpp @@ -227,6 +227,7 @@ namespace gui { virtual void setOnDownPressed(const runnable &callback); virtual void setSyntax(std::string_view lang); + virtual const std::string& getSyntax() const; virtual void setMarkup(std::string_view lang); virtual const std::string& getMarkup() const; diff --git a/src/logic/scripting/lua/libs/libgui.cpp b/src/logic/scripting/lua/libs/libgui.cpp index 56239fac..004e24e5 100644 --- a/src/logic/scripting/lua/libs/libgui.cpp +++ b/src/logic/scripting/lua/libs/libgui.cpp @@ -299,6 +299,22 @@ static int p_get_line_numbers(UINode* node, lua::State* L) { return 0; } +static int p_get_syntax(UINode* node, lua::State* L) { + if (auto box = dynamic_cast(node)) { + return lua::pushstring(L, box->getSyntax()); + } + return 0; +} + +static int p_get_markup(UINode* node, lua::State* L) { + if (auto box = dynamic_cast(node)) { + return lua::pushstring(L, box->getMarkup()); + } else if (auto label = dynamic_cast(node)) { + return lua::pushstring(L, label->getMarkup()); + } + return 0; +} + static int p_get_src(UINode* node, lua::State* L) { if (auto image = dynamic_cast(node)) { return lua::pushstring(L, image->getTexture()); @@ -420,6 +436,8 @@ static int l_gui_getattr(lua::State* L) { {"lineNumbers", p_get_line_numbers}, {"lineAt", p_get_line_at}, {"linePos", p_get_line_pos}, + {"syntax", p_get_syntax}, + {"markup", p_get_markup}, {"src", p_get_src}, {"value", p_get_value}, {"min", p_get_min}, @@ -512,6 +530,18 @@ static void p_set_line_numbers(UINode* node, lua::State* L, int idx) { box->setShowLineNumbers(lua::toboolean(L, idx)); } } +static void p_set_syntax(UINode* node, lua::State* L, int idx) { + if (auto box = dynamic_cast(node)) { + box->setSyntax(lua::require_string(L, idx)); + } +} +static void p_set_markup(UINode* node, lua::State* L, int idx) { + if (auto box = dynamic_cast(node)) { + box->setMarkup(lua::require_string(L, idx)); + } else if (auto label = dynamic_cast(node)) { + label->setMarkup(lua::require_string(L, idx)); + } +} static void p_set_src(UINode* node, lua::State* L, int idx) { if (auto image = dynamic_cast(node)) { image->setTexture(lua::require_string(L, idx)); @@ -612,6 +642,8 @@ static int l_gui_setattr(lua::State* L) { {"text", p_set_text}, {"editable", p_set_editable}, {"lineNumbers", p_set_line_numbers}, + {"syntax", p_set_syntax}, + {"markup", p_set_markup}, {"src", p_set_src}, {"caret", p_set_caret}, {"value", p_set_value},