65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
//
|
|
// Created by sebastian on 10.02.26.
|
|
//
|
|
|
|
#ifndef DICEWARS_SIEDLER_UICOMPONENT_H
|
|
#define DICEWARS_SIEDLER_UICOMPONENT_H
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "layout/UiPositioner.h"
|
|
#include "../../../renderer/components/UiRenderBundle.h"
|
|
#include "../../../renderer/model/GUITexture.h"
|
|
|
|
enum class UiElementState {
|
|
NORMAL, HOVERED, PRESSED
|
|
};
|
|
|
|
struct UiEvent {
|
|
bool handled = false;
|
|
virtual ~UiEvent() = default;
|
|
};
|
|
|
|
|
|
class UiComponent {
|
|
public:
|
|
UiComponent() :uiPositioner(*this) {};
|
|
explicit UiComponent(const LayoutStyle& layout) : uiPositioner(*this, layout) {};
|
|
virtual ~UiComponent() = default;
|
|
template<typename T>
|
|
T* addChild(std::unique_ptr<UiComponent> child) {
|
|
T* ptr = static_cast<T*>(child.get());
|
|
child->parent = this;
|
|
children.push_back(std::move(child));
|
|
return ptr; // NOLINT
|
|
}
|
|
void setVisible(bool visible);
|
|
[[nodiscard]] bool isVisible() const;
|
|
void update(float delta);
|
|
void collectRenderData(UiRenderBundle& uiRenderBundle);
|
|
virtual bool isMouseOver(float mouseX, float mouseY);
|
|
UiComponent* parent = nullptr;
|
|
UiPositioner uiPositioner;
|
|
std::vector<std::unique_ptr<UiComponent>> children;
|
|
|
|
LayoutStyle& getLayoutStyle() {
|
|
return uiPositioner.getLayout();
|
|
}
|
|
void setLayoutStyle(const LayoutStyle& style) {
|
|
uiPositioner.setLayout(style);
|
|
}
|
|
virtual void onClick() {};
|
|
|
|
UiComponent* getChildAtIndex(size_t t) const;
|
|
|
|
void dispatchEvent(UiEvent& event);
|
|
protected:
|
|
bool visible = true;
|
|
|
|
virtual void onUpdate(float );
|
|
virtual void onCollectRenderData(UiRenderBundle& uiRenderBundle) {}
|
|
|
|
};
|
|
|
|
|
|
#endif //DICEWARS_SIEDLER_UICOMPONENT_H
|