revert non-throwing 'id' and add 'exists' property & update doc/*/scripting/ui.md

This commit is contained in:
MihailRis 2025-11-12 18:49:04 +03:00
parent b5e69f1eae
commit ef656e9ff1
3 changed files with 8 additions and 1 deletions

View File

@ -37,6 +37,7 @@ Properties that apply to all elements:
| Name | Type | Read | Write | Description | | Name | Type | Read | Write | Description |
| ------------- | ------- | ---- | ----- | ------------------------------------------- | | ------------- | ------- | ---- | ----- | ------------------------------------------- |
| id | string | yes | *no* | element id | | id | string | yes | *no* | element id |
| exists | bool | yes | *no* | checks if element exists |
| pos | vec2 | yes | yes | element position inside a container | | pos | vec2 | yes | yes | element position inside a container |
| wpos | vec2 | yes | yes | element position inside the window | | wpos | vec2 | yes | yes | element position inside the window |
| size | vec2 | yes | yes | element size | | size | vec2 | yes | yes | element size |

View File

@ -37,6 +37,7 @@ document["worlds-panel"]:clear()
| Название | Тип | Чтение | Запись | Описание | | Название | Тип | Чтение | Запись | Описание |
| ------------- | ------- | ------ | ------ | ----------------------------------------- | | ------------- | ------- | ------ | ------ | ----------------------------------------- |
| id | string | да | *нет* | идентификатор элемента | | id | string | да | *нет* | идентификатор элемента |
| exists | bool | да | *нет* | проверяет, существует ли элемент |
| pos | vec2 | да | да | позиция элемента внутри контейнера | | pos | vec2 | да | да | позиция элемента внутри контейнера |
| wpos | vec2 | да | да | позиция элемента в окне | | wpos | vec2 | да | да | позиция элемента в окне |
| size | vec2 | да | да | размер элемента | | size | vec2 | да | да | размер элемента |

View File

@ -546,8 +546,12 @@ static int p_get_options(UINode* node, lua::State* L) {
return 0; return 0;
} }
static int p_is_exists(UINode* node, lua::State* L) {
return lua::pushboolean(L, node != nullptr);
}
static bool is_node_required(std::string_view attr) { static bool is_node_required(std::string_view attr) {
return attr != "id"; return attr != "exists";
} }
static int l_gui_getattr(lua::State* L) { static int l_gui_getattr(lua::State* L) {
@ -585,6 +589,7 @@ static int l_gui_getattr(lua::State* L) {
std::function<int(UINode*, lua::State*)>> std::function<int(UINode*, lua::State*)>>
getters { getters {
{"id", p_get_id}, {"id", p_get_id},
{"exists", p_is_exists},
{"color", p_get_color}, {"color", p_get_color},
{"hoverColor", p_get_hover_color}, {"hoverColor", p_get_hover_color},
{"pressedColor", p_get_pressed_color}, {"pressedColor", p_get_pressed_color},