More boilerplate

This commit is contained in:
2024-08-05 12:42:04 -04:00
parent e5659ee535
commit 91bb1e1be8
4 changed files with 49 additions and 30 deletions

View File

@@ -22,17 +22,20 @@ namespace JUI
class ImageBase
{
public:
ImageBase();
ImageBase(JGL::Texture* texture);
public:
[[nodiscard]] JGL::Texture* Content() const { return texture;}
[[nodiscard]] Color4 Color() const { return image_color;}
[[nodiscard]] Vector2 Scale() const { return scale;}
[[nodiscard]] Vector2 Origin() const { return origin;}
void SetContent(JGL::Texture* content);
void Color(const Color4& newColor);
void Scale(const Vector2& newScale);
void Origin(const Vector2& newOrigin);
public:
void Draw(const Vector2& pos, const Vector2& size);
void SetContent(JGL::Texture* content)
{
this->texture = content;
}
protected:
JGL::Texture* texture;
Color4 image_color = Color4(255,255,255);

View File

@@ -21,32 +21,14 @@ namespace JUI
public:
Image();
explicit Image(Widget* parent);
explicit Image(Widget* parent, JGL::Texture* tex) : Widget(), ImageBase(tex)
{
this->SetParent(parent);
}
explicit Image(Widget* parent, JGL::Texture* tex);
~Image() override {}
public:
Vector2 GetAbsoluteSize() const override
{
return parent->GetAbsoluteSize();
}
Vector2 GetAbsolutePosition() const override
{
return parent->GetAbsolutePosition();
}
Vector2 GetAbsoluteSize() const override;
Vector2 GetAbsolutePosition() const override;
void Draw() override
{
// TODO: Factor in margin?
ImageBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
Widget::Draw();
}
void Update(float delta) override
{
Widget::Update(delta);
}
void Draw() override;
void Update(float delta) override;
};
}

View File

@@ -20,5 +20,15 @@ namespace JUI
{
this->texture = tex;
}
void ImageBase::SetContent(JGL::Texture *content) {
this->texture = content;
}
void ImageBase::Color(const Color4 &newColor) { this->image_color = newColor;}
void ImageBase::Scale(const Vector2 &newScale) { scale = newScale;}
void ImageBase::Origin(const Vector2 &newOrigin) { origin = newOrigin; }
}

View File

@@ -11,4 +11,28 @@ namespace JUI
{
SetParent(parent);
}
Image::Image(Widget *parent, JGL::Texture *tex) : Widget(), ImageBase(tex)
{
this->SetParent(parent);
}
Vector2 Image::GetAbsoluteSize() const {
return parent->GetAbsoluteSize();
}
Vector2 Image::GetAbsolutePosition() const {
return parent->GetAbsolutePosition();
}
void Image::Draw() {
// TODO: Factor in margin?
ImageBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
Widget::Draw();
}
void Image::Update(float delta) {
Widget::Update(delta);
}
}