Dawn/archive/ui/UIElement.hpp

80 lines
2.2 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/UIShader.hpp"
#include "component/ui/UICanvas.hpp"
namespace Dawn {
class UIElement {
protected:
/**
* Virtual method overridden by the UIElement to get the quads for the
* component.
*
* @param alignment The alignment of this component.
* @param ctx The canvas to add the quads to.
*/
virtual void getSelfQuads(UICanvas &ctx);
public:
/**
* Overrided method by the UI Element that requests the minimum
* width of the content.
*
* @return The minimum width of the content.
*/
virtual float_t getContentWidth();
/**
* Overrided method by the UI Element that requests the minimum
* height of the content.
*
* @return The minimum height of the content.
*/
virtual float_t getContentHeight();
/**
* Returns the width of this component.
*
* @return The width of this component.
*/
virtual float_t getWidth();
/**
* Returns the height of this component.
*
* @return The height of this component.
*/
virtual float_t getHeight();
/**
* Virtual method overridden by the UIElement to get the children of
* this component.
*/
virtual std::vector<std::shared_ptr<UIElement>> getChildren();
/**
* Method called by the UICanvas to get the quads for this component.
*
* @param ctx The canvas to add the quads to.
*/
void getQuads(UICanvas &ctx);
/**
* Updates the alignment of this component based on the parent. Typically
* left to the UIAlignableElement to implement, default implementation
* does nothing but invoke children.
*
* @param parentPosition The position of the parent.
* @param parentSize The size of the parent.
*/
virtual void updateAlignment(
const glm::vec2 parentPosition,
const glm::vec2 parentSize,
const float_t canvasScale
);
};
}