Dicewars-Siedler/src/engine/core/gui/uiComponent/UiComponent.cpp
2026-02-15 16:16:00 +01:00

58 lines
1.2 KiB
C++

//
// Created by sebastian on 10.02.26.
//
#include "UiComponent.h"
#include "../../Application.h"
#include "../../../platform/glfw/InputManager.h"
#include "GLFW/glfw3.h"
size_t UiComponent::addChild(std::unique_ptr<UiComponent> child) {
child->parent = this;
children.emplace_back(std::move(child));
return children.size() - 1;
}
void UiComponent::setVisible(const bool v) {
this->visible = v;
}
bool UiComponent::isVisible() const {
return visible;
}
void UiComponent::update(float delta) {
if (!visible) return;
onUpdate(delta);
for (const auto &child : children) {
child->update(delta);
}
}
void UiComponent::collectRenderData(UiRenderBundle& uiRenderBundle) {
if (!visible) return;
onCollectRenderData(uiRenderBundle);
for (const auto &child : children) {
child->collectRenderData(uiRenderBundle);
}
}
bool UiComponent::isMouseOver(float mouseX, float mouseY) {
if (!visible) return false;
return uiPositioner.screenSpace.contains(mouseX, mouseY);
}
UiComponent* UiComponent::getChildAtIndex(size_t t) const {
return children[t].get();
}
void UiComponent::onUpdate(float) {
}