Refactoring basic text rendering
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include <functional>
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
struct Attributes {
|
||||
std::function<void()> onClick;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,24 +1,17 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
HorizontalLayout.h
|
||||
HorizontalLayout.cpp
|
||||
Layout.h
|
||||
Layout.cpp
|
||||
RenderHierarchy.h
|
||||
RenderHierarchy.cpp
|
||||
System.h
|
||||
System.cpp
|
||||
VerticalLayout.h
|
||||
VerticalLayout.cpp)
|
||||
Attributes.h
|
||||
Element.h
|
||||
Element.cpp
|
||||
|
||||
)
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
HorizontalLayout.h
|
||||
Layout.h
|
||||
RenderHierarchy.h
|
||||
System.h
|
||||
VerticalLayout.h)
|
||||
Attributes.h
|
||||
Element.h
|
||||
)
|
||||
|
||||
|
||||
add_subdirectory(Elements/)
|
||||
add_subdirectory(Style/)
|
||||
add_subdirectory(Element/)
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "Element.h"
|
||||
#include "System.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Array<RenderElement> Element::render() {
|
||||
RenderElement result;
|
||||
result.position = UVector2(0, 0);
|
||||
result.size = UVector2(style.width, style.height);
|
||||
result.backgroundColor = style.backgroundColor;
|
||||
result.fontSize = style.fontSize;
|
||||
result.fontFamily = style.fontFamily;
|
||||
return {result};
|
||||
}
|
||||
|
||||
Element::Element(Attributes attr, Array<OElement> children) : attr(attr), children(std::move(children)) {}
|
||||
|
||||
Element::~Element() {}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "Attributes.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "Style/Style.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
struct RenderElement;
|
||||
DECLARE_REF(Element)
|
||||
class Element {
|
||||
public:
|
||||
Element(Attributes attr, Array<OElement> children);
|
||||
virtual ~Element();
|
||||
virtual void calcStyle(Style parentStyle) = 0;
|
||||
Array<RenderElement> render();
|
||||
|
||||
protected:
|
||||
Style style;
|
||||
Attributes attr;
|
||||
Array<OElement> children;
|
||||
};
|
||||
DEFINE_REF(Element)
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,4 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Div.h
|
||||
Text.h)
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "UI/Element.h"
|
||||
#include "UI/Style/Class.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
template<StyleClass... classes>
|
||||
class Div : public Element {
|
||||
public:
|
||||
Div(Attributes attr, std::initializer_list<OElement> children) : Element(attr, children) { style.displayType = DisplayType::Block; }
|
||||
virtual ~Div() {}
|
||||
private:
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "UI/Element.h"
|
||||
#include "UI/Style/Class.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class Text : public Element {
|
||||
public:
|
||||
Text(std::string text) : Element({}, {}), text(text) {}
|
||||
virtual void calcStyle(Style parentStyle) override { style = parentStyle; }
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,4 +0,0 @@
|
||||
#include "Button.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class Button : public Element {};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,18 +0,0 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Button.h
|
||||
Button.cpp
|
||||
Element.h
|
||||
Element.cpp
|
||||
Label.h
|
||||
Label.cpp
|
||||
Panel.h
|
||||
Panel.cpp)
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
FILES
|
||||
Button.h
|
||||
Element.h
|
||||
Label.h
|
||||
Panel.h)
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "Element.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "UI/System.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Element::Element() : dirty(false), enabled(false) {}
|
||||
|
||||
Element::~Element() {}
|
||||
|
||||
void Element::setParent(PElement element) {
|
||||
if (parent != nullptr) {
|
||||
parent->removeChild(this);
|
||||
}
|
||||
parent = element;
|
||||
}
|
||||
|
||||
PElement Element::getParent() const { return parent; }
|
||||
|
||||
void Element::addChild(PElement element) { children.add(element); }
|
||||
|
||||
void Element::removeChild(PElement element) { children.remove(element, false); }
|
||||
|
||||
const Array<PElement> Element::getChildren() { return children; }
|
||||
|
||||
void Element::clear() { children.clear(); }
|
||||
|
||||
void Element::setEnabled(bool newEnabled) { enabled = newEnabled; }
|
||||
|
||||
bool Element::isEnabled() const { return enabled; }
|
||||
|
||||
Rect& Element::getBoundingBox() { return boundingBox; }
|
||||
|
||||
const Rect Element::getBoundingBox() const { return boundingBox; }
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
#include "Containers/Array.h"
|
||||
#include "Math/Math.h"
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
// Element defines any part of the UI
|
||||
DECLARE_REF(Element)
|
||||
DECLARE_REF(System)
|
||||
class Element {
|
||||
public:
|
||||
Element();
|
||||
virtual ~Element();
|
||||
void setParent(PElement element);
|
||||
PElement getParent() const;
|
||||
void addChild(PElement element);
|
||||
void removeChild(PElement element);
|
||||
const Array<PElement> getChildren();
|
||||
void clear();
|
||||
void setEnabled(bool newEnabled);
|
||||
bool isEnabled() const;
|
||||
// maybe not the healthiest inteface
|
||||
// non-const version
|
||||
Rect& getBoundingBox();
|
||||
// The bounding box describes the relative size of any Element
|
||||
// relative to the total view, meaning a bounding box of (0,0), (1,1)
|
||||
// would take up the entire view
|
||||
const Rect getBoundingBox() const;
|
||||
|
||||
protected:
|
||||
Rect boundingBox;
|
||||
bool dirty;
|
||||
|
||||
bool enabled;
|
||||
PSystem system;
|
||||
PElement parent;
|
||||
Array<PElement> children;
|
||||
friend class RenderElement;
|
||||
};
|
||||
DEFINE_REF(Element)
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,4 +0,0 @@
|
||||
#include "Label.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class Label : public Element {
|
||||
public:
|
||||
Label();
|
||||
~Label();
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "Panel.h"
|
||||
#include "UI/Layout.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Panel::Panel() {}
|
||||
|
||||
Panel::~Panel() {}
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
DECLARE_REF(Layout)
|
||||
class Panel : Element {
|
||||
public:
|
||||
Panel();
|
||||
virtual ~Panel();
|
||||
|
||||
private:
|
||||
PLayout activeLayout;
|
||||
};
|
||||
|
||||
DEFINE_REF(Panel);
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "HorizontalLayout.h"
|
||||
#include "Elements/Element.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
HorizontalLayout::HorizontalLayout(PElement element) : Layout(element) {}
|
||||
|
||||
HorizontalLayout::~HorizontalLayout() {}
|
||||
|
||||
void HorizontalLayout::apply() {
|
||||
Array<PElement> children = element->getChildren();
|
||||
const Rect parent = element->getBoundingBox();
|
||||
float xOffset = parent.offset.x;
|
||||
float yOffset = parent.offset.y;
|
||||
float xSize = parent.size.x / children.size();
|
||||
float ySize = parent.size.y;
|
||||
for (uint32 index = 0; index < children.size(); ++index) {
|
||||
Rect& child = children[index]->getBoundingBox();
|
||||
child.offset.x = xOffset + (index * xSize);
|
||||
child.offset.y = yOffset;
|
||||
child.size.x = xSize;
|
||||
child.size.y = ySize;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include "Layout.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class HorizontalLayout : Layout {
|
||||
public:
|
||||
HorizontalLayout(PElement element);
|
||||
~HorizontalLayout();
|
||||
virtual void apply() override;
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "Layout.h"
|
||||
#include "Elements/Element.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
Layout::Layout(PElement element) : element(element) {}
|
||||
|
||||
Layout::~Layout() {}
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
DECLARE_REF(Element);
|
||||
class Layout {
|
||||
public:
|
||||
Layout(PElement element);
|
||||
virtual ~Layout();
|
||||
virtual void apply() = 0;
|
||||
|
||||
protected:
|
||||
PElement element;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,58 +0,0 @@
|
||||
#include "RenderHierarchy.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
void AddElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements) {
|
||||
auto parentIt = elements.find([this](RenderElement e) { return e.parent == parent; });
|
||||
parentIt->referencedElement->addChild(addedElement);
|
||||
addedElement->setParent(parentIt->referencedElement);
|
||||
|
||||
elements.emplace(parentIt->referencedElement, addedElement);
|
||||
}
|
||||
|
||||
void RemoveElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements) {
|
||||
auto elementIt = elements.find([this](RenderElement e) { return e.referencedElement == element; });
|
||||
if (!removeChildren) {
|
||||
for (auto child : elementIt->referencedElement->getChildren()) {
|
||||
child->setParent(elementIt->referencedElement->getParent());
|
||||
}
|
||||
}
|
||||
elementIt->referencedElement->setParent(nullptr);
|
||||
|
||||
elements.remove(elementIt);
|
||||
}
|
||||
|
||||
RenderHierarchy::RenderHierarchy() {}
|
||||
|
||||
RenderHierarchy::~RenderHierarchy() {}
|
||||
|
||||
void RenderHierarchy::addElement(PElement addedElement) {
|
||||
std::scoped_lock lock(updateLock);
|
||||
updates.add(new AddElementRenderHierarchyUpdate{addedElement.getHandle(), addedElement->getParent().getHandle()});
|
||||
}
|
||||
|
||||
void RenderHierarchy::removeElement(PElement elementToRemove) {
|
||||
std::scoped_lock lock(updateLock);
|
||||
updates.add(new RemoveElementRenderHierarchyUpdate{
|
||||
elementToRemove.getHandle(),
|
||||
});
|
||||
}
|
||||
|
||||
void RenderHierarchy::moveElement(PElement elementToMove, PElement newParent) {
|
||||
std::scoped_lock lock(updateLock);
|
||||
updates.add(new AddElementRenderHierarchyUpdate{elementToMove.getHandle(), newParent.getHandle()});
|
||||
updates.add(new RemoveElementRenderHierarchyUpdate{elementToMove.getHandle()});
|
||||
}
|
||||
|
||||
void RenderHierarchy::updateHierarchy() {
|
||||
List<RenderHierarchyUpdate*> localUpdates;
|
||||
{ // make a local copy of the updates so we dont hold the lock for too long
|
||||
std::scoped_lock lock(updateLock);
|
||||
localUpdates = updates;
|
||||
updates.clear();
|
||||
}
|
||||
for (auto update : localUpdates) {
|
||||
update->apply(drawElements);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
#pragma once
|
||||
#include "Containers/List.h"
|
||||
#include "Elements/Element.h"
|
||||
#include "Graphics/Resources.h"
|
||||
#include "Graphics/Texture.h"
|
||||
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
struct RenderElementStyle {
|
||||
Vector position = Vector(0, 0, 0);
|
||||
uint32 backgroundImageIndex = UINT32_MAX;
|
||||
Vector backgroundColor = Vector(1, 1, 1);
|
||||
float opacity = 1.0f;
|
||||
// Vector4 borderBottomColor = Vector4(1, 1, 1, 1);
|
||||
// Vector4 borderLeftColor = Vector4(1, 1, 1, 1);
|
||||
// Vector4 borderRightColor = Vector4(1, 1, 1, 1);
|
||||
// Vector4 borderTopColor = Vector4(1, 1, 1, 1);
|
||||
// float borderBottomLeftRadius = 0;
|
||||
// float borderBottomRightRadius = 0;
|
||||
// float borderTopLeftRadius = 0;
|
||||
// float borderTopRightRadius = 0;
|
||||
Vector2 dimensions = Vector2(1, 1);
|
||||
};
|
||||
class RenderElement {
|
||||
public:
|
||||
RenderElement() = default;
|
||||
RenderElement(Element* parent, Element* referencedElement) : parent(parent), referencedElement(referencedElement) {}
|
||||
~RenderElement() = default;
|
||||
Element* parent;
|
||||
Element* referencedElement;
|
||||
};
|
||||
|
||||
struct RenderHierarchyUpdate {
|
||||
virtual void apply(Array<RenderElement>& elements) = 0;
|
||||
};
|
||||
|
||||
struct AddElementRenderHierarchyUpdate : public RenderHierarchyUpdate {
|
||||
Element* addedElement;
|
||||
Element* parent;
|
||||
AddElementRenderHierarchyUpdate(Element* addedElement, Element* parent) : addedElement(addedElement), parent(parent) {}
|
||||
virtual void apply(Array<RenderElement>& elements) override;
|
||||
};
|
||||
|
||||
struct RemoveElementRenderHierarchyUpdate : public RenderHierarchyUpdate {
|
||||
Element* element;
|
||||
bool removeChildren;
|
||||
RemoveElementRenderHierarchyUpdate(Element* elementToRemove, bool removeChildren = false)
|
||||
: element(elementToRemove), removeChildren(removeChildren) {}
|
||||
virtual void apply(Array<RenderElement>& elements) override;
|
||||
};
|
||||
class RenderHierarchy {
|
||||
public:
|
||||
RenderHierarchy();
|
||||
~RenderHierarchy();
|
||||
// logic thread interface, queue hierarchy changes
|
||||
void addElement(PElement addedElement);
|
||||
void removeElement(PElement elementToRemove);
|
||||
void moveElement(PElement elementToMove, PElement newParent);
|
||||
|
||||
// render thread interface, apply changes
|
||||
void updateHierarchy();
|
||||
|
||||
private:
|
||||
static_assert(std::is_trivially_copyable_v<RenderElement>);
|
||||
// List of all drawable elements in draw order
|
||||
Array<RenderElement> drawElements;
|
||||
// Shader data used for styling elements
|
||||
Array<RenderElementStyle> elementStyles;
|
||||
Array<Gfx::PTexture> usedTextures;
|
||||
|
||||
List<RenderHierarchyUpdate*> updates;
|
||||
std::mutex updateLock;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,4 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Class.h
|
||||
Style.h)
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Style.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
template <typename C>
|
||||
concept StyleClass = requires(C c, Style& s) { c.apply(s); };
|
||||
|
||||
template <uint32 w, DimensionType widthType> struct WidthClass {
|
||||
static void apply(Style& s) {
|
||||
s.width = w;
|
||||
s.widthType = widthType;
|
||||
}
|
||||
};
|
||||
using W_Full = WidthClass<100, DimensionType::Percent>;
|
||||
using W_1 = WidthClass<2, DimensionType::Pixel>;
|
||||
|
||||
template <DisplayType displayType> struct DisplayClass {
|
||||
static void apply(Style& s) { s.displayType = displayType; }
|
||||
};
|
||||
using Hidden = DisplayClass<DisplayType::Hidden>;
|
||||
using Block = DisplayClass<DisplayType::Block>;
|
||||
using Flex = DisplayClass<DisplayType::Flex>;
|
||||
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "Math/Vector.h"
|
||||
#include "Asset/FontAsset.h"
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
enum class DimensionType {
|
||||
Pixel,
|
||||
Percent, // EM, PEM, etc...
|
||||
};
|
||||
enum class PositionType {
|
||||
Relative,
|
||||
Static,
|
||||
Absolute,
|
||||
Sticky,
|
||||
};
|
||||
enum class DisplayType {
|
||||
Inline,
|
||||
Hidden,
|
||||
Block,
|
||||
Flex,
|
||||
Grid,
|
||||
};
|
||||
struct Style {
|
||||
DimensionType widthType = DimensionType::Pixel;
|
||||
uint32 width = 0;
|
||||
DimensionType heightType = DimensionType::Pixel;
|
||||
uint32 height = 0;
|
||||
uint32 z = 0;
|
||||
Vector backgroundColor = Vector(1, 1, 1);
|
||||
DisplayType displayType = DisplayType::Inline;
|
||||
PositionType position = PositionType::Relative;
|
||||
PFontAsset fontFamily;
|
||||
uint32 lineHeight = 12;
|
||||
uint32 fontSize = 12;
|
||||
uint32 fontWeight = 0;
|
||||
uint32 paddingTop = 0;
|
||||
uint32 paddingBottom = 0;
|
||||
uint32 paddingLeft = 0;
|
||||
uint32 paddingRight = 0;
|
||||
uint32 marginTop = 0;
|
||||
uint32 marginBottom = 0;
|
||||
uint32 marginLeft = 0;
|
||||
uint32 marginRight = 0;
|
||||
uint32 gap = 0;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "System.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Elements/Panel.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
System::System() {}
|
||||
|
||||
System::~System() {}
|
||||
|
||||
void System::update() {}
|
||||
|
||||
void System::updateViewport(Gfx::PViewport) {
|
||||
// TODO set viewport FoV to 0
|
||||
}
|
||||
|
||||
Component::Camera System::getVirtualCamera() const { return virtualCamera; }
|
||||
+21
-15
@@ -1,26 +1,32 @@
|
||||
#pragma once
|
||||
#include "Graphics/RenderPass/TextPass.h"
|
||||
#include "Graphics/RenderPass/UIPass.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "RenderHierarchy.h"
|
||||
|
||||
#include "Element.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
DECLARE_REF(Panel)
|
||||
struct RenderElement {
|
||||
// position relative to target viewport in pixels
|
||||
UVector2 position;
|
||||
// size relative to target viewport in pixels
|
||||
UVector2 size;
|
||||
// background color of area
|
||||
Vector backgroundColor;
|
||||
// text to render
|
||||
std::string text;
|
||||
// font size in pixels
|
||||
uint32 fontSize;
|
||||
// font family
|
||||
PFontAsset fontFamily;
|
||||
};
|
||||
class System {
|
||||
public:
|
||||
System();
|
||||
virtual ~System();
|
||||
void update();
|
||||
void updateViewport(Gfx::PViewport viewport);
|
||||
Component::Camera getVirtualCamera() const;
|
||||
System(OElement rootElement) : rootElement(std::move(rootElement)) {}
|
||||
~System();
|
||||
Array<RenderElement> render(UVector2 viewport) {
|
||||
}
|
||||
|
||||
private:
|
||||
Component::Camera virtualCamera;
|
||||
PPanel rootPanel;
|
||||
RenderHierarchy hierarchy;
|
||||
OElement rootElement;
|
||||
};
|
||||
DEFINE_REF(System)
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
} // namespace Seele
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "VerticalLayout.h"
|
||||
#include "Elements/Element.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
VerticalLayout::VerticalLayout(PElement element) : Layout(element) {}
|
||||
|
||||
VerticalLayout::~VerticalLayout() {}
|
||||
|
||||
void VerticalLayout::apply() {
|
||||
Array<PElement> children = element->getChildren();
|
||||
const Rect parent = element->getBoundingBox();
|
||||
float xOffset = parent.offset.x;
|
||||
float yOffset = parent.offset.y;
|
||||
float xSize = parent.size.x;
|
||||
float ySize = parent.size.y / children.size();
|
||||
for (uint32 index = 0; index < children.size(); ++index) {
|
||||
Rect& child = children[index]->getBoundingBox();
|
||||
child.offset.x = xOffset;
|
||||
child.offset.y = yOffset + (index * ySize);
|
||||
child.size.x = xSize;
|
||||
child.size.y = ySize;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include "Layout.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
class VerticalLayout : Layout {
|
||||
public:
|
||||
VerticalLayout(PElement element);
|
||||
~VerticalLayout();
|
||||
virtual void apply() override;
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user