Skip to content

Commit a562094

Browse files
committed
rewrite inputs
1 parent d88b0a4 commit a562094

23 files changed

+490
-813
lines changed

sources/include/cage-core/any.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,51 @@ namespace cage
77
{
88
namespace detail
99
{
10+
template<class T, uint32 MaxSize>
11+
concept AnyValueConcept = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T> && std::is_same_v<std::remove_cvref_t<T>, T> && sizeof(T) <= MaxSize && sizeof(T) > 0;
12+
1013
template<uint32 MaxSize>
1114
struct alignas(16) AnyBase
1215
{
1316
AnyBase() = default;
1417
AnyBase(const AnyBase &) = default;
1518

16-
template<class T>
19+
template<AnyValueConcept<MaxSize> T>
1720
CAGE_FORCE_INLINE AnyBase(const T &v) noexcept
1821
{
19-
static_assert(std::is_trivially_copyable_v<T>);
20-
static_assert(sizeof(T) <= MaxSize);
21-
static_assert(sizeof(T) > 0);
2222
detail::typeIndex<T>(); // detect hash collisions
2323
detail::memcpy(data_, &v, sizeof(T));
2424
type_ = detail::typeHash<T>();
2525
}
2626

2727
AnyBase &operator=(const AnyBase &) = default;
2828

29-
template<class T>
29+
template<AnyValueConcept<MaxSize> T>
3030
CAGE_FORCE_INLINE AnyBase &operator=(const T &v) noexcept
3131
{
3232
return *this = AnyBase(v);
3333
}
3434

35-
CAGE_FORCE_INLINE void clear() noexcept { type_ = m; }
36-
CAGE_FORCE_INLINE uint32 typeHash() const noexcept { return type_; }
37-
CAGE_FORCE_INLINE explicit operator bool() const noexcept { return type_ != m; }
35+
template<AnyValueConcept<MaxSize> T>
36+
CAGE_FORCE_INLINE bool has() const noexcept
37+
{
38+
return detail::typeHash<T>() == type_;
39+
}
3840

39-
template<class T>
41+
template<AnyValueConcept<MaxSize> T>
4042
T get() const
4143
{
42-
static_assert(std::is_trivially_copyable_v<T>);
43-
static_assert(sizeof(T) <= MaxSize);
44-
static_assert(sizeof(T) > 0);
4544
CAGE_ASSERT(detail::typeHash<T>() == type_);
4645
T tmp;
4746
detail::memcpy(&tmp, data_, sizeof(T));
4847
return tmp;
4948
}
5049

50+
CAGE_FORCE_INLINE void clear() noexcept { type_ = m; }
51+
CAGE_FORCE_INLINE uint32 typeHash() const noexcept { return type_; }
52+
CAGE_FORCE_INLINE explicit operator bool() const noexcept { return type_ != m; }
53+
static constexpr uint32 MaxSize = MaxSize;
54+
5155
private:
5256
char data_[MaxSize];
5357
uint32 type_ = m;

sources/include/cage-core/entities.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace cage
1111
class Entity;
1212

1313
template<class T>
14-
concept ComponentConcept = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>;
14+
concept ComponentConcept = std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T> && std::is_same_v<std::remove_cvref_t<T>, T>;
1515

1616
class CAGE_CORE_API EntityManager : private Immovable
1717
{

sources/include/cage-core/entitiesVisitor.h

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace cage
1616
template<class R, class T, class... Args>
1717
struct DecomposeLambda<R (T::*)(Args...) const>
1818
{
19-
using Return = R;
20-
using Class = T;
2119
using Params = std::tuple<Args...>;
2220
};
2321

sources/include/cage-core/typeIndex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace cage
1111
constexpr PointerRange<const char> typeName() noexcept
1212
{
1313
static_assert(std::is_same_v<std::decay_t<T>, T>);
14-
static_assert(std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, T>);
14+
static_assert(std::is_same_v<std::remove_cvref_t<T>, T>);
1515
#ifdef _MSC_VER
1616
return __FUNCSIG__;
1717
#else

sources/include/cage-engine/core.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace cage
2222
enum class CheckBoxStateEnum : uint32;
2323
enum class InputButtonsPlacementModeEnum : uint32;
2424
enum class GuiElementTypeEnum : uint32;
25-
enum class InputClassEnum : uint32;
2625
enum class LightTypeEnum : uint32;
2726
enum class WindowFlags : uint32;
2827

sources/include/cage-engine/guiBuilder.h

+7-37
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66

77
namespace cage
88
{
9-
class EntityManager;
10-
class Entity;
11-
12-
namespace privat
13-
{
14-
template<void (*F)(), bool StopPropagation = true>
15-
CAGE_FORCE_INLINE bool guiActionWrapper(Entity *)
16-
{
17-
(F)();
18-
return StopPropagation;
19-
}
20-
}
21-
229
namespace guiBuilder
2310
{
2411
class GuiBuilder;
@@ -50,34 +37,17 @@ namespace cage
5037
BuilderItem skin(uint32 index = m);
5138
BuilderItem disabled(bool disable = true);
5239

53-
BuilderItem event(Delegate<bool(Entity *)> ev);
54-
template<bool (*F)(Entity *)>
55-
BuilderItem event()
56-
{
57-
return event(Delegate<bool(Entity *)>().bind<F>());
58-
}
59-
template<class D, bool (*F)(D, Entity *)>
60-
BuilderItem event(D d)
40+
BuilderItem event(Delegate<bool(GenericInput)> ev);
41+
template<class Callable>
42+
requires(std::is_invocable_r_v<bool, Callable, GenericInput>)
43+
BuilderItem event(Callable &&callable)
6144
{
62-
return event(Delegate<bool(Entity *)>().bind<D, F>(d));
63-
}
64-
template<void (*F)(), bool StopPropagation = true>
65-
BuilderItem event()
66-
{
67-
return event(Delegate<bool(Entity *)>().bind<&privat::guiActionWrapper<F, StopPropagation>>());
45+
Delegate<bool(GenericInput)> ev;
46+
ev.bind(std::move(callable));
47+
return event(ev);
6848
}
6949

7050
BuilderItem update(Delegate<void(Entity *)> u);
71-
template<void (*F)(Entity *)>
72-
BuilderItem update()
73-
{
74-
return update(Delegate<void(Entity *)>().bind<F>());
75-
}
76-
template<class D, void (*F)(D, Entity *)>
77-
BuilderItem update(D d)
78-
{
79-
return update(Delegate<void(Entity *)>().bind<D, F>(d));
80-
}
8151

8252
BuilderItem tooltip(const GuiTooltipComponent &t);
8353
template<StringLiteral Text, uint32 AssetName = 0, uint32 TextName = 0>

sources/include/cage-engine/guiComponents.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define guard_guiComponents_sdf1gh45hk485aws
33

44
#include <cage-core/stringLiteral.h>
5-
#include <cage-engine/core.h>
5+
#include <cage-engine/inputs.h>
66

77
namespace cage
88
{
@@ -74,11 +74,14 @@ namespace cage
7474

7575
struct CAGE_ENGINE_API GuiEventComponent
7676
{
77-
Delegate<bool(Entity *)> event;
77+
Delegate<bool(GenericInput)> event;
7878
};
7979

8080
struct CAGE_ENGINE_API GuiUpdateComponent
8181
{
82+
// called periodically from the gui itself
83+
// useful for updating text, image, format, etc.
84+
// do NOT use for adding/removing entities
8285
Delegate<void(Entity *)> update;
8386
};
8487

@@ -201,12 +204,9 @@ namespace cage
201204
{
202205
// input box and text area
203206
None = 0,
204-
//ReadOnly = 1 << 0,
205-
//SelectAllOnFocusGain = 1 << 1,
206-
GoToEndOnFocusGain = 1 << 2,
207-
ShowArrowButtons = 1 << 3,
208-
AlwaysRoundValueToStep = 1 << 4,
209-
//AcceptTabs = 1 << 5, // tab key will write tab rather than skip to next widget
207+
ShowArrowButtons = 1 << 1,
208+
AlwaysRoundValueToStep = 1 << 2,
209+
GoToEndOnFocusGain = 1 << 3,
210210
};
211211

212212
struct CAGE_ENGINE_API GuiInputComponent

0 commit comments

Comments
 (0)