Fixed world name label behaviour

This commit is contained in:
MihailRis 2024-01-18 20:11:47 +03:00
parent b12d242335
commit 9c110b83d3
4 changed files with 23 additions and 2 deletions

View File

@ -78,9 +78,20 @@ bool UINode::isInside(glm::vec2 pos) {
}
shared_ptr<UINode> UINode::getAt(vec2 pos, shared_ptr<UINode> self) {
if (!interactive) {
return nullptr;
}
return isInside(pos) ? self : nullptr;
}
bool UINode::isInteractive() const {
return interactive;
}
void UINode::setInteractive(bool flag) {
interactive = flag;
}
vec2 UINode::calcCoord() const {
if (parent) {
return coord + parent->calcCoord() + parent->contentOffset();

View File

@ -30,6 +30,7 @@ namespace gui {
bool hover_ = false;
bool pressed_ = false;
bool focused_ = false;
bool interactive = true;
Align align_ = Align::left;
UINode* parent = nullptr;
UINode(glm::vec2 coord, glm::vec2 size);
@ -74,9 +75,12 @@ namespace gui {
virtual bool isInside(glm::vec2 pos);
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
virtual bool isInteractive() const;
virtual void setInteractive(bool flag);
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
glm::vec2 calcCoord() const;
void setCoord(glm::vec2 coord);
virtual void setCoord(glm::vec2 coord);
glm::vec2 size() const;
virtual void size(glm::vec2 size);
void _size(glm::vec2 size);

View File

@ -18,6 +18,9 @@ Container::Container(vec2 coord, vec2 size) : UINode(coord, size) {
}
shared_ptr<UINode> Container::getAt(vec2 pos, shared_ptr<UINode> self) {
if (!interactive) {
return nullptr;
}
if (!isInside(pos)) return nullptr;
for (auto node : nodes) {
if (!node->visible())

View File

@ -201,7 +201,10 @@ Panel* create_worlds_panel(Engine* engine) {
auto btn = std::make_shared<RichButton>(vec2(390, 46));
btn->color(vec4(1.0f, 1.0f, 1.0f, 0.1f));
btn->setHoverColor(vec4(1.0f, 1.0f, 1.0f, 0.17f));
btn->add(std::make_shared<Label>(namews), vec2(8, 8));
auto label = std::make_shared<Label>(namews);
label->setInteractive(false);
btn->add(label, vec2(8, 8));
btn->listenAction([=](GUI*) {
open_world(name, engine);
});