Skip to content

Commit

Permalink
simplify PropertyParseKeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Jan 20, 2024
1 parent d9b7f89 commit 0719128
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
2 changes: 2 additions & 0 deletions pkg/ant.rmlui/make.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local lm = require "luamake"

--lm.warnings = "error"
lm.cxx = "c++latest"

lm:source_set "yoga" {
rootdir = lm.AntDir .. "/3rd/yoga",
Expand Down Expand Up @@ -43,6 +44,7 @@ lm:lua_source "rmlui_css" {
includes = {
"src",
lm.AntDir .. "/3rd/glm",
lm.AntDir .. "/3rd/yoga",
lm.AntDir .. "/3rd/stylecache",
lm.AntDir .. "/3rd/bee.lua",
lm.AntDir .. "/clibs/luabind",
Expand Down
15 changes: 10 additions & 5 deletions pkg/ant.rmlui/src/css/EnumName.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ constexpr bool IsUpper(const char c) {
template <CssEnumNameStyle Style, auto E>
constexpr auto CssEnumNameRaw() {
constexpr auto rawname = EnumNameV<E>;
size_t i = 1;
size_t i = 0;
size_t sz = 0;
std::array<char, 32> name = {};
if (rawname[0] == '_') {
if constexpr (!std::is_scoped_enum_v<decltype(E)>) {
constexpr auto rawtypename = EnumTypeNameV<decltype(E)>;
static_assert(rawtypename == std::string_view { rawname.data(), rawtypename.size() });
i = rawtypename.size();
}
if (rawname[i] == '_') {
if constexpr (Style != CssEnumNameStyle::Camel) {
name[sz++] = '-';
}
name[sz++] = ToLower(rawname[1]);
i = 2;
name[sz++] = ToLower(rawname[++i]);
}
else {
name[sz++] = ToLower(rawname[0]);
name[sz++] = ToLower(rawname[i]);
}
++i;
if constexpr (Style == CssEnumNameStyle::Camel) {
for (; i < rawname.size(); ++i) {
name[sz++] = rawname[i];
Expand Down
19 changes: 10 additions & 9 deletions pkg/ant.rmlui/src/css/StyleSheetSpecification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <array>
#include <memory>
#include <optional>
#include <yoga/Yoga.h>

namespace Rml {

Expand Down Expand Up @@ -72,7 +73,7 @@ static constexpr PropertyIdSet InheritableProperties = (+[]{
return set;
})();
static_assert((InheritableProperties & LayoutProperties).empty());
static constexpr auto PropertyNames = MakeCssEnumNames<PropertyId>();
static constexpr auto PropertyNames = MakeCssEnumNames<PropertyId>();
static constexpr auto ShorthandNames = MakeCssEnumNames<ShorthandId>();

static constexpr auto PropertyDefinitions = MakeEnumArray<PropertyId, PropertyDefinition>({
Expand Down Expand Up @@ -301,13 +302,13 @@ static constexpr auto PropertyDefinitions = MakeEnumArray<PropertyId, PropertyDe

// flex layout
{ PropertyId::Display, {
PropertyParseKeyword<"flex", "none">,
PropertyParseKeyword<YGDisplay>,
}},
{ PropertyId::Overflow, {
PropertyParseKeyword<"visible", "hidden", "scroll">,
PropertyParseKeyword<YGOverflow>,
}},
{ PropertyId::Position, {
PropertyParseKeyword<"static", "relative", "absolute">,
PropertyParseKeyword<YGPositionType>,
}},

{ PropertyId::MarginTop, {
Expand Down Expand Up @@ -395,16 +396,16 @@ static constexpr auto PropertyDefinitions = MakeEnumArray<PropertyId, PropertyDe
PropertyParseKeyword<"auto", "flex-start", "center", "flex-end", "stretch", "baseline", "space-between", "space-around">,
}},
{ PropertyId::Direction, {
PropertyParseKeyword<"inherit", "ltr", "rtl">,
PropertyParseKeyword<YGDirection>,
}},
{ PropertyId::FlexDirection, {
PropertyParseKeyword<"column", "column-reverse", "row", "row-reverse">,
PropertyParseKeyword<YGFlexDirection>,
}},
{ PropertyId::FlexWrap, {
PropertyParseKeyword<"nowrap", "wrap", "wrap-reverse">,
PropertyParseKeyword<YGWrap>,
}},
{ PropertyId::JustifyContent, {
PropertyParseKeyword<"flex-start", "center", "flex-end", "space-between", "space-around", "space-evenly">,
PropertyParseKeyword<YGJustify>,
}},

{ PropertyId::AspectRatio, {
Expand Down Expand Up @@ -806,7 +807,7 @@ static bool ParseShorthandDeclaration(PropertyVector& vec, ShorthandId shorthand
}
return ParseShorthandDeclaration(vec, shorthand_id, property_values);
}

void StyleSheetSpecification::Initialise() {
Style::Initialise(InheritableProperties);
StyleSheetDefaultValue::Initialise();
Expand Down
22 changes: 21 additions & 1 deletion pkg/ant.rmlui/src/util/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,27 @@ namespace Rml {
static_assert(false, "Unsupported compiler");
#endif
}

template <auto Value>
constexpr auto EnumNameV = EnumName<Value>();

template <typename T>
constexpr auto EnumTypeName() {
#if __GNUC__ || __clang__
std::string_view name = __PRETTY_FUNCTION__;
std::size_t start = name.find('=') + 2;
std::size_t end = name.size() - 1;
return std::string_view{name.data() + start, end - start};
#elif _MSC_VER
std::string_view name = __FUNCSIG__;
std::size_t start = name.find('<') + 1;
std::size_t end = name.rfind(">(");
name = std::string_view{name.data() + start, end - start};
start = name.find(' ');
return start == std::string_view::npos ? name : std::string_view{name.data() + start + 1, name.size() - start - 1};
#else
static_assert(false, "Unsupported compiler");
#endif
}
template <typename T>
constexpr auto EnumTypeNameV = EnumTypeName<T>();
}

0 comments on commit 0719128

Please sign in to comment.