vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
ui_button.h
1#pragma once
2
3#include <cstdint>
4#include <string>
5
6#include <glm/glm.hpp>
7
8#include "core/reflect.h"
9#include "ecs/component/ui/ui_shape.h"
10
11namespace Vkm::Engine {
12
20struct UIButton {
21 enum class State : uint8_t { Normal, Hover, Pressed, Disabled };
22
23 glm::vec4 normalColor = {0.18f, 0.20f, 0.26f, 0.95f};
24 glm::vec4 hoverColor = {0.26f, 0.30f, 0.40f, 0.95f};
25 glm::vec4 pressedColor = {0.12f, 0.14f, 0.18f, 0.95f};
26 glm::vec4 disabledColor = {0.15f, 0.15f, 0.17f, 0.60f};
27
29 std::string eventId;
30 bool interactable = true;
31
32 // Written by the UISystem every frame the button is drawn; never authored.
33 State state = State::Normal;
35 bool held = false;
37 glm::vec2 pointer = glm::vec2(0.0f);
39 glm::vec2 resolvedSize = glm::vec2(0.0f);
40
46 const glm::vec4& colorForState() const {
47 // No default, so a new state is a build warning rather than a silent Normal.
48 switch (state) {
49 case State::Normal: return normalColor;
50 case State::Hover: return hoverColor;
51 case State::Pressed: return pressedColor;
52 case State::Disabled: return disabledColor;
53 }
54 return normalColor;
55 }
56};
57
58} // namespace Vkm::Engine
59
60VKM_REFLECT_BEGIN(::Vkm::Engine::UIButton)
61 VKM_F(normalColor)
62 VKM_F(hoverColor)
63 VKM_F(pressedColor)
64 VKM_F(disabledColor)
65 VKM_F(shape)
66 VKM_F(eventId)
67 VKM_F(interactable)
68VKM_REFLECT_END()
An interactive, hit-tested button drawn over its element's rect.
Definition ui_button.h:20
std::string eventId
Identifier carried by the UIClickEvent this button fires.
Definition ui_button.h:29
glm::vec2 pointer
In the element's reference pixels, from its top-left.
Definition ui_button.h:37
bool interactable
When false: drawn Disabled, ignores the pointer.
Definition ui_button.h:30
bool held
A press began on it and is still down, wherever the pointer is now.
Definition ui_button.h:35
const glm::vec4 & colorForState() const
The background tint for the current state.
Definition ui_button.h:46
glm::vec2 resolvedSize
The element's laid-out size, in the same pixels as pointer.
Definition ui_button.h:39
UIShape shape
Corners, edge and fade of the quad, whatever state colours it.
Definition ui_button.h:28
How a filled quad is drawn beyond its flat tint: corners, an edge, a fade.
Definition ui_shape.h:15