new content menu (WIP)

This commit is contained in:
MihailRis
2024-05-02 04:07:07 +03:00
parent 690e3f54c9
commit 5915b811f2
27 changed files with 340 additions and 202 deletions
+8
View File
@@ -125,6 +125,14 @@ void Container::remove(std::shared_ptr<UINode> selected) {
refresh();
}
void Container::clear() {
for (auto node : nodes) {
node->setParent(nullptr);
}
nodes.clear();
refresh();
}
void Container::listenInterval(float interval, ontimeout callback, int repeat) {
intervalEvents.push_back({callback, interval, 0.0f, repeat});
}
+1
View File
@@ -24,6 +24,7 @@ namespace gui {
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
virtual void add(std::shared_ptr<UINode> node);
virtual void add(std::shared_ptr<UINode> node, glm::vec2 pos);
virtual void clear();
virtual void remove(std::shared_ptr<UINode> node);
virtual void scrolled(int value) override;
virtual void setScrollable(bool flag);
+6 -2
View File
@@ -22,9 +22,13 @@ void Image::draw(const DrawContext* pctx, Assets* assets) {
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
}
batch->texture(texture);
batch->setColor(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,
0, 0, 0, UVRegion(), false, true, color);
0, 0, 0, UVRegion(), false, true, batch->getColor());
}
void Image::setAutoResize(bool flag) {
+4
View File
@@ -52,6 +52,10 @@ void Panel::add(std::shared_ptr<UINode> node) {
void Panel::refresh() {
UINode::refresh();
std::stable_sort(nodes.begin(), nodes.end(), [](auto a, auto b) {
return a->getZIndex() < b->getZIndex();
});
float x = padding.x;
float y = padding.y;
glm::vec2 size = getSize();
+12 -1
View File
@@ -198,7 +198,18 @@ int UINode::getZIndex() const {
return zindex;
}
void UINode::lock() {
void UINode::moveInto(
std::shared_ptr<UINode> node,
std::shared_ptr<Container> dest
) {
auto parent = node->getParent();
if (auto container = dynamic_cast<Container*>(parent)) {
container->remove(node);
}
if (parent) {
parent->scrolled(0);
}
dest->add(node);
}
vec2supplier UINode::getPositionFunc() const {
+5 -1
View File
@@ -17,6 +17,7 @@ class Assets;
namespace gui {
class UINode;
class GUI;
class Container;
using onaction = std::function<void(GUI*)>;
using onnumberchange = std::function<void(GUI*, double)>;
@@ -188,7 +189,10 @@ namespace gui {
parent->fullRefresh();
}
};
virtual void lock();
static void moveInto(
std::shared_ptr<UINode> node,
std::shared_ptr<Container> dest
);
virtual vec2supplier getPositionFunc() const;
virtual void setPositionFunc(vec2supplier);