gui: added UINode.zindex
This commit is contained in:
@@ -143,6 +143,14 @@ glm::vec4 UINode::getMargin() const {
|
|||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UINode::setZIndex(int zindex) {
|
||||||
|
this->zindex = zindex;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UINode::getZIndex() const {
|
||||||
|
return zindex;
|
||||||
|
}
|
||||||
|
|
||||||
void UINode::lock() {
|
void UINode::lock() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ namespace gui {
|
|||||||
bool focused = false;
|
bool focused = false;
|
||||||
bool interactive = true;
|
bool interactive = true;
|
||||||
bool resizing = true;
|
bool resizing = true;
|
||||||
|
int zindex = 0;
|
||||||
Align align = Align::left;
|
Align align = Align::left;
|
||||||
UINode* parent = nullptr;
|
UINode* parent = nullptr;
|
||||||
UINode(glm::vec2 coord, glm::vec2 size);
|
UINode(glm::vec2 coord, glm::vec2 size);
|
||||||
@@ -68,6 +69,9 @@ namespace gui {
|
|||||||
virtual void setMargin(glm::vec4 margin);
|
virtual void setMargin(glm::vec4 margin);
|
||||||
glm::vec4 getMargin() const;
|
glm::vec4 getMargin() const;
|
||||||
|
|
||||||
|
virtual void setZIndex(int idx);
|
||||||
|
int getZIndex() const;
|
||||||
|
|
||||||
virtual void focus(GUI*) {focused = true;}
|
virtual void focus(GUI*) {focused = true;}
|
||||||
virtual void click(GUI*, int x, int y);
|
virtual void click(GUI*, int x, int y);
|
||||||
virtual void clicked(GUI*, int button) {}
|
virtual void clicked(GUI*, int button) {}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ static void _readUINode(xml::xmlelement element, UINode& node) {
|
|||||||
if (element->has("margin")) {
|
if (element->has("margin")) {
|
||||||
node.setMargin(element->attr("margin").asVec4());
|
node.setMargin(element->attr("margin").asVec4());
|
||||||
}
|
}
|
||||||
|
if (element->has("z-index")) {
|
||||||
|
node.setZIndex(element->attr("z-index").asInt());
|
||||||
|
}
|
||||||
std::string alignName = element->attr("align", "").getText();
|
std::string alignName = element->attr("align", "").getText();
|
||||||
node.setAlign(align_from_string(alignName, node.getAlign()));
|
node.setAlign(align_from_string(alignName, node.getAlign()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,12 @@ void Container::setSize(glm::vec2 size) {
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Container::refresh() {
|
||||||
|
std::stable_sort(nodes.begin(), nodes.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a->getZIndex() < b->getZIndex();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<UINode>>& Container::getNodes() const {
|
const std::vector<std::shared_ptr<UINode>>& Container::getNodes() const {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
@@ -190,6 +196,7 @@ void Panel::add(std::shared_ptr<UINode> node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Panel::refresh() {
|
void Panel::refresh() {
|
||||||
|
UINode::refresh();
|
||||||
float x = padding.x;
|
float x = padding.x;
|
||||||
float y = padding.y;
|
float y = padding.y;
|
||||||
vec2 size = getSize();
|
vec2 size = getSize();
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ namespace gui {
|
|||||||
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
||||||
virtual glm::vec2 contentOffset() override {return glm::vec2(0.0f, scroll);};
|
virtual glm::vec2 contentOffset() override {return glm::vec2(0.0f, scroll);};
|
||||||
virtual void setSize(glm::vec2 size) override;
|
virtual void setSize(glm::vec2 size) override;
|
||||||
|
virtual void refresh() override;
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<UINode>>& getNodes() const;
|
const std::vector<std::shared_ptr<UINode>>& getNodes() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -251,6 +251,8 @@ HudRenderer::HudRenderer(Engine* engine, LevelFrontend* frontend)
|
|||||||
debugPanel = createDebugPanel(engine);
|
debugPanel = createDebugPanel(engine);
|
||||||
menu->reset();
|
menu->reset();
|
||||||
|
|
||||||
|
debugPanel->setZIndex(1);
|
||||||
|
|
||||||
gui->addBack(darkOverlay);
|
gui->addBack(darkOverlay);
|
||||||
gui->addBack(hotbarView);
|
gui->addBack(hotbarView);
|
||||||
gui->add(debugPanel);
|
gui->add(debugPanel);
|
||||||
|
|||||||
Reference in New Issue
Block a user