83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "ui/UIElement.hpp"
|
|
|
|
namespace Dawn {
|
|
#define UI_ALIGN_SIZE_AUTO -1.0f
|
|
|
|
enum class UIAlignmentType {
|
|
START,
|
|
MIDDLE,
|
|
END,
|
|
STRETCH
|
|
};
|
|
|
|
enum class UIAlignmentUnit {
|
|
PIXEL,
|
|
SCALE,
|
|
PERCENT,
|
|
RATIO
|
|
};
|
|
|
|
class UIAlignableElement : public UIElement {
|
|
protected:
|
|
glm::vec2 position;
|
|
glm::vec2 size;
|
|
|
|
/**
|
|
* Updates the alignment of this element ONLY.
|
|
*
|
|
* @param parentPosition The position of the parent.
|
|
* @param parentSize The size of the parent.
|
|
* @param canvasScale The scale of the canvas.
|
|
*/
|
|
virtual void updateSelfAlignment(
|
|
const glm::vec2 parentPosition,
|
|
const glm::vec2 parentSize,
|
|
const float_t canvasScale
|
|
);
|
|
|
|
/**
|
|
* Returns true only if the width of this component is explicitly set.
|
|
*
|
|
* @return True if the width of this component is explicitly set.
|
|
*/
|
|
bool_t hasExplicitWidth();
|
|
|
|
/**
|
|
* Returns true only if the height of this component is explicitly set.
|
|
*
|
|
* @return True if the height of this component is explicitly set.
|
|
*/
|
|
bool_t hasExplicitHeight();
|
|
|
|
public:
|
|
// Primary alignment controls
|
|
glm::vec4 align = glm::vec4(0, 0, 0, 0);
|
|
enum UIAlignmentType alignX = UIAlignmentType::STRETCH;
|
|
enum UIAlignmentType alignY = UIAlignmentType::STRETCH;
|
|
enum UIAlignmentUnit alignUnit[4];
|
|
|
|
std::function<
|
|
void(const glm::vec2, const glm::vec2)
|
|
> eventAlignmentUpdated;
|
|
|
|
/**
|
|
* Constructor for the UIAlignableElement.
|
|
*/
|
|
UIAlignableElement();
|
|
|
|
float_t getWidth() override;
|
|
float_t getHeight() override;
|
|
|
|
void updateAlignment(
|
|
const glm::vec2 parentPosition,
|
|
const glm::vec2 parentSize,
|
|
const float_t canvasScale
|
|
) override;
|
|
};
|
|
} |