Major cleanup.
Moved to namespace Cleanup includes
This commit is contained in:
@@ -1,84 +1,88 @@
|
||||
#pragma once
|
||||
#include "../Core/Maths.h"
|
||||
#include <map>
|
||||
enum class PropType
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
HEIGHT, MAX_HEIGHT, MIN_HEIGHT, WIDTH, MAX_WIDTH, MIN_WIDTH,
|
||||
LAYOUT_DIRECTION, JUSTIFY_CONTENT,
|
||||
FLEX_BASIS, FLEX_GROW, FLEX_SHRINK,FLEX_WRAP, FLEX_DIRECTION,
|
||||
ASPECT_RATIO,
|
||||
ALIGN_ITEMS, SELF_ALIGN, ALIGN_CONTENT,
|
||||
POSITION,
|
||||
LEFT, RIGHT, TOP, BOTTOM,
|
||||
MARGIN, MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM,
|
||||
PADDING, PADDING_LEFT, PADDING_RIGHT, PADDING_TOP, PADDING_BOTTOM,
|
||||
BORDER, BORDER_LEFT, BORDER_RIGHT, BORDER_TOP, BORDER_BOTTOM,
|
||||
BORDER_RADIUS, BORDER_RADIUS_LEFT, BORDER_RADIUS_RIGHT, BORDER_RADIUS_TOP, BORDER_RADIUS_BOTTOM,
|
||||
BACKGROUND_COLOR, COLOR,
|
||||
};
|
||||
|
||||
enum class PropValueType
|
||||
{
|
||||
PIXEL, PERCENT, AUTO, COLOR, ENUM
|
||||
};
|
||||
union Value
|
||||
{
|
||||
float Number;
|
||||
Color Color;
|
||||
int Enum;
|
||||
};
|
||||
struct PropValue
|
||||
{
|
||||
PropValueType type;
|
||||
Value value;
|
||||
};
|
||||
|
||||
class StyleGroup
|
||||
{
|
||||
public:
|
||||
std::map<PropType, PropValue> Props;
|
||||
|
||||
StyleGroup()
|
||||
enum class PropType
|
||||
{
|
||||
this->Props = std::map<PropType, PropValue>();
|
||||
}
|
||||
HEIGHT, MAX_HEIGHT, MIN_HEIGHT, WIDTH, MAX_WIDTH, MIN_WIDTH,
|
||||
LAYOUT_DIRECTION, JUSTIFY_CONTENT,
|
||||
FLEX_BASIS, FLEX_GROW, FLEX_SHRINK, FLEX_WRAP, FLEX_DIRECTION,
|
||||
ASPECT_RATIO,
|
||||
ALIGN_ITEMS, SELF_ALIGN, ALIGN_CONTENT,
|
||||
POSITION,
|
||||
LEFT, RIGHT, TOP, BOTTOM,
|
||||
MARGIN, MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM,
|
||||
PADDING, PADDING_LEFT, PADDING_RIGHT, PADDING_TOP, PADDING_BOTTOM,
|
||||
BORDER, BORDER_LEFT, BORDER_RIGHT, BORDER_TOP, BORDER_BOTTOM,
|
||||
BORDER_RADIUS, BORDER_RADIUS_LEFT, BORDER_RADIUS_RIGHT, BORDER_RADIUS_TOP, BORDER_RADIUS_BOTTOM,
|
||||
BACKGROUND_COLOR, COLOR,
|
||||
};
|
||||
|
||||
void SetProp(PropType type, PropValue prop)
|
||||
enum class PropValueType
|
||||
{
|
||||
Props[type] = prop;
|
||||
}
|
||||
|
||||
PropValue& GetProp(PropType type)
|
||||
PIXEL, PERCENT, AUTO, COLOR, ENUM
|
||||
};
|
||||
union Value
|
||||
{
|
||||
if (Props.find(type) != Props.end())
|
||||
return Props[type];
|
||||
|
||||
return PropValue();
|
||||
}
|
||||
|
||||
bool HasProp(PropType type)
|
||||
float Number;
|
||||
Color Color;
|
||||
int Enum;
|
||||
};
|
||||
struct PropValue
|
||||
{
|
||||
return Props.find(type) != Props.end();
|
||||
}
|
||||
PropValueType type;
|
||||
Value value;
|
||||
};
|
||||
|
||||
std::map<PropType, PropValue> GetProps()
|
||||
class StyleGroup
|
||||
{
|
||||
return Props;
|
||||
}
|
||||
public:
|
||||
std::map<PropType, PropValue> Props;
|
||||
|
||||
StyleGroup operator+(StyleGroup other)
|
||||
{
|
||||
for (auto p : other.Props)
|
||||
StyleGroup()
|
||||
{
|
||||
this->Props[p.first] = p.second;
|
||||
this->Props = std::map<PropType, PropValue>();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
void SetProp(PropType type, PropValue prop)
|
||||
{
|
||||
Props[type] = prop;
|
||||
}
|
||||
|
||||
PropValue& GetProp(PropType type)
|
||||
{
|
||||
if (Props.find(type) != Props.end())
|
||||
return Props[type];
|
||||
|
||||
return PropValue();
|
||||
}
|
||||
|
||||
bool HasProp(PropType type)
|
||||
{
|
||||
return Props.find(type) != Props.end();
|
||||
}
|
||||
|
||||
std::map<PropType, PropValue> GetProps()
|
||||
{
|
||||
return Props;
|
||||
}
|
||||
|
||||
StyleGroup operator+(StyleGroup other)
|
||||
{
|
||||
for (auto p : other.Props)
|
||||
{
|
||||
this->Props[p.first] = p.second;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Style
|
||||
{
|
||||
class Style
|
||||
{
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,52 +2,53 @@
|
||||
#include <regex>
|
||||
#include <src/Vendors/pugixml/pugixml.hpp>
|
||||
|
||||
PropValue StyleSheetParser::ParsePropType(const std::string& str, PropType type)
|
||||
namespace Nuake
|
||||
{
|
||||
switch (type)
|
||||
PropValue StyleSheetParser::ParsePropType(const std::string& str, PropType type)
|
||||
{
|
||||
case PropType::HEIGHT: case PropType::MIN_HEIGHT: case PropType::MAX_HEIGHT:
|
||||
case PropType::WIDTH: case PropType::MIN_WIDTH: case PropType::MAX_WIDTH:
|
||||
case PropType::LEFT: case PropType::RIGHT: case PropType::TOP: case PropType::BOTTOM:
|
||||
case PropType::MARGIN_LEFT: case PropType::MARGIN_RIGHT: case PropType::MARGIN_TOP: case PropType::MARGIN_BOTTOM:
|
||||
case PropType::PADDING_LEFT: case PropType::PADDING_RIGHT: case PropType::PADDING_TOP: case PropType::PADDING_BOTTOM:
|
||||
case PropType::BORDER_LEFT: case PropType::BORDER_RIGHT: case PropType::BORDER_TOP: case PropType::BORDER_BOTTOM:
|
||||
{
|
||||
std::regex only_number("[0-9]+");
|
||||
std::regex not_number("[^0-9]+");
|
||||
// is percentage
|
||||
std::smatch match_value;
|
||||
if (std::regex_search(str.begin(), str.end(), match_value, only_number))
|
||||
switch (type)
|
||||
{
|
||||
std::smatch match_type;
|
||||
if (std::regex_search(str.begin(), str.end(), match_type, not_number))
|
||||
case PropType::HEIGHT: case PropType::MIN_HEIGHT: case PropType::MAX_HEIGHT:
|
||||
case PropType::WIDTH: case PropType::MIN_WIDTH: case PropType::MAX_WIDTH:
|
||||
case PropType::LEFT: case PropType::RIGHT: case PropType::TOP: case PropType::BOTTOM:
|
||||
case PropType::MARGIN_LEFT: case PropType::MARGIN_RIGHT: case PropType::MARGIN_TOP: case PropType::MARGIN_BOTTOM:
|
||||
case PropType::PADDING_LEFT: case PropType::PADDING_RIGHT: case PropType::PADDING_TOP: case PropType::PADDING_BOTTOM:
|
||||
case PropType::BORDER_LEFT: case PropType::BORDER_RIGHT: case PropType::BORDER_TOP: case PropType::BORDER_BOTTOM:
|
||||
{
|
||||
std::regex only_number("[0-9]+");
|
||||
std::regex not_number("[^0-9]+");
|
||||
// is percentage
|
||||
std::smatch match_value;
|
||||
if (std::regex_search(str.begin(), str.end(), match_value, only_number))
|
||||
{
|
||||
float value = std::stof(match_value[0]);
|
||||
if (match_type[0] == "%")
|
||||
std::smatch match_type;
|
||||
if (std::regex_search(str.begin(), str.end(), match_type, not_number))
|
||||
{
|
||||
PropValue returnValue = PropValue{
|
||||
PropValueType::PERCENT,
|
||||
{0}
|
||||
};
|
||||
returnValue.value.Number = value;
|
||||
return returnValue;
|
||||
}
|
||||
else if (match_type[0] == "px")
|
||||
{
|
||||
PropValue returnValue = PropValue{
|
||||
PropValueType::PIXEL,
|
||||
{0}
|
||||
};
|
||||
returnValue.value.Number = value;
|
||||
return returnValue;
|
||||
float value = std::stof(match_value[0]);
|
||||
if (match_type[0] == "%")
|
||||
{
|
||||
PropValue returnValue = PropValue{
|
||||
PropValueType::PERCENT,
|
||||
{0}
|
||||
};
|
||||
returnValue.value.Number = value;
|
||||
return returnValue;
|
||||
}
|
||||
else if (match_type[0] == "px")
|
||||
{
|
||||
PropValue returnValue = PropValue {
|
||||
PropValueType::PIXEL,
|
||||
{0}
|
||||
};
|
||||
returnValue.value.Number = value;
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
return PropValue();
|
||||
}
|
||||
|
||||
|
||||
return PropValue();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
#include <string>
|
||||
#include "Style.h"
|
||||
|
||||
class StyleSheetParser
|
||||
namespace Nuake
|
||||
{
|
||||
class StyleSheetParser
|
||||
{
|
||||
|
||||
public:
|
||||
static PropValue ParsePropType(const std::string& str, PropType type);
|
||||
};
|
||||
public:
|
||||
static PropValue ParsePropType(const std::string& str, PropType type);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
#include "Stylesheet.h"
|
||||
|
||||
namespace UI
|
||||
{
|
||||
|
||||
|
||||
|
||||
Ref<StyleSheet> StyleSheet::New(const std::string& path)
|
||||
{
|
||||
|
||||
|
||||
return CreateRef<StyleSheet>(path);
|
||||
|
||||
namespace Nuake {
|
||||
namespace UI {
|
||||
Ref<StyleSheet> StyleSheet::New(const std::string& path)
|
||||
{
|
||||
return CreateRef<StyleSheet>(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,252 +9,256 @@
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <map>
|
||||
namespace UI
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class StyleSheet
|
||||
namespace UI
|
||||
{
|
||||
private:
|
||||
KatanaOutput* Data;
|
||||
|
||||
std::map<std::string, Ref<StyleGroup>> Styles;
|
||||
public:
|
||||
std::string Path;
|
||||
static Ref<StyleSheet> New(const std::string& path);
|
||||
std::vector<std::string> Split(std::string const& str, const char delim)
|
||||
class StyleSheet
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
size_t start;
|
||||
size_t end = 0;
|
||||
private:
|
||||
KatanaOutput* Data;
|
||||
|
||||
while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
|
||||
std::map<std::string, Ref<StyleGroup>> Styles;
|
||||
public:
|
||||
std::string Path;
|
||||
static Ref<StyleSheet> New(const std::string& path);
|
||||
std::vector<std::string> Split(std::string const& str, const char delim)
|
||||
{
|
||||
end = str.find(delim, start);
|
||||
result.push_back(str.substr(start, end - start));
|
||||
}
|
||||
std::vector<std::string> result;
|
||||
size_t start;
|
||||
size_t end = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
void AddStyleGroup(std::string selector, Ref<StyleGroup> group)
|
||||
{
|
||||
Styles[selector] = group;
|
||||
}
|
||||
|
||||
bool HasStyleGroup(const std::string& group)
|
||||
{
|
||||
return Styles.find(group) != Styles.end();
|
||||
}
|
||||
|
||||
Ref<StyleGroup> GetStyleGroup(const std::string group)
|
||||
{
|
||||
if (!HasStyleGroup(group))
|
||||
return nullptr;
|
||||
|
||||
return Styles[group];
|
||||
}
|
||||
|
||||
StyleSheet(const std::string& path)
|
||||
{
|
||||
this->Path = path;
|
||||
ParseSheet();
|
||||
}
|
||||
|
||||
~StyleSheet()
|
||||
{
|
||||
katana_destroy_output(Data);
|
||||
}
|
||||
|
||||
bool ParseRule(KatanaRule* rule)
|
||||
{
|
||||
if (rule->type == KatanaRuleStyle)
|
||||
{
|
||||
Ref<StyleGroup> styleGroup = CreateRef<StyleGroup>();
|
||||
|
||||
// Selectors
|
||||
KatanaStyleRule* stylerule = (KatanaStyleRule*)rule;
|
||||
for (int j = 0; j < stylerule->selectors->length; j++)
|
||||
while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
|
||||
{
|
||||
KatanaSelector* selector = (KatanaSelector*)stylerule->selectors->data[j];
|
||||
std::string name = selector->data->value;
|
||||
|
||||
AddStyleGroup(name, styleGroup);
|
||||
end = str.find(delim, start);
|
||||
result.push_back(str.substr(start, end - start));
|
||||
}
|
||||
|
||||
// Declarations
|
||||
for (int k = 0; k < stylerule->declarations->length; k++)
|
||||
return result;
|
||||
}
|
||||
void AddStyleGroup(std::string selector, Ref<StyleGroup> group)
|
||||
{
|
||||
Styles[selector] = group;
|
||||
}
|
||||
|
||||
bool HasStyleGroup(const std::string& group)
|
||||
{
|
||||
return Styles.find(group) != Styles.end();
|
||||
}
|
||||
|
||||
Ref<StyleGroup> GetStyleGroup(const std::string group)
|
||||
{
|
||||
if (!HasStyleGroup(group))
|
||||
return nullptr;
|
||||
|
||||
return Styles[group];
|
||||
}
|
||||
|
||||
StyleSheet(const std::string& path)
|
||||
{
|
||||
this->Path = path;
|
||||
ParseSheet();
|
||||
}
|
||||
|
||||
~StyleSheet()
|
||||
{
|
||||
katana_destroy_output(Data);
|
||||
}
|
||||
|
||||
bool ParseRule(KatanaRule* rule)
|
||||
{
|
||||
if (rule->type == KatanaRuleStyle)
|
||||
{
|
||||
KatanaDeclaration* declaration = (KatanaDeclaration*)(stylerule->declarations->data[k]);
|
||||
std::string value = declaration->raw;
|
||||
std::string name = declaration->property;
|
||||
PropType type;
|
||||
Ref<StyleGroup> styleGroup = CreateRef<StyleGroup>();
|
||||
|
||||
if (name == "height") type = PropType::HEIGHT;
|
||||
if (name == "width") type = PropType::WIDTH;
|
||||
if (name == "left") type = PropType::LEFT;
|
||||
if (name == "right") type = PropType::RIGHT;
|
||||
if (name == "top") type = PropType::TOP;
|
||||
if (name == "bottom") type = PropType::BOTTOM;
|
||||
if (name == "margin")
|
||||
// Selectors
|
||||
KatanaStyleRule* stylerule = (KatanaStyleRule*)rule;
|
||||
for (int j = 0; j < stylerule->selectors->length; j++)
|
||||
{
|
||||
std::regex regex("[0-9]+[^ ]+");
|
||||
std::smatch match_value;
|
||||
Layout::LayoutVec4 result;
|
||||
KatanaSelector* selector = (KatanaSelector*)stylerule->selectors->data[j];
|
||||
std::string name = selector->data->value;
|
||||
|
||||
std::vector<std::string> splits = Split(value, ' ');
|
||||
int idx = 0;
|
||||
for (auto& s : splits)
|
||||
AddStyleGroup(name, styleGroup);
|
||||
}
|
||||
|
||||
// Declarations
|
||||
for (int k = 0; k < stylerule->declarations->length; k++)
|
||||
{
|
||||
KatanaDeclaration* declaration = (KatanaDeclaration*)(stylerule->declarations->data[k]);
|
||||
std::string value = declaration->raw;
|
||||
std::string name = declaration->property;
|
||||
PropType type;
|
||||
|
||||
if (name == "height") type = PropType::HEIGHT;
|
||||
if (name == "width") type = PropType::WIDTH;
|
||||
if (name == "left") type = PropType::LEFT;
|
||||
if (name == "right") type = PropType::RIGHT;
|
||||
if (name == "top") type = PropType::TOP;
|
||||
if (name == "bottom") type = PropType::BOTTOM;
|
||||
if (name == "margin")
|
||||
{
|
||||
if (idx == 0)
|
||||
std::regex regex("[0-9]+[^ ]+");
|
||||
std::smatch match_value;
|
||||
Layout::LayoutVec4 result;
|
||||
|
||||
std::vector<std::string> splits = Split(value, ' ');
|
||||
int idx = 0;
|
||||
for (auto& s : splits)
|
||||
{
|
||||
type = PropType::MARGIN_LEFT;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
if (idx == 0)
|
||||
{
|
||||
type = PropType::MARGIN_LEFT;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
else if (idx == 1)
|
||||
{
|
||||
type = PropType::MARGIN_RIGHT;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
else if (idx == 2)
|
||||
{
|
||||
type = PropType::MARGIN_TOP;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
else if (idx == 3)
|
||||
{
|
||||
type = PropType::MARGIN_BOTTOM;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
else if (idx == 1)
|
||||
{
|
||||
type = PropType::MARGIN_RIGHT;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
else if (idx == 2)
|
||||
{
|
||||
type = PropType::MARGIN_TOP;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
else if (idx == 3)
|
||||
{
|
||||
type = PropType::MARGIN_BOTTOM;
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type));
|
||||
}
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (name == "flex-direction")
|
||||
{
|
||||
type = PropType::FLEX_DIRECTION;
|
||||
Value propValue{};
|
||||
|
||||
if (value == "row")
|
||||
propValue.Enum = (int)Layout::FlexDirection::ROW;
|
||||
if (value == "row-reversed")
|
||||
propValue.Enum = (int)Layout::FlexDirection::ROW_REVERSED;
|
||||
if (value == "column")
|
||||
propValue.Enum = (int)Layout::FlexDirection::COLUMN;
|
||||
if (value == "column-reversed")
|
||||
propValue.Enum = (int)Layout::FlexDirection::COLUMN_REVERSED;
|
||||
if (name == "flex-direction")
|
||||
{
|
||||
type = PropType::FLEX_DIRECTION;
|
||||
Value propValue{};
|
||||
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "justify-content")
|
||||
{
|
||||
type = PropType::JUSTIFY_CONTENT;
|
||||
Value propValue{};
|
||||
if (value == "flex-start")
|
||||
propValue.Enum = (int)Layout::JustifyContent::FLEX_START;
|
||||
if (value == "flex-end")
|
||||
propValue.Enum = (int)Layout::JustifyContent::FLEX_END;
|
||||
if (value == "center")
|
||||
propValue.Enum = (int)Layout::JustifyContent::CENTER;
|
||||
if (value == "space-between")
|
||||
propValue.Enum = (int)Layout::JustifyContent::SPACE_BETWEEN;
|
||||
if (value == "space-around")
|
||||
propValue.Enum = (int)Layout::JustifyContent::SPACE_AROUND;
|
||||
if (value == "space-evenly")
|
||||
propValue.Enum = (int)Layout::JustifyContent::SPACE_EVENLY;
|
||||
if (value == "row")
|
||||
propValue.Enum = (int)Layout::FlexDirection::ROW;
|
||||
if (value == "row-reversed")
|
||||
propValue.Enum = (int)Layout::FlexDirection::ROW_REVERSED;
|
||||
if (value == "column")
|
||||
propValue.Enum = (int)Layout::FlexDirection::COLUMN;
|
||||
if (value == "column-reversed")
|
||||
propValue.Enum = (int)Layout::FlexDirection::COLUMN_REVERSED;
|
||||
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "flex-wrap")
|
||||
{
|
||||
type = PropType::FLEX_WRAP;
|
||||
Value propValue{};
|
||||
if (value == "no-wrap")
|
||||
propValue.Enum = (int)Layout::FlexWrap::NO_WRAP;
|
||||
if (value == "wrap")
|
||||
propValue.Enum = (int)Layout::FlexWrap::WRAP;
|
||||
if (value == "wrap-reversed")
|
||||
propValue.Enum = (int)Layout::FlexWrap::WRAP_REVERSED;
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "justify-content")
|
||||
{
|
||||
type = PropType::JUSTIFY_CONTENT;
|
||||
Value propValue{};
|
||||
if (value == "flex-start")
|
||||
propValue.Enum = (int)Layout::JustifyContent::FLEX_START;
|
||||
if (value == "flex-end")
|
||||
propValue.Enum = (int)Layout::JustifyContent::FLEX_END;
|
||||
if (value == "center")
|
||||
propValue.Enum = (int)Layout::JustifyContent::CENTER;
|
||||
if (value == "space-between")
|
||||
propValue.Enum = (int)Layout::JustifyContent::SPACE_BETWEEN;
|
||||
if (value == "space-around")
|
||||
propValue.Enum = (int)Layout::JustifyContent::SPACE_AROUND;
|
||||
if (value == "space-evenly")
|
||||
propValue.Enum = (int)Layout::JustifyContent::SPACE_EVENLY;
|
||||
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "align-self" || name == "align-items")
|
||||
{
|
||||
if (name == "align-self")
|
||||
type = PropType::SELF_ALIGN;
|
||||
else
|
||||
type = PropType::ALIGN_ITEMS;
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "flex-wrap")
|
||||
{
|
||||
type = PropType::FLEX_WRAP;
|
||||
Value propValue{};
|
||||
if (value == "no-wrap")
|
||||
propValue.Enum = (int)Layout::FlexWrap::NO_WRAP;
|
||||
if (value == "wrap")
|
||||
propValue.Enum = (int)Layout::FlexWrap::WRAP;
|
||||
if (value == "wrap-reversed")
|
||||
propValue.Enum = (int)Layout::FlexWrap::WRAP_REVERSED;
|
||||
|
||||
Value propValue{};
|
||||
if (value == "stretch")
|
||||
propValue.Enum = (int)Layout::AlignItems::STRETCH;
|
||||
if (value == "flex-start")
|
||||
propValue.Enum = (int)Layout::AlignItems::FLEX_START;
|
||||
if (value == "flex-end")
|
||||
propValue.Enum = (int)Layout::AlignItems::FLEX_END;
|
||||
if (value == "center")
|
||||
propValue.Enum = (int)Layout::AlignItems::CENTER;
|
||||
if (value == "baseline")
|
||||
propValue.Enum = (int)Layout::AlignItems::BASELINE;
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "align-self" || name == "align-items")
|
||||
{
|
||||
if (name == "align-self")
|
||||
type = PropType::SELF_ALIGN;
|
||||
else
|
||||
type = PropType::ALIGN_ITEMS;
|
||||
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "align-content")
|
||||
{
|
||||
type = PropType::ALIGN_CONTENT;
|
||||
Value propValue{};
|
||||
if (value == "stretch")
|
||||
propValue.Enum = (int)Layout::AlignItems::STRETCH;
|
||||
if (value == "flex-start")
|
||||
propValue.Enum = (int)Layout::AlignItems::FLEX_START;
|
||||
if (value == "flex-end")
|
||||
propValue.Enum = (int)Layout::AlignItems::FLEX_END;
|
||||
if (value == "center")
|
||||
propValue.Enum = (int)Layout::AlignItems::CENTER;
|
||||
if (value == "baseline")
|
||||
propValue.Enum = (int)Layout::AlignItems::BASELINE;
|
||||
|
||||
Value propValue{};
|
||||
if (value == "stretch")
|
||||
propValue.Enum = (int)Layout::AlignContent::STRETCH;
|
||||
if (value == "flex-start")
|
||||
propValue.Enum = (int)Layout::AlignContent::FLEX_START;
|
||||
if (value == "flex-end")
|
||||
propValue.Enum = (int)Layout::AlignContent::FLEX_END;
|
||||
if (value == "center")
|
||||
propValue.Enum = (int)Layout::AlignContent::CENTER;
|
||||
if (value == "space-between")
|
||||
propValue.Enum = (int)Layout::AlignContent::SPACE_BETWEEN;
|
||||
if (value == "space-around")
|
||||
propValue.Enum = (int)Layout::AlignContent::SPACE_AROUND;
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "align-content")
|
||||
{
|
||||
type = PropType::ALIGN_CONTENT;
|
||||
|
||||
Value propValue{};
|
||||
if (value == "stretch")
|
||||
propValue.Enum = (int)Layout::AlignContent::STRETCH;
|
||||
if (value == "flex-start")
|
||||
propValue.Enum = (int)Layout::AlignContent::FLEX_START;
|
||||
if (value == "flex-end")
|
||||
propValue.Enum = (int)Layout::AlignContent::FLEX_END;
|
||||
if (value == "center")
|
||||
propValue.Enum = (int)Layout::AlignContent::CENTER;
|
||||
if (value == "space-between")
|
||||
propValue.Enum = (int)Layout::AlignContent::SPACE_BETWEEN;
|
||||
if (value == "space-around")
|
||||
propValue.Enum = (int)Layout::AlignContent::SPACE_AROUND;
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
if (name == "position")
|
||||
{
|
||||
type = PropType::POSITION;
|
||||
Value propValue{};
|
||||
if (value == "relative")
|
||||
propValue.Enum = (int)Layout::PositionType::RELATIVE;
|
||||
if (value == "absolute")
|
||||
propValue.Enum = (int)Layout::PositionType::ABSOLUTE;
|
||||
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(value, type));
|
||||
Logger::Log(declaration->property);
|
||||
}
|
||||
if (name == "position")
|
||||
{
|
||||
type = PropType::POSITION;
|
||||
Value propValue{};
|
||||
if (value == "relative")
|
||||
propValue.Enum = (int)Layout::PositionType::RELATIVE;
|
||||
if (value == "absolute")
|
||||
propValue.Enum = (int)Layout::PositionType::ABSOLUTE;
|
||||
|
||||
styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue });
|
||||
continue;
|
||||
}
|
||||
styleGroup->SetProp(type, StyleSheetParser::ParsePropType(value, type));
|
||||
Logger::Log(declaration->property);
|
||||
Logger::Log(rule->name);
|
||||
}
|
||||
Logger::Log(rule->name);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ParseSheet()
|
||||
{
|
||||
std::string content = FileSystem::ReadFile(this->Path);
|
||||
Data = katana_parse(content.c_str(), content.length(), KatanaParserModeStylesheet);
|
||||
for (int i = 0; i < Data->stylesheet->rules.length; i++)
|
||||
bool ParseSheet()
|
||||
{
|
||||
KatanaRule* rule = (KatanaRule*)Data->stylesheet->rules.data[i];
|
||||
ParseRule(rule);
|
||||
std::string content = FileSystem::ReadFile(this->Path);
|
||||
Data = katana_parse(content.c_str(), content.length(), KatanaParserModeStylesheet);
|
||||
for (int i = 0; i < Data->stylesheet->rules.length; i++)
|
||||
{
|
||||
KatanaRule* rule = (KatanaRule*)Data->stylesheet->rules.data[i];
|
||||
ParseRule(rule);
|
||||
}
|
||||
|
||||
if (Data->errors.length > 0)
|
||||
{
|
||||
KatanaArray errors = Data->errors;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Data->errors.length > 0)
|
||||
{
|
||||
KatanaArray errors = Data->errors;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user