Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/ext/imgui/imgui_extras.cpp
5656 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
int 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 ctrlHeld = ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl);
25
bool held = ImGui::IsItemActive() && shiftHeld;
26
27
static float repeatDelay = 0.25f; // seconds before repeating starts
28
static ImGuiID activeId = 0;
29
static float holdTimer = 0.0f;
30
31
ImGuiID id = ImGui::GetItemID();
32
if (held) {
33
if (activeId != id) {
34
activeId = id;
35
holdTimer = 0.0f;
36
} else {
37
holdTimer += ImGui::GetIO().DeltaTime;
38
if (holdTimer >= repeatDelay) {
39
float t = holdTimer - repeatDelay;
40
int steps = static_cast<int>(t / repeatRate);
41
static int lastStep = -1;
42
if (steps != lastStep) {
43
int count = steps - lastStep;
44
lastStep = steps;
45
return count;
46
}
47
}
48
}
49
} else {
50
// Reset if not holding
51
if (activeId == id) {
52
activeId = 0;
53
holdTimer = 0.0f;
54
}
55
}
56
57
return clicked ? 1 : 0;
58
}
59
60
bool CollapsingHeaderWithCount(const char *title, int count, ImGuiTreeNodeFlags flags) {
61
char temp[256];
62
snprintf(temp, sizeof(temp), "%s (%d)##%s", title, count, title);
63
return ImGui::CollapsingHeader(temp, flags);
64
}
65
66
} // namespace ImGui
67
68