Skip to content

Commit

Permalink
Compiles on my machine πŸ‘ŒπŸ‘ŒπŸ‘ŒπŸ‘Œ
Browse files Browse the repository at this point in the history
  • Loading branch information
RanolP committed Mar 8, 2020
1 parent f19997d commit b8ec654
Show file tree
Hide file tree
Showing 22 changed files with 339 additions and 70 deletions.
12 changes: 11 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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} )
6 changes: 3 additions & 3 deletions examples/Counter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cstdlib>

#include <spaic/Prelude.hpp>
#include <spaic-css/Prelude.hpp>

namespace props::counter
{
Expand Down Expand Up @@ -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;
}
10 changes: 7 additions & 3 deletions include/spaic-css/CSS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

#include <spaic-css/Stylesheet.hpp>

namespace spaic
namespace spaic::css
{
template <typename... T>
spaic::css::Stylesheet css(T... params);
}
Stylesheet css(T... params);
template <typename... T>
Stylesheet keyframes(T... params);
} // namespace spaic::css

#include <spaic-css/detail/CSS.hpp>
18 changes: 18 additions & 0 deletions include/spaic-css/CssProperty.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

namespace spaic::css::prop
{
template <typename T>
class AssignedCssProperty
{
};

template <typename T>
class CssProperty
{
public:
AssignedCssProperty<T> operator=(T value);
};
} // namespace spaic::css::prop

#include <spaic-css/detail/CssProperty.hpp>
11 changes: 11 additions & 0 deletions include/spaic-css/PredefinedCssProperty.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <spaic-css/CssProperty.hpp>
#include <spaic-css/Unit.hpp>

namespace spaic::css::prop
{
using namespace spaic::css::unit;
// TODO: Strong type check, can we use Length type?
CssProperty<CssUnit<CssUnitType::px>> width;
} // namespace spaic::css::prop
9 changes: 9 additions & 0 deletions include/spaic-css/Prelude.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <spaic-css/PredefinedCssProperty.hpp>
#include <spaic-css/CSS.hpp>
#include <spaic-css/Unit.hpp>

using namespace spaic::css::prop;
using spaic::css::css;
using namespace spaic::css::unit;
3 changes: 3 additions & 0 deletions include/spaic-css/Stylesheet.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once

#include <string>

namespace spaic::css
{
class Stylesheet
{
std::string compile();
};
} // namespace spaic::css
102 changes: 102 additions & 0 deletions include/spaic-css/Unit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#pragma once

#define defineUnitUDLRaw(underscore, unitType) \
CssUnit<CssUnitType::unitType> operator"" underscore##unitType(long double v) noexcept \
{ \
return CssUnit<CssUnitType::unitType>(v); \
} \
CssUnit<CssUnitType::unitType> operator"" underscore##unitType(unsigned long long v) noexcept \
{ \
return CssUnit<CssUnitType::unitType>(v); \
}
#define defineUnitUDL(unitType) defineUnitUDLRaw(_, unitType)

#include <string>

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 <CssUnitType T>
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
12 changes: 12 additions & 0 deletions include/spaic-css/detail/CSS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <spaic-css/CSS.hpp>

namespace spaic::css
{
template <typename... T>
spaic::css::Stylesheet css(T... params)
{
throw "TODO";
}
} // namespace spaic::css
14 changes: 14 additions & 0 deletions include/spaic-css/detail/CssProperty.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <spaic-css/CssProperty.hpp>

namespace spaic::css::prop
{

template <typename T>
AssignedCssProperty<T> CssProperty<T>::operator=(T value)
{
return AssignedCssProperty<T>();
}

} // namespace spaic::css::prop
14 changes: 7 additions & 7 deletions include/spaic/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ namespace spaic::comp
using ShouldRender = bool;
using Update = std::function<ShouldRender()>;
using Render = std::function<spaic::vnode::VNode()>;

class ComponentBody;
class ComponentBody
{
public:
spaic::vnode::VNode operator()(spaic::vnode::VNode children...) noexcept;
};
template <typename Props>
class Component
{
public:
template <typename... T>
ComponentBody operator()(T... args) noexcept;
};
class ComponentBody
{
public:
spaic::vnode::VNode operator()(spaic::vnode::VNode children...) noexcept;
};
template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render);
} // namespace spaic::comp

#include <spaic/detail/Component.hpp>
2 changes: 2 additions & 0 deletions include/spaic/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ class Message
};

} // namespace spaic::msg

#include <spaic/detail/Message.hpp>
16 changes: 9 additions & 7 deletions include/spaic/Property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Property
{

public:
virtual AssignedProperty<I, O> operator=(I &&value) noexcept;
virtual AssignedProperty<I, O> operator=(I &&value) noexcept {};
};

template <typename I, typename O>
Expand All @@ -23,14 +23,16 @@ class AssignedProperty
Property<I, O> &target;
O value;

AssignedProperty(Property<I, O> &target, O &&value);
public:
template <typename U>
AssignedProperty(Property<I, O> &target, U &&value);
};
template <typename T>
Property<T, T> &&required() noexcept;

Property<T, T> required() noexcept;
template <typename T>
Property<T, std::optional<T>> &&optional() noexcept;

Property<T, std::optional<T>> optional() noexcept;
template <typename T>
Property<T, T> &&fallback(T &&value) noexcept;
Property<T, T> fallback(T &&fallback_value) noexcept;
} // namespace spaic::props

#include <spaic/detail/Property.hpp>
3 changes: 2 additions & 1 deletion include/spaic/State.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class State
public:
State() {}

// todo:
T &operator*();
};
} // namespace spaic::state

#include <spaic/detail/State.hpp>
1 change: 1 addition & 0 deletions include/spaic/VNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace spaic::vnode
{
// TODO: Array of VNode should be VNode.
using VNode = std::variant<
std::string,
std::nullptr_t,
Expand Down
27 changes: 27 additions & 0 deletions include/spaic/detail/Component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <functional>
#include <variant>
#include <spaic/VNode.hpp>
#include <spaic/Property.hpp>
#include <spaic/State.hpp>

namespace spaic::comp
{
spaic::vnode::VNode ComponentBody::operator()(spaic::vnode::VNode children...) noexcept
{
throw "TODO: ComponentBody::operator()(children)";
}

template <typename Props>
template <typename... T>
ComponentBody Component<Props>::operator()(T... args) noexcept
{
throw "TODO: Component::operator()(args)";
}
template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render)
{
throw "TODO: create_component(props, state, update, render)";
}
} // namespace spaic::comp
22 changes: 22 additions & 0 deletions include/spaic/detail/Message.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <tuple>
#include <spaic/Message.hpp>

namespace spaic::msg
{

template <typename... T>
Message<T...>::operator bool()
{
throw "TODO: Message::operator bool()";
}

template <typename... T>
template <size_t I>
typename std::tuple_element<I, std::tuple<T...>>::type Message<T...>::get()
{
throw "TODO: Message::get<I>()";
}

} // namespace spaic::msg
Loading

0 comments on commit b8ec654

Please sign in to comment.