Merge pull request #733 from MihailRis/zindex-attr

z-index property access
This commit is contained in:
MihailRis 2025-12-11 22:24:55 +03:00 • committed by GitHub
commit 515d0e3812
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 63 additions and 43 deletions

View file

@ -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:

View file

@ -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 определяет порядок |
Общие методы элементов:

View file

@ -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<gui::Panel>(page.panel)) {
panel->cropToContent();
}

View file

@ -67,7 +67,7 @@ void Panel::remove(UINode* node) {
}
void Panel::refresh() {
UINode::refresh();
Container::refresh();
float x = padding.x;
float y = padding.y;

View file

@ -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<TrackBar*>(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()) {