diff --git a/doc/en/scripting/ui.md b/doc/en/scripting/ui.md index 22a878944..968a11929 100644 --- a/doc/en/scripting/ui.md +++ b/doc/en/scripting/ui.md @@ -34,25 +34,26 @@ Access to nested elements is performed by index (starting from one). Properties that apply to all elements: -| Name | Type | Read | Write | Description | -| ------------- | ------- | ---- | ----- | ------------------------------------------- | -| id | string | yes | *no* | element id | -| exists | bool | yes | *no* | checks if element exists | -| pos | vec2 | yes | yes | element position inside a container | -| wpos | vec2 | yes | yes | element position inside the window | -| size | vec2 | yes | yes | element size | -| interactive | bool | yes | yes | ability to interact with the element | -| enabled | bool | yes | yes | visually indicated version of *interactive* | -| visible | bool | yes | yes | element visibility | -| focused | bool | yes | yes | focus on element | -| color | rgba | yes | yes | element color | -| hoverColor | rgba | yes | yes | hover color | -| pressedColor | rgba | yes | yes | color when pressed | -| tooltip | string | yes | yes | tooltip text | -| tooltipDelay | float | yes | yes | tooltip delay | -| contentOffset | vec2 | yes | *no* | element content offset | -| cursor | string | yes | yes | cursor displayed on hover | -| parent | Element | yes | *no* | parent element or nil | +| Name | Type | Read | Write | Description | +| ------------- | ------- | ---- | ----- | ------------------------------------------------ | +| id | string | yes | *no* | element id | +| exists | bool | yes | *no* | checks if element exists | +| pos | vec2 | yes | yes | element position inside a container | +| wpos | vec2 | yes | yes | element position inside the window | +| size | vec2 | yes | yes | element size | +| interactive | bool | yes | yes | ability to interact with the element | +| enabled | bool | yes | yes | visually indicated version of *interactive* | +| visible | bool | yes | yes | element visibility | +| focused | bool | yes | yes | focus on element | +| color | rgba | yes | yes | element color | +| hoverColor | rgba | yes | yes | hover color | +| pressedColor | rgba | yes | yes | color when pressed | +| tooltip | string | yes | yes | tooltip text | +| tooltipDelay | float | yes | yes | tooltip delay | +| contentOffset | vec2 | yes | *no* | element content offset | +| cursor | string | yes | yes | cursor displayed on hover | +| parent | Element | yes | *no* | parent element or nil | +| zIndex | bool | yes | *no* | z-index value. In panel, it determines the order | Common element methods: diff --git a/doc/ru/scripting/ui.md b/doc/ru/scripting/ui.md index 05b448a43..33c4958f4 100644 --- a/doc/ru/scripting/ui.md +++ b/doc/ru/scripting/ui.md @@ -34,25 +34,26 @@ document["worlds-panel"]:clear() Свойства, относящиеся ко всем элементам: -| Название | Тип | Чтение | Запись | Описание | -| ------------- | ------- | ------ | ------ | ----------------------------------------- | -| id | string | да | *нет* | идентификатор элемента | -| exists | bool | да | *нет* | проверяет, существует ли элемент | -| pos | vec2 | да | да | позиция элемента внутри контейнера | -| wpos | vec2 | да | да | позиция элемента в окне | -| size | vec2 | да | да | размер элемента | -| interactive | bool | да | да | возможность взаимодействия с элементом | -| enabled | bool | да | да | визуально обозначаемая версия interactive | -| visible | bool | да | да | видимость элемента | -| focused | bool | да | да | фокус на элементе | -| color | rgba | да | да | цвет элемента | -| hoverColor | rgba | да | да | цвет при наведении | -| pressedColor | rgba | да | да | цвет при нажатии | -| tooltip | string | да | да | текст всплывающей подсказки | -| tooltipDelay | float | да | да | задержка всплывающей подсказки | -| contentOffset | vec2 | да | *нет* | смещение содержимого | -| cursor | string | да | да | курсор, отображаемый при наведении | -| parent | Element | да | *нет* | родительский элемент или nil | +| Название | Тип | Чтение | Запись | Описание | +| ------------- | ------- | ------ | ------ | ---------------------------------------------- | +| id | string | да | *нет* | идентификатор элемента | +| exists | bool | да | *нет* | проверяет, существует ли элемент | +| pos | vec2 | да | да | позиция элемента внутри контейнера | +| wpos | vec2 | да | да | позиция элемента в окне | +| size | vec2 | да | да | размер элемента | +| interactive | bool | да | да | возможность взаимодействия с элементом | +| enabled | bool | да | да | визуально обозначаемая версия interactive | +| visible | bool | да | да | видимость элемента | +| focused | bool | да | да | фокус на элементе | +| color | rgba | да | да | цвет элемента | +| hoverColor | rgba | да | да | цвет при наведении | +| pressedColor | rgba | да | да | цвет при нажатии | +| tooltip | string | да | да | текст всплывающей подсказки | +| tooltipDelay | float | да | да | задержка всплывающей подсказки | +| contentOffset | vec2 | да | *нет* | смещение содержимого | +| cursor | string | да | да | курсор, отображаемый при наведении | +| parent | Element | да | *нет* | родительский элемент или nil | +| zIndex | bool | да | *нет* | значение z-индекса. В panel определяет порядок | Общие методы элементов: diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 5fa617bda..05c20604a 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -135,9 +135,10 @@ void GUI::actMouse(float delta, const CursorState& cursor) { if (this->hover && this->hover != hover) { this->hover->setMouseEnter(false); } - if (hover && hover != this->hover) { - hover->setMouseEnter(true); - + if (hover) { + if (hover != this->hover) { + hover->setMouseEnter(true); + } int scroll = input.getScroll(); if (scroll) { hover->scrolled(scroll); @@ -269,7 +270,6 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) { auto& page = menu->getCurrent(); if (page.panel) { menu->setSize(page.panel->getSize()); - page.panel->refresh(); if (auto panel = std::dynamic_pointer_cast(page.panel)) { panel->cropToContent(); } diff --git a/src/graphics/ui/elements/Panel.cpp b/src/graphics/ui/elements/Panel.cpp index ed9af66c5..885ae3d61 100644 --- a/src/graphics/ui/elements/Panel.cpp +++ b/src/graphics/ui/elements/Panel.cpp @@ -67,7 +67,7 @@ void Panel::remove(UINode* node) { } void Panel::refresh() { - UINode::refresh(); + Container::refresh(); float x = padding.x; float y = padding.y; diff --git a/src/logic/scripting/lua/libs/libgui.cpp b/src/logic/scripting/lua/libs/libgui.cpp index e8cc70186..4d1506e23 100644 --- a/src/logic/scripting/lua/libs/libgui.cpp +++ b/src/logic/scripting/lua/libs/libgui.cpp @@ -577,6 +577,13 @@ static int p_get_options(UINode* node, lua::State* L) { return 0; } +static int p_get_zindex(UINode* node, lua::State* L) { + if (node == nullptr) { + return 0; + } + return lua::pushinteger(L, node->getZIndex()); +} + static int p_is_exists(UINode* node, lua::State* L) { return lua::pushboolean(L, node != nullptr); } @@ -677,6 +684,7 @@ static int l_gui_getattr(lua::State* L) { {"parent", p_get_parent}, {"region", p_get_region}, {"options", p_get_options}, + {"zIndex", p_get_zindex}, }; auto func = getters.find(attr); if (func != getters.end()) { @@ -813,6 +821,15 @@ static void p_set_options(UINode* node, lua::State* L, int idx) { selectbox->setOptions(std::move(options)); } } +static void p_set_zindex(UINode* node, lua::State* L, int idx) { + if (node == nullptr) { + return; + } + node->setZIndex(lua::tointeger(L, idx)); + if (auto parent = node->getParent()) { + parent->setMustRefresh(); + } +} static void p_set_value(UINode* node, lua::State* L, int idx) { if (auto bar = dynamic_cast(node)) { bar->setValue(lua::tonumber(L, idx)); @@ -961,6 +978,7 @@ static int l_gui_setattr(lua::State* L) { {"focused", p_set_focused}, {"region", p_set_region}, {"options", p_set_options}, + {"zIndex", p_set_zindex}, }; auto func = setters.find(attr); if (func != setters.end()) {