65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#pragma once
|
|
#include <Event.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <J3ML/LinearAlgebra.h>
|
|
#include <JUI/UDim2.hpp>
|
|
|
|
namespace JUI
|
|
{
|
|
|
|
class Widget
|
|
{
|
|
public:
|
|
Widget();
|
|
Widget(Widget* parent);
|
|
virtual ~Widget() {}
|
|
public:
|
|
Event<> Focused;
|
|
Event<> Unfocused;
|
|
Event<Widget *> DescendantAdded;
|
|
Event<Widget *> DescendantRemoved;
|
|
Event<Widget *, Widget*> AncestryChanged;
|
|
Event<Widget *> ChildAdded;
|
|
Event<Widget *> ChildRemoved;
|
|
Event<Widget *> Destroying;
|
|
public:
|
|
Widget* Add(Widget* newChild);
|
|
bool IsAncestorOf(Widget* w) const;
|
|
bool IsDescendantOf(Widget* w) const;
|
|
Widget* FindFirstChild(const std::string& name);
|
|
std::vector<Widget*> GetDescendants();
|
|
std::vector<Widget*> GetAncestors();
|
|
std::vector<Widget*> GetChildren();
|
|
virtual Vector2 GetAbsoluteSize() const;
|
|
virtual Vector2 GetAbsolutePosition() const;
|
|
virtual float GetAbsoluteRotation() const;
|
|
Widget* GetParent() const;
|
|
|
|
public:
|
|
virtual void Draw();
|
|
virtual void Update(float delta);
|
|
Widget* GetFamilyTreeRoot() const;
|
|
protected:
|
|
UDim2 position;
|
|
UDim2 size;
|
|
Widget* parent = nullptr;
|
|
std::vector<Widget*> children;
|
|
float rotation = 0;
|
|
std::string name;
|
|
bool selected = false;
|
|
UDim pad_left = 0_px;
|
|
UDim pad_right = 0_px;
|
|
UDim pad_top = 0_px;
|
|
UDim pad_bottom = 0_px;
|
|
UDim margin_left = 0_px;
|
|
UDim margin_right = 0_px;
|
|
UDim margin_top = 0_px;
|
|
UDim margin_bottom = 0_px;
|
|
Vector2 anchor_point = {0.f, 0.f};
|
|
bool visible = true;
|
|
Widget* next = nullptr;
|
|
Widget* prev = nullptr;
|
|
};
|
|
}
|