-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonStyleComponent.h
More file actions
113 lines (92 loc) · 2.89 KB
/
Copy pathButtonStyleComponent.h
File metadata and controls
113 lines (92 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once
#include <stdint.h>
#include "DekiBehaviour.h"
#include "assets/AssetRef.h"
#include "reflection/ObjectRef.h"
#include "reflection/DekiProperty.h"
#include "Color.h"
#include "Sprite.h"
// Forward declarations
class ButtonComponent;
class SpriteComponent;
enum class ButtonState : uint8_t;
/**
* @brief Transition mode for ButtonStyleComponent
*/
enum class ButtonStyleMode : uint8_t
{
ColorTint = 0, // Tint the existing sprite per state
SpriteSwap = 1 // Swap entire sprite assets per state
};
/**
* @brief CSS-like visual feedback for buttons
*
* ButtonStyleComponent observes a ButtonComponent via ObjectRef and modifies
* a sibling SpriteComponent's appearance based on button state.
*
* Two modes:
* - ColorTint: Changes the sprite's tint color per state
* - SpriteSwap: Swaps the entire sprite asset per state
*
* Usage:
* @code
* auto* entity = new DekiObject("StyledButton");
* auto* sprite = entity->AddComponent<SpriteComponent>();
* auto* button = entity->AddComponent<ButtonComponent>();
* auto* style = entity->AddComponent<ButtonStyleComponent>();
*
* // Set button reference (required)
* style->button.Set(entity);
*
* // Configure colors (ColorTint mode)
* style->normal_color = deki::Color::White;
* style->pressed_color = deki::Color(160, 160, 160);
* @endcode
*/
class ButtonStyleComponent : public DekiBehaviour
{
DEKI_COMPONENT(ButtonStyleComponent, DekiBehaviour, "2D", "0c34e973-6cd1-45d2-b2c6-f010ba320707", "DEKI_FEATURE_BUTTON")
DEKI_DESCRIPTION("Gives a button its look per state, by tinting or by swapping sprites.")
public:
// Button to observe (required)
DEKI_EXPORT
ObjectRef<ButtonComponent> button;
// Sprite to modify
DEKI_EXPORT
ObjectRef<SpriteComponent> sprite;
// Transition mode
DEKI_EXPORT
ButtonStyleMode transition;
// --- ColorTint mode colors ---
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
deki::Color normal_color;
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
deki::Color hovered_color;
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
deki::Color pressed_color;
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
deki::Color disabled_color;
// --- SpriteSwap mode sprites ---
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
Deki::AssetRef<Sprite> normal_sprite;
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
Deki::AssetRef<Sprite> hovered_sprite;
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
Deki::AssetRef<Sprite> pressed_sprite;
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
Deki::AssetRef<Sprite> disabled_sprite;
ButtonStyleComponent();
void Start() override;
private:
void ApplyState(ButtonState state);
};
// Generated property metadata (after class definition for offsetof)
#include "generated/ButtonStyleComponent.gen.h"