-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.h
More file actions
145 lines (120 loc) · 4.43 KB
/
UI.h
File metadata and controls
145 lines (120 loc) · 4.43 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include <imgui/imgui.h>
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui/imgui_internal.h>
#include "Lux/ImGui/Colors.h"
#include "Lux/ImGui/ImGuiUtilities.h"
namespace Lux::UI {
// =========================================================================
// Scoped helpers — mirrors the Hazel UI:: namespace conventions
// =========================================================================
/// RAII wrapper for ImGui::PushStyleColor / PopStyleColor
struct ScopedColour
{
ScopedColour() = default;
ScopedColour(ImGuiCol idx, ImVec4 colour, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, colour);
}
ScopedColour(ImGuiCol idx, ImU32 colour, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, colour);
}
ScopedColour(ImGuiCol idx, ImColor colour, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, colour.Value);
}
~ScopedColour()
{
if (m_Set)
ImGui::PopStyleColor();
}
ScopedColour(const ScopedColour&) = delete;
ScopedColour& operator=(const ScopedColour&) = delete;
private:
bool m_Set = false;
};
// Legacy alias kept for backwards compatibility
using ScopedStyleColor = ScopedColour;
/// RAII wrapper for ImGui::PushStyleVar / PopStyleVar
struct ScopedStyle
{
ScopedStyle(ImGuiStyleVar styleVar, float value) { ImGui::PushStyleVar(styleVar, value); }
ScopedStyle(ImGuiStyleVar styleVar, ImVec2 value) { ImGui::PushStyleVar(styleVar, value); }
~ScopedStyle() { ImGui::PopStyleVar(); }
ScopedStyle(const ScopedStyle&) = delete;
ScopedStyle& operator=(const ScopedStyle&) = delete;
};
/// RAII wrapper for ImGui::PushFont / PopFont
struct ScopedFont
{
ScopedFont(ImFont* font) { ImGui::PushFont(font); }
~ScopedFont() { ImGui::PopFont(); }
ScopedFont(const ScopedFont&) = delete;
ScopedFont& operator=(const ScopedFont&) = delete;
};
// =========================================================================
// Cursor helpers
// =========================================================================
/// Shift the cursor position along the X axis by the given amount
inline void ShiftCursorX(float distance)
{
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + distance);
}
/// Shift the cursor position along the Y axis by the given amount
inline void ShiftCursorY(float distance)
{
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + distance);
}
/// Shift the cursor position along both axes
inline void ShiftCursor(float x, float y)
{
const ImVec2 cursor = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(cursor.x + x, cursor.y + y));
}
// =========================================================================
// DrawButtonImage — draws a texture directly into an already-placed item
// rect, choosing the tint based on the item interaction state.
// =========================================================================
/// Draw a button image using separate textures for each interaction state.
/// Call this *after* an invisible button or any other item that occupies the
/// desired rect, then the tint colour is picked automatically.
inline void DrawButtonImage(
const Ref<Texture2D>& imageNormal,
const Ref<Texture2D>& imageHovered,
const Ref<Texture2D>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax,
ImVec2 uv0 = ImVec2(0.0f, 0.0f), ImVec2 uv1 = ImVec2(1.0f, 1.0f))
{
// Delegate to ImGuiEx which has the full implementation
ImGuiEx::DrawButtonImage(imageNormal, imageHovered, imagePressed,
tintNormal, tintHovered, tintPressed, rectMin, rectMax, uv0, uv1);
}
/// Convenience overload — single texture for all states
inline void DrawButtonImage(
const Ref<Texture2D>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax,
ImVec2 uv0 = ImVec2(0.0f, 0.0f), ImVec2 uv1 = ImVec2(1.0f, 1.0f))
{
ImGuiEx::DrawButtonImage(image, tintNormal, tintHovered, tintPressed,
rectMin, rectMax, uv0, uv1);
}
/// Convenience overload — uses the last item rect for the image bounds
inline void DrawButtonImage(
const Ref<Texture2D>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 uv0 = ImVec2(0.0f, 0.0f), ImVec2 uv1 = ImVec2(1.0f, 1.0f))
{
ImGuiEx::DrawButtonImage(image, tintNormal, tintHovered, tintPressed, uv0, uv1);
}
}