diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3d088b2..eff3c85 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,6 +8,16 @@ set(CMAKE_CXX_EXTENSIONS OFF) include_directories("../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp") +list(FILTER SOURCE_LIST EXCLUDE REGEX "CMakeCXXCompilerId.cpp$") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin") -add_executable(${PROJECT_NAME} ${SOURCE_LIST}) +foreach( source ${SOURCE_LIST} ) + string(REPLACE ".cpp" "" name ${source} ) + string(REGEX REPLACE ".+/" "" name ${name} ) + add_executable( ${name} ${source} ) + target_link_libraries(${name} + PRIVATE + Spaic + SpaicCSS + ) +endforeach( source ${SOURCE_LIST} ) \ No newline at end of file diff --git a/examples/Counter.cpp b/examples/Counter.cpp index 967ebe3..af8022c 100644 --- a/examples/Counter.cpp +++ b/examples/Counter.cpp @@ -1,6 +1,7 @@ #include #include +#include namespace props::counter { @@ -46,9 +47,8 @@ auto counter = create_component(props::counter::all, state::counter::all, update int main() { using namespace props::counter; + auto wtf_is_this_style = css( + width = 10.0_px); counter(is_dark_theme = true)("Hello, world!"); - // new Counter(is_dark_theme = true); - // Counter{is_dark_theme = true}; - // Counter(is_dark_theme = true); return EXIT_SUCCESS; } diff --git a/include/spaic-css/CSS.hpp b/include/spaic-css/CSS.hpp index 4194b4a..f661ea1 100644 --- a/include/spaic-css/CSS.hpp +++ b/include/spaic-css/CSS.hpp @@ -2,8 +2,12 @@ #include -namespace spaic +namespace spaic::css { template -spaic::css::Stylesheet css(T... params); -} +Stylesheet css(T... params); +template +Stylesheet keyframes(T... params); +} // namespace spaic::css + +#include \ No newline at end of file diff --git a/include/spaic-css/CssProperty.hpp b/include/spaic-css/CssProperty.hpp new file mode 100644 index 0000000..12f6093 --- /dev/null +++ b/include/spaic-css/CssProperty.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace spaic::css::prop +{ +template +class AssignedCssProperty +{ +}; + +template +class CssProperty +{ +public: + AssignedCssProperty operator=(T value); +}; +} // namespace spaic::css::prop + +#include \ No newline at end of file diff --git a/include/spaic-css/PredefinedCssProperty.hpp b/include/spaic-css/PredefinedCssProperty.hpp new file mode 100644 index 0000000..60edce1 --- /dev/null +++ b/include/spaic-css/PredefinedCssProperty.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace spaic::css::prop +{ +using namespace spaic::css::unit; +// TODO: Strong type check, can we use Length type? +CssProperty> width; +} // namespace spaic::css::prop \ No newline at end of file diff --git a/include/spaic-css/Prelude.hpp b/include/spaic-css/Prelude.hpp new file mode 100644 index 0000000..7d2d1ee --- /dev/null +++ b/include/spaic-css/Prelude.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include +#include +#include + +using namespace spaic::css::prop; +using spaic::css::css; +using namespace spaic::css::unit; \ No newline at end of file diff --git a/include/spaic-css/Stylesheet.hpp b/include/spaic-css/Stylesheet.hpp index d8642e8..6ea190f 100644 --- a/include/spaic-css/Stylesheet.hpp +++ b/include/spaic-css/Stylesheet.hpp @@ -1,8 +1,11 @@ #pragma once +#include + namespace spaic::css { class Stylesheet { + std::string compile(); }; } // namespace spaic::css diff --git a/include/spaic-css/Unit.hpp b/include/spaic-css/Unit.hpp new file mode 100644 index 0000000..0ea99c0 --- /dev/null +++ b/include/spaic-css/Unit.hpp @@ -0,0 +1,102 @@ +#pragma once + +#define defineUnitUDLRaw(underscore, unitType) \ + CssUnit operator"" underscore##unitType(long double v) noexcept \ + { \ + return CssUnit(v); \ + } \ + CssUnit operator"" underscore##unitType(unsigned long long v) noexcept \ + { \ + return CssUnit(v); \ + } +#define defineUnitUDL(unitType) defineUnitUDLRaw(_, unitType) + +#include + +namespace spaic::css::unit +{ +enum class CssUnitType +{ + em, + ex, + cap, + ch, + ic, + rem, + lh, + rlh, + vw, + vh, + vi, + vb, + vmin, + vmax, + cm, + mm, + q, + in, + pc, + pt, + px, + deg, + grad, + rad, + turn, + s, + ms, + hz, + khz, + dpi, + dpcm, + dppx, + percent +}; +template +class CssUnit +{ +private: + long double value; + +public: + CssUnit(long double value) noexcept : value(value) {} + + std::string toCssValue(); +}; + +defineUnitUDL(em); +defineUnitUDL(ex); +defineUnitUDL(cap); +defineUnitUDL(ch); +defineUnitUDL(ic); +defineUnitUDL(rem); +defineUnitUDL(lh); +defineUnitUDL(rlh); +defineUnitUDL(vw); +defineUnitUDL(vh); +defineUnitUDL(vi); +defineUnitUDL(vb); +defineUnitUDL(vmin); +defineUnitUDL(vmax); +defineUnitUDL(cm); +defineUnitUDL(mm); +defineUnitUDL(q); +defineUnitUDL(in); +defineUnitUDL(pc); +defineUnitUDL(pt); +defineUnitUDL(px); +defineUnitUDL(deg); +defineUnitUDL(grad); +defineUnitUDL(rad); +defineUnitUDL(turn); +defineUnitUDL(s); +defineUnitUDL(ms); +defineUnitUDL(hz); +defineUnitUDL(khz); +defineUnitUDL(dpi); +defineUnitUDL(dpcm); +defineUnitUDL(dppx); +defineUnitUDL(percent); +} // namespace spaic::css::unit + +#undef defineUnitUDLRaw +#undef defineUnitUDL \ No newline at end of file diff --git a/include/spaic-css/detail/CSS.hpp b/include/spaic-css/detail/CSS.hpp new file mode 100644 index 0000000..19efa0f --- /dev/null +++ b/include/spaic-css/detail/CSS.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace spaic::css +{ +template +spaic::css::Stylesheet css(T... params) +{ + throw "TODO"; +} +} // namespace spaic::css diff --git a/include/spaic-css/detail/CssProperty.hpp b/include/spaic-css/detail/CssProperty.hpp new file mode 100644 index 0000000..09fa61e --- /dev/null +++ b/include/spaic-css/detail/CssProperty.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace spaic::css::prop +{ + +template +AssignedCssProperty CssProperty::operator=(T value) +{ + return AssignedCssProperty(); +} + +} // namespace spaic::css::prop \ No newline at end of file diff --git a/include/spaic/Component.hpp b/include/spaic/Component.hpp index 51af79c..62e42b3 100644 --- a/include/spaic/Component.hpp +++ b/include/spaic/Component.hpp @@ -11,8 +11,11 @@ namespace spaic::comp using ShouldRender = bool; using Update = std::function; using Render = std::function; - -class ComponentBody; +class ComponentBody +{ +public: + spaic::vnode::VNode operator()(spaic::vnode::VNode children...) noexcept; +}; template class Component { @@ -20,11 +23,8 @@ class Component template ComponentBody operator()(T... args) noexcept; }; -class ComponentBody -{ -public: - spaic::vnode::VNode operator()(spaic::vnode::VNode children...) noexcept; -}; template Component create_component(Props props, StateSet state, Update update, Render render); } // namespace spaic::comp + +#include \ No newline at end of file diff --git a/include/spaic/Message.hpp b/include/spaic/Message.hpp index d6cdef0..7a5f38c 100644 --- a/include/spaic/Message.hpp +++ b/include/spaic/Message.hpp @@ -17,3 +17,5 @@ class Message }; } // namespace spaic::msg + +#include \ No newline at end of file diff --git a/include/spaic/Property.hpp b/include/spaic/Property.hpp index 358388f..109b4ae 100644 --- a/include/spaic/Property.hpp +++ b/include/spaic/Property.hpp @@ -13,7 +13,7 @@ class Property { public: - virtual AssignedProperty operator=(I &&value) noexcept; + virtual AssignedProperty operator=(I &&value) noexcept {}; }; template @@ -23,14 +23,16 @@ class AssignedProperty Property ⌖ O value; - AssignedProperty(Property &target, O &&value); +public: + template + AssignedProperty(Property &target, U &&value); }; template -Property &&required() noexcept; - +Property required() noexcept; template -Property> &&optional() noexcept; - +Property> optional() noexcept; template -Property &&fallback(T &&value) noexcept; +Property fallback(T &&fallback_value) noexcept; } // namespace spaic::props + +#include \ No newline at end of file diff --git a/include/spaic/State.hpp b/include/spaic/State.hpp index 848e66d..0947d40 100644 --- a/include/spaic/State.hpp +++ b/include/spaic/State.hpp @@ -8,7 +8,8 @@ class State public: State() {} - // todo: T &operator*(); }; } // namespace spaic::state + +#include \ No newline at end of file diff --git a/include/spaic/VNode.hpp b/include/spaic/VNode.hpp index bc22a2a..f286aa4 100644 --- a/include/spaic/VNode.hpp +++ b/include/spaic/VNode.hpp @@ -6,6 +6,7 @@ namespace spaic::vnode { +// TODO: Array of VNode should be VNode. using VNode = std::variant< std::string, std::nullptr_t, diff --git a/include/spaic/detail/Component.hpp b/include/spaic/detail/Component.hpp new file mode 100644 index 0000000..db41b7b --- /dev/null +++ b/include/spaic/detail/Component.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace spaic::comp +{ +spaic::vnode::VNode ComponentBody::operator()(spaic::vnode::VNode children...) noexcept +{ + throw "TODO: ComponentBody::operator()(children)"; +} + +template +template +ComponentBody Component::operator()(T... args) noexcept +{ + throw "TODO: Component::operator()(args)"; +} +template +Component create_component(Props props, StateSet state, Update update, Render render) +{ + throw "TODO: create_component(props, state, update, render)"; +} +} // namespace spaic::comp diff --git a/include/spaic/detail/Message.hpp b/include/spaic/detail/Message.hpp new file mode 100644 index 0000000..cf523bd --- /dev/null +++ b/include/spaic/detail/Message.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +namespace spaic::msg +{ + +template +Message::operator bool() +{ + throw "TODO: Message::operator bool()"; +} + +template +template +typename std::tuple_element>::type Message::get() +{ + throw "TODO: Message::get()"; +} + +} // namespace spaic::msg diff --git a/include/spaic/detail/Property.hpp b/include/spaic/detail/Property.hpp new file mode 100644 index 0000000..ffea73b --- /dev/null +++ b/include/spaic/detail/Property.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include +#include + +namespace spaic::props +{ + +template +class Required : public Property +{ +public: + AssignedProperty operator=(T &&value) noexcept + { + return AssignedProperty(*this, value); + }; +}; +template +class Optional : public Property> +{ +public: + AssignedProperty> operator=(T &&value) noexcept + { + return AssignedProperty(*this, std::optional(value)); + }; +}; +template +class Fallback : public Property +{ +private: + T m_fallback_value; + +public: + template + Fallback(U &&fallback_value) : m_fallback_value(std::forward(fallback_value)) + { + } + AssignedProperty operator=(T &&value) noexcept + { + return AssignedProperty(*this, value); + }; +}; + +template +template +AssignedProperty::AssignedProperty(Property &target, U &&value) : target(target), value(std::forward(value)) {} + +template +Property required() noexcept +{ + return Required(); +} +template +Property> optional() noexcept +{ + return Optional(); +} +template +Property fallback(T &&fallback_value) noexcept +{ + return Fallback(fallback_value); +} +} // namespace spaic::props diff --git a/include/spaic/detail/State.hpp b/include/spaic/detail/State.hpp new file mode 100644 index 0000000..e16ef75 --- /dev/null +++ b/include/spaic/detail/State.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace spaic::state +{ + +template +T &State::operator*() +{ + throw "TODO: State::operator*()"; +} + +} // namespace spaic::state diff --git a/src/spaic-css/CMakeLists.txt b/src/spaic-css/CMakeLists.txt index 4362780..7a7dbd1 100644 --- a/src/spaic-css/CMakeLists.txt +++ b/src/spaic-css/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) include_directories("../../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp") +list(FILTER SOURCE_LIST EXCLUDE REGEX "CMakeCXXCompilerId.cpp$") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../../bin") add_library(${PROJECT_NAME} STATIC ${SOURCE_LIST}) diff --git a/src/spaic/CMakeLists.txt b/src/spaic/CMakeLists.txt index 4ce38d1..69dac14 100644 --- a/src/spaic/CMakeLists.txt +++ b/src/spaic/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) include_directories("../../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp") +list(FILTER SOURCE_LIST EXCLUDE REGEX "CMakeCXXCompilerId.cpp$") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../../bin") add_library(${PROJECT_NAME} STATIC ${SOURCE_LIST}) diff --git a/src/spaic/Property.cpp b/src/spaic/Property.cpp index 37047ba..6af2406 100644 --- a/src/spaic/Property.cpp +++ b/src/spaic/Property.cpp @@ -4,52 +4,4 @@ namespace spaic::props { -template -class Required : Property -{ -public: - AssignedProperty operator=(T &&value) noexcept - { - return std::move(new AssignedProperty(&this, value)); - }; -}; -template -class Optional : Property> -{ -public: - AssignedProperty> operator=(T &&value) noexcept - { - return std::move(new AssignedProperty(&this, std::optional(value))); - }; -}; -template -class Fallback : Property -{ -private: - T &&m_fallback_value; - -public: - Fallback(T &&fallback_value) : m_fallback_value(fallback_value) - { - } - AssignedProperty operator=(T &&value) noexcept - { - return std::move(new AssignedProperty(&this, value)); - }; -}; -template -Property &&required() noexcept -{ - return std::move(Required()); -} -template -Property> &&optional() noexcept -{ - return std::move(Optional()); -} -template -Property &&fallback(T &&fallback_value) noexcept -{ - return std::move(Fallback(fallback_value)); -} } // namespace spaic::props