Adding basic memory resource
This commit is contained in:
@@ -31,10 +31,10 @@ class Element {
|
||||
// calculates the relative positions of the child elements for the applied layout style
|
||||
virtual void layout(UVector2 parentSize) {
|
||||
if (style.maxWidthType == DimensionType::Auto) {
|
||||
maxDimensions.x = parentSize.x;
|
||||
maxDimensions.x = (float)parentSize.x;
|
||||
}
|
||||
if (style.maxHeightType == DimensionType::Auto) {
|
||||
maxDimensions.y = parentSize.y;
|
||||
maxDimensions.y = (float)parentSize.y;
|
||||
}
|
||||
if (style.widthType == DimensionType::Pixel) {
|
||||
dimensions.x = style.width;
|
||||
@@ -69,7 +69,7 @@ class Element {
|
||||
// create a new line in case the element doesnt fit on the current one anymore,
|
||||
// but keep in current line in case we are still at the start, as a new line wouldnt help here
|
||||
if (cursor.x + child->dimensions.x > maxDimensions.x - child->style.left && cursor.x != 0) {
|
||||
cursor.x = style.paddingLeft;
|
||||
cursor.x = (float)style.paddingLeft;
|
||||
cursor.y += lineHeight;
|
||||
lineHeight = 0;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class Element {
|
||||
if (child->style.position == PositionType::Static || child->style.position == PositionType::Relative) {
|
||||
// create a new line in case we are not already at one
|
||||
if (cursor.x != 0) {
|
||||
cursor.x = style.paddingLeft;
|
||||
cursor.x = (float)style.paddingLeft;
|
||||
cursor.y += lineHeight;
|
||||
}
|
||||
child->position.x = cursor.x + child->style.marginLeft;
|
||||
|
||||
@@ -13,7 +13,7 @@ template <StyleClass... classes> class Text : public Element {
|
||||
style.outerDisplay = OuterDisplayType::Inline;
|
||||
(classes::apply(style), ...);
|
||||
}
|
||||
virtual void layout(UVector2 parentSize) override {
|
||||
virtual void layout(UVector2) override {
|
||||
UVector2 cursor = UVector2(0);
|
||||
dimensions = style.fontFamily->shapeText(text, style.fontSize, glyphRenders);
|
||||
}
|
||||
|
||||
+10
-10
@@ -67,24 +67,24 @@ using BG_Red = BackgroundColorClass<Vector(1, 0, 0)>;
|
||||
|
||||
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct MarginClass {
|
||||
static void apply(UI::Style& s) {
|
||||
if (ml != -1)
|
||||
if constexpr (ml != -1)
|
||||
s.marginLeft = ml;
|
||||
if (mr != -1)
|
||||
if constexpr (mr != -1)
|
||||
s.marginRight = mr;
|
||||
if (mt != -1)
|
||||
if constexpr (mt != -1)
|
||||
s.marginTop = mt;
|
||||
if (mb != -1)
|
||||
if constexpr (mb != -1)
|
||||
s.marginBottom = mb;
|
||||
}
|
||||
};
|
||||
#define DECLARE_MARGIN_CLASSES(x) \
|
||||
using M_##x = MarginClass<x, x, x, x>; \
|
||||
using M_X##x = MarginClass<x, x, -1u, -1u>; \
|
||||
using M_Y##x = MarginClass<-1u, -1u, x, x>; \
|
||||
using M_L##x = MarginClass<x, -1u, -1u, -1u>; \
|
||||
using M_R##x = MarginClass<-1u, x, -1u, -1u>; \
|
||||
using M_T##x = MarginClass<-1u, -1u, x, -1u>; \
|
||||
using M_B##x = MarginClass<-1u, -1u, -1u, x>;
|
||||
using M_X##x = MarginClass<x, x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||
using M_Y##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, x>; \
|
||||
using M_L##x = MarginClass<x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||
using M_R##x = MarginClass<std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||
using M_T##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max()>; \
|
||||
using M_B##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x>;
|
||||
|
||||
DECLARE_MARGIN_CLASSES(0)
|
||||
DECLARE_MARGIN_CLASSES(1)
|
||||
|
||||
Reference in New Issue
Block a user