settings menu update + UINode 'enabled' property

This commit is contained in:
MihailRis
2024-04-30 16:41:44 +03:00
parent 9b843817f8
commit 2380375f3c
15 changed files with 130 additions and 84 deletions
+5 -1
View File
@@ -79,7 +79,11 @@ void Button::drawBackground(const DrawContext* pctx, Assets* assets) {
glm::vec2 pos = calcPos();
auto batch = pctx->getBatch2D();
batch->texture(nullptr);
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
if (enabled) {
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
} else {
batch->setColor({color.r, color.g, color.b, color.a * 0.5f});
}
batch->rect(pos.x, pos.y, size.x, size.y);
}
+1 -1
View File
@@ -11,7 +11,7 @@ Container::Container(glm::vec2 size) : UINode(size) {
}
std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
if (!interactive) {
if (!interactive || !enabled) {
return nullptr;
}
if (!isInside(pos)) return nullptr;
+13 -1
View File
@@ -20,6 +20,18 @@ void UINode::setVisible(bool flag) {
visible = flag;
}
void UINode::setEnabled(bool flag) {
enabled = flag;
if (!flag) {
defocus();
hover = false;
}
}
bool UINode::isEnabled() const {
return enabled;
}
Align UINode::getAlign() const {
return align;
}
@@ -82,7 +94,7 @@ bool UINode::isInside(glm::vec2 point) {
}
std::shared_ptr<UINode> UINode::getAt(glm::vec2 point, std::shared_ptr<UINode> self) {
if (!interactive) {
if (!interactive || !enabled) {
return nullptr;
}
return isInside(point) ? self : nullptr;
+8 -2
View File
@@ -1,14 +1,15 @@
#ifndef GRAPHICS_UI_ELEMENTS_UINODE_H_
#define GRAPHICS_UI_ELEMENTS_UINODE_H_
#include "../../../delegates.h"
#include "../../../window/input.h"
#include <glm/glm.hpp>
#include <vector>
#include <memory>
#include <string>
#include <functional>
#include <unordered_map>
#include "../../../delegates.h"
#include "../../../window/input.h"
class DrawContext;
class Assets;
@@ -60,6 +61,8 @@ namespace gui {
glm::vec4 pressedColor {1.0f};
/// @brief element margin (only supported for Panel sub-nodes)
glm::vec4 margin {1.0f};
/// @brief element enabled state
bool enabled = true;
/// @brief is element visible
bool visible = true;
/// @brief is mouse over the element
@@ -95,6 +98,9 @@ namespace gui {
virtual void setVisible(bool flag);
bool isVisible() const;
virtual void setEnabled(bool flag);
bool isEnabled() const;
virtual void setAlign(Align align);
Align getAlign() const;
+3
View File
@@ -87,6 +87,9 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
if (element->has("visible")) {
node.setVisible(element->attr("visible").asBool());
}
if (element->has("enabled")) {
node.setEnabled(element->attr("enabled").asBool());
}
if (element->has("position-func")) {
node.setPositionFunc(scripting::create_vec2_supplier(
reader.getEnvironment(),
+5
View File
@@ -304,6 +304,9 @@ static int l_gui_getattr(lua_State* L) {
} else if (attr == "visible") {
lua_pushboolean(L, node->isVisible());
return 1;
} else if (attr == "enabled") {
lua_pushboolean(L, node->isEnabled());
return 1;
}
if (getattr(L, dynamic_cast<Container*>(node), attr))
@@ -350,6 +353,8 @@ static int l_gui_setattr(lua_State* L) {
node->setInteractive(lua_toboolean(L, 4));
} else if (attr == "visible") {
node->setVisible(lua_toboolean(L, 4));
} else if (attr == "enabled") {
node->setEnabled(lua_toboolean(L, 4));
} else {
if (setattr(L, dynamic_cast<Button*>(node), attr))
return 0;