Stuck on non-render of test scene.
This commit is contained in:
@@ -26,14 +26,14 @@ namespace JUI {
|
||||
void Update(float delta) override;
|
||||
bool IsMouseInside() const;
|
||||
|
||||
Color4 GetBGColor() const;
|
||||
Color4 GetBorderColor() const;
|
||||
float GetBorderWidth() const;
|
||||
Color4 GetBGColor() const { return bg_color; }
|
||||
Color4 GetBorderColor() const { return border_color;}
|
||||
float GetBorderWidth() const { return border_width;}
|
||||
|
||||
|
||||
void SetBGColor(const Color4&);
|
||||
void SetBorderColor(const Color4&);
|
||||
void SetBorderWidth(float f);
|
||||
void SetBGColor(const Color4& col) { bg_color = col;}
|
||||
void SetBorderColor(const Color4& col) { border_color = col;}
|
||||
void SetBorderWidth(float w) {border_width = w;}
|
||||
|
||||
|
||||
void SetCornerRounding(float radius);
|
||||
@@ -48,5 +48,11 @@ namespace JUI {
|
||||
SetBorderColor(color);
|
||||
SetBorderWidth(width);
|
||||
}
|
||||
protected:
|
||||
float border_width = 1.f;
|
||||
Color4 bg_color = {128,128,128, 255};
|
||||
Color4 border_color = {192, 192, 192, 0};
|
||||
bool clips_descendants = false; // Controls if child objects can render outside of their parent's rectangle bounds.
|
||||
float corner_rounding_radius = 0.f; // Curves the rectangle corners by N degrees.
|
||||
};
|
||||
}
|
||||
|
@@ -9,8 +9,13 @@ namespace JUI
|
||||
class Scene : public Widget {
|
||||
public:
|
||||
Scene();
|
||||
|
||||
~Scene() override {}
|
||||
void Draw() override;
|
||||
void Update(float delta) override;
|
||||
|
||||
[[nodiscard]] Vector2 GetAbsolutePosition() const override;
|
||||
|
||||
[[nodiscard]] Vector2 GetAbsoluteSize() const override;
|
||||
};
|
||||
}
|
||||
|
@@ -42,9 +42,9 @@ namespace JUI
|
||||
virtual float GetAbsoluteRotation() const;
|
||||
Widget* GetParent() const;
|
||||
|
||||
UDim2 GetPosition() const;
|
||||
[[nodiscard]] UDim2 GetPosition() const;
|
||||
|
||||
UDim2 GetSize() const;
|
||||
[[nodiscard]] UDim2 GetSize() const;
|
||||
|
||||
void SetPosition(const UDim2 &pos);
|
||||
|
||||
@@ -56,19 +56,47 @@ namespace JUI
|
||||
|
||||
bool IsAncestorOf(Widget *descendant);
|
||||
|
||||
Vector2 GetAnchorPoint() const;
|
||||
[[nodiscard]] Vector2 GetAnchorPoint() const;
|
||||
|
||||
[[nodiscard]] UDim GetPaddingLeft() const;
|
||||
[[nodiscard]] UDim GetPaddingTop() const;
|
||||
[[nodiscard]] UDim GetPaddingRight() const;
|
||||
[[nodiscard]] UDim GetPaddingBottom() const;
|
||||
|
||||
void SetPaddingLeft(const UDim &pad_left);
|
||||
void SetPaddingTop(const UDim &pad_top);
|
||||
void SetPaddingRight(const UDim &pad_right);
|
||||
void SetPaddingBottom(const UDim &pad_bottom);
|
||||
|
||||
void SetPadding(const UDim& left, const UDim& top, const UDim& right, const UDim& bottom);
|
||||
void SetPadding(const UDim& padding);
|
||||
|
||||
[[nodiscard]] UDim GetMarginLeft() const;
|
||||
[[nodiscard]] UDim GetMarginTop() const;
|
||||
[[nodiscard]] UDim GetMarginRight() const;
|
||||
[[nodiscard]] UDim GetMarginBottom() const;
|
||||
|
||||
void SetMarginLeft(const UDim &ml);
|
||||
void SetMarginTop(const UDim &mt);
|
||||
void SetMarginRight(const UDim &mr);
|
||||
void SetMarginBottom(const UDim &mb);
|
||||
|
||||
void SetMargin(const UDim& left, const UDim& top, const UDim& right, const UDim& bottom);
|
||||
void SetMargin(const UDim& margin);
|
||||
|
||||
|
||||
UDim GetPaddingLeft() const;
|
||||
UDim GetPaddingTop() const;
|
||||
UDim GetPaddingRight() const;
|
||||
UDim GetPaddingBottom() const;
|
||||
[[nodiscard]] std::string GetName() const;
|
||||
void SetName(const std::string &new_name);
|
||||
|
||||
[[nodiscard]] bool IsVisible() const;
|
||||
|
||||
void SetVisible(bool enabled);
|
||||
|
||||
public:
|
||||
virtual void Draw();
|
||||
virtual void Update(float delta);
|
||||
void DrawChildWidgets();
|
||||
void UpdateChildWidgets(float delta);
|
||||
Widget* GetFamilyTreeRoot() const;
|
||||
protected:
|
||||
UDim2 position;
|
||||
|
15
main.cpp
15
main.cpp
@@ -30,9 +30,9 @@ public:
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
JGL::Update(getSize());
|
||||
|
||||
JGL::J2D::Begin();
|
||||
JGL::J2D::FillRect(JGL::Color3(255,0,0), {0,0}, {50, 50});
|
||||
JGL::J2D::End();
|
||||
//JGL::J2D::Begin();
|
||||
//JGL::J2D::FillRect(JGL::Color3(255,0,0), {0,0}, {50, 50});
|
||||
//JGL::J2D::End();
|
||||
}
|
||||
|
||||
//bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent &e) override {}
|
||||
@@ -42,14 +42,15 @@ public:
|
||||
JUI::Scene* CreateScene() {
|
||||
using namespace JUI;
|
||||
|
||||
Scene* root;
|
||||
Scene* root = new Scene();
|
||||
|
||||
Rect* element = new Rect(root);
|
||||
element->SetBGColor({0,255,0});
|
||||
element->SetSize({50_px, 50_px});
|
||||
auto size = UDim2(64, 64, 0, 0);
|
||||
element->SetSize(size);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
@@ -67,6 +68,8 @@ int main()
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
scene->Update(0.f);
|
||||
scene->Draw();
|
||||
window->glSwapBuffers();
|
||||
}
|
||||
return 0;
|
||||
|
@@ -1,7 +1,47 @@
|
||||
#include <JGL/JGL.h>
|
||||
#include <JUI/Rect.hpp>
|
||||
|
||||
JUI::Rect::Rect(): Widget() {}
|
||||
namespace JUI {
|
||||
Rect::Rect(): Widget() {}
|
||||
|
||||
Rect::Rect(Widget *parent): Rect() {
|
||||
this->SetParent(parent);
|
||||
}
|
||||
|
||||
void Rect::Draw() {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
Vector2 abs_size = GetAbsoluteSize();
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
// TODO: Re-enable clipping
|
||||
|
||||
|
||||
// Background rect
|
||||
//J2D::FillRoundedRect(bg_color, abs_pos, abs_size, corner_rounding_radius);
|
||||
|
||||
J2D::FillRect(bg_color, abs_pos, abs_size);
|
||||
|
||||
// Outline rect
|
||||
if (corner_rounding_radius >= 0) {
|
||||
J2D::OutlineRect(border_color, abs_pos, abs_size);
|
||||
//J2D::OutlineRoundedRect(bg_color, abs_pos, abs_size, corner_rounding_radius, border_width);
|
||||
}
|
||||
|
||||
|
||||
Widget::Draw();
|
||||
// TODO: Return clip to previous state
|
||||
}
|
||||
|
||||
|
||||
void Rect::Update(float delta) {
|
||||
Widget::Update(delta);
|
||||
}
|
||||
|
||||
JUI::Rect::Rect(Widget *parent): Rect() {
|
||||
this->SetParent(parent);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1 +1,20 @@
|
||||
#include <JUI/Scene.hpp>
|
||||
#include <JUI/Scene.hpp>
|
||||
|
||||
namespace JUI {
|
||||
Scene::Scene(): Widget() {}
|
||||
|
||||
Vector2 Scene::GetAbsolutePosition() const { return {0,0};}
|
||||
|
||||
Vector2 Scene::GetAbsoluteSize() const { return {600,480};}
|
||||
|
||||
|
||||
void Scene::Draw() {
|
||||
Widget::Draw();
|
||||
}
|
||||
|
||||
void Scene::Update(float delta) {
|
||||
Widget::Update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -87,11 +87,52 @@ namespace JUI {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Widget *> Widget::GetChildren() {
|
||||
return this->children;
|
||||
Vector2 Widget::GetAnchorPoint() const {
|
||||
return anchor_point;
|
||||
}
|
||||
|
||||
UDim Widget::GetPaddingLeft() const { return pad_left;}
|
||||
UDim Widget::GetPaddingTop() const { return pad_top;}
|
||||
UDim Widget::GetPaddingRight() const { return pad_right;}
|
||||
UDim Widget::GetPaddingBottom() const { return pad_bottom;}
|
||||
|
||||
void Widget::SetPaddingLeft (const UDim& pl) { pad_left = pl;}
|
||||
void Widget::SetPaddingTop (const UDim& pt) { pad_top = pt;}
|
||||
void Widget::SetPaddingRight (const UDim& pr) { pad_right = pr;}
|
||||
void Widget::SetPaddingBottom(const UDim& pb) { pad_bottom = pb;}
|
||||
|
||||
UDim Widget::GetMarginLeft () const { return margin_left;}
|
||||
UDim Widget::GetMarginTop () const { return margin_top;}
|
||||
UDim Widget::GetMarginRight () const { return margin_right;}
|
||||
UDim Widget::GetMarginBottom() const { return margin_bottom;}
|
||||
|
||||
void Widget::SetMarginLeft(const UDim& ml) { margin_left = ml;}
|
||||
void Widget::SetMarginTop(const UDim& mt) { margin_top = mt;}
|
||||
void Widget::SetMarginRight(const UDim& mr) { margin_right = mr;}
|
||||
void Widget::SetMarginBottom(const UDim& mb) { margin_bottom = mb;}
|
||||
|
||||
std::string Widget::GetName() const { return name; }
|
||||
void Widget::SetName(const std::string& new_name) { name = new_name;}
|
||||
|
||||
bool Widget::IsVisible() const { return visible; }
|
||||
void Widget::SetVisible(bool enabled) { visible = enabled;}
|
||||
|
||||
Widget* Widget::GetParent() const { return parent;}
|
||||
|
||||
UDim2 Widget::GetPosition() const { return position; }
|
||||
void Widget::SetPosition(const UDim2& pos) { position = pos; }
|
||||
|
||||
UDim2 Widget::GetSize() const { return size;}
|
||||
void Widget::SetSize(const UDim2& s) { size = s; }
|
||||
|
||||
float Widget::GetAbsoluteRotation() const {
|
||||
// TODO: implement correctly!!
|
||||
return rotation;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Widget *> Widget::GetChildren() { return children; }
|
||||
|
||||
std::vector<Widget *> Widget::GetDescendants() {
|
||||
std::vector<Widget*> descendants;
|
||||
for (auto& child: this->GetChildren()) {
|
||||
@@ -110,16 +151,7 @@ namespace JUI {
|
||||
return ancestors;
|
||||
}
|
||||
|
||||
Widget* Widget::GetParent() const { return parent;}
|
||||
|
||||
UDim2 Widget::GetPosition() const { return position; }
|
||||
UDim2 Widget::GetSize() const { return size;}
|
||||
|
||||
void Widget::SetPosition(const UDim2& pos) {
|
||||
position = pos;
|
||||
}
|
||||
|
||||
void Widget::SetSize(const UDim2& s) { size = s; }
|
||||
|
||||
Vector2 Widget::GetAbsolutePosition() const {
|
||||
auto child_pos_scale = this->GetPosition().GetScale();
|
||||
@@ -154,6 +186,60 @@ namespace JUI {
|
||||
Vector2 parent_abs_size = this->GetParent()->GetAbsoluteSize();
|
||||
|
||||
UDim padding_h = parent->GetPaddingLeft() + parent->GetPaddingRight();
|
||||
float final_pad_x = padding_h.Pixels + (padding_h.Scale * parent->GetAbsoluteSize().x);
|
||||
|
||||
UDim padding_v = parent->GetPaddingTop() + parent->GetPaddingBottom();
|
||||
float final_pad_y = padding_v.Pixels + (padding_v.Scale * parent->GetAbsoluteSize().y);
|
||||
|
||||
Vector2 pad_size_reduction = {final_pad_x, final_pad_y};
|
||||
|
||||
Vector2 abs_size = child_size_px + (parent_abs_size * child_size_scale) - pad_size_reduction;
|
||||
|
||||
// TODO: Take into account constraints on widgets.
|
||||
return abs_size;
|
||||
}
|
||||
|
||||
|
||||
// TODO: Consider std::optional
|
||||
Widget* Widget::FindFirstChild(const std::string& search_name) {
|
||||
for (auto& child : children) {
|
||||
if (child->GetName() == search_name)
|
||||
return child;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Widget::Draw() {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
DrawChildWidgets();
|
||||
}
|
||||
|
||||
void Widget::Update(float delta) {
|
||||
|
||||
UpdateChildWidgets(delta);
|
||||
}
|
||||
|
||||
void Widget::DrawChildWidgets() {
|
||||
for (auto child : children) {
|
||||
child->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::UpdateChildWidgets(float delta) {
|
||||
for (auto child : children) {
|
||||
child->Update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
Widget* Widget::GetFamilyTreeRoot() const {
|
||||
// This is stupid, Fix ASAP!
|
||||
auto parent = this->GetParent();
|
||||
if (parent->GetParent() == nullptr)
|
||||
return parent;
|
||||
return parent->GetFamilyTreeRoot();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user