Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/ext/imgui/imgui_extras.cpp
3187 views
1
// Just some string_view and related wrappers.
2
3
#include <cstdio>
4
#include <cstdlib>
5
#include <string_view>
6
#include "ext/imgui/imgui.h"
7
8
namespace ImGui {
9
10
bool RepeatButton(const char *title) {
11
if (ImGui::SmallButton(title)) {
12
return true;
13
}
14
if (ImGui::IsItemActive()) {
15
return true;
16
}
17
return false;
18
}
19
20
bool RepeatButtonShift(const char* label, float repeatRate) {
21
bool clicked = ImGui::Button(label);
22
23
bool shiftHeld = ImGui::IsKeyDown(ImGuiKey_LeftShift) || ImGui::IsKeyDown(ImGuiKey_RightShift);
24
bool held = ImGui::IsItemActive() && shiftHeld;
25
26
static float repeatDelay = 0.25f; // seconds before repeating starts
27
static ImGuiID activeId = 0;
28
static float holdTimer = 0.0f;
29
30
ImGuiID id = ImGui::GetItemID();
31
if (held) {
32
if (activeId != id) {
33
activeId = id;
34
holdTimer = 0.0f;
35
} else {
36
holdTimer += ImGui::GetIO().DeltaTime;
37
if (holdTimer >= repeatDelay) {
38
float t = holdTimer - repeatDelay;
39
int steps = static_cast<int>(t / repeatRate);
40
static int lastStep = -1;
41
if (steps != lastStep) {
42
lastStep = steps;
43
return true;
44
}
45
}
46
}
47
} else {
48
// Reset if not holding
49
if (activeId == id) {
50
activeId = 0;
51
holdTimer = 0.0f;
52
}
53
}
54
55
return clicked;
56
}
57
58
bool CollapsingHeaderWithCount(const char *title, int count, ImGuiTreeNodeFlags flags) {
59
char temp[256];
60
snprintf(temp, sizeof(temp), "%s (%d)##%s", title, count, title);
61
return ImGui::CollapsingHeader(temp, flags);
62
}
63
64
} // namespace ImGui
65
66