13#include <imgui/imgui.h>
14#include <imgui/imgui_internal.h>
15#include <initializer_list>
28 bool Spinner(
const char* label,
float radius,
float thickness,
const ImU32& color);
33 bool BeginMenu(
const char* label,
bool enabled,
bool& hovered);
34 void BeginMenuChild(
const char* child_str_id,
const char* menu_label, std::function<
void()> draw_func);
35 void BeginMenu(
const char* menu_label, std::function<
void()> draw_func);
38 bool TreeNodeEx(
const char* label, ImGuiTreeNodeFlags flags,
void* icon);
45 bool BeginTable(
const char* str_id,
int column, ImGuiTableFlags flags = 0,
const ImVec2& outer_size = ImVec2(0.0f, 0.0f),
float inner_width = 0.0f, ImGuiWindowFlags child_window_flags = 0);
63 requires std::is_enum_v<E>
65 const bool selected = ImGui::Selectable(
to_string(value).data());
75 template<
typename E, std::ranges::range R>
76 requires(std::is_enum_v<E> && std::same_as<std::ranges::range_value_t<R>, E>)
77 bool EnumCombo(
const char* label, E& storage,
const R& values,
const std::map<E, std::function<std::string()>>& pPopupText = {}) {
78 if (ImGui::BeginCombo(label,
to_string(storage).data())) {
79 bool selected =
false;
80 for (
const E& val : values) {
85 if (ImGui::IsItemHovered()) {
86 if (
const auto& iterator = pPopupText.find(val); iterator != pPopupText.end()) {
87 const auto& second = iterator->second();
88 ImGui::SetTooltip(
"%s", second.c_str());
102 requires(std::is_enum_v<E>)
103 bool EnumCombo(
const char* label, E& storage,
const std::initializer_list<E>& values,
const std::map<E, std::function<std::string()>>& pPopupText = {}) {
104 if (ImGui::BeginCombo(label,
to_string(storage).data())) {
105 bool selected =
false;
106 for (
const E& val : values) {
111 if (ImGui::IsItemHovered()) {
112 if (
const auto& iterator = pPopupText.find(val); iterator != pPopupText.end()) {
113 ImGui::SetTooltip(
"%s", iterator->second().c_str());
133 requires std::is_enum_v<E>
134 bool EnumCombo(
const char* label, E& storage, E lastElement,
const std::map<uint64_t, std::function<std::string()>>& pPopupText = {}) {
135 if (ImGui::BeginCombo(label,
to_string(storage).data())) {
136 bool selected =
false;
137 for (uint64_t i = 0; i < static_cast<uint64_t>(lastElement); ++i) {
142 if (ImGui::IsItemHovered()) {
143 if (
const auto& iterator = pPopupText.find(i); iterator != pPopupText.end()) {
144 ImGui::SetTooltip(
"%s", iterator->second().c_str());
157 requires std::is_enum_v<E>
159 return ImGui::RadioButton(
to_string(value).data(), &buttonStorage,
static_cast<int>(value));
163 requires std::is_enum_v<E>
177 const bool pressed = ImGui::RadioButton(label, v == v_button);
183 template<
class... Args>
184 void TextColored(
const ImVec4& col, std::string_view fmt, Args&&... args) {
185 ImGui::PushStyleColor(ImGuiCol_Text, col);
186 ImGui::TextEx(std::vformat(fmt, std::make_format_args(args...)).c_str(), NULL, ImGuiTextFlags_NoWidthForLargeClippedText);
187 ImGui::PopStyleColor();
202 void KeyInput(
const char* label,
const char*
id,
char* buffer,
size_t bufSize, WPARAM& keyContainer,
const char* notSetText);
215 void OptionalSetting(std::optional<T>& setting,
const char* title,
const char* checkboxLabel, std::function<T()> constructValue, std::function<
void()> children) {
216 ImGui::TextUnformatted(title);
218 bool settingActive = setting.has_value();
220 if (ImGui::Checkbox(checkboxLabel, &settingActive)) {
222 setting = constructValue();
229 ImGui::PushItemFlag(ImGuiItemFlags_Disabled, !settingActive);
234 ImGui::PopItemFlag();
243 template<std::ranges::viewable_range T,
typename ValueType = std::ranges::views::all_t<T>>
245 bool FilteredCombo(
const char* pLabel,
const T& pContainer, ValueType& pCurrent,
bool* pPopupOpen =
nullptr) {
249 ImGuiContext& g = *GImGui;
251 ImGuiWindow* window = ImGui::GetCurrentWindow();
252 if (window->SkipItems)
255 static char searchInputBuffer[256] = {0};
257 std::string popupName = std::format(
"###FilteredCombo_popup_name_{}", pLabel);
261 bool valueChanged =
false;
263 const float expectedWidth = ImGui::CalcItemWidth();
264 bool isNewOpen =
false;
265 float frameHeight = ImGui::GetFrameHeight();
266 ImVec2 size(frameHeight, frameHeight);
267 ImVec2 CursorPos = window->DC.CursorPos;
268 ImVec2 pos = CursorPos + ImVec2(expectedWidth - frameHeight, 0);
269 const ImRect bb(pos, pos + size);
271 float ButtonTextAlignX = g.Style.ButtonTextAlign.x;
272 g.Style.ButtonTextAlign.x = 0;
273 if (ImGui::Button(std::format(
"{}###FilteredCombo_button_label_{}",
to_string(pCurrent), pLabel).c_str(), ImVec2(expectedWidth, 0))) {
274 ImGui::OpenPopup(popupName.c_str());
276 memset(searchInputBuffer, 0,
sizeof searchInputBuffer);
278 g.Style.ButtonTextAlign.x = ButtonTextAlignX;
286 const ImU32 textColor = ImGui::GetColorU32(ImGuiCol_Text);
287 ImGui::RenderArrow(window->DrawList, bb.Min + ImVec2(ImMax(0.0f, (size.x - g.FontSize) * 0.5f), ImMax(0.0f, (size.y - g.FontSize) * 0.5f)), textColor, ImGuiDir_Down);
289 ImVec2 item_max = ImGui::GetItemRectMax();
290 ImGui::SetNextWindowPos({CursorPos.x, item_max.y});
291 ImGui::SetNextWindowSize({ImGui::GetItemRectSize().x, 0});
293 if (ImGui::BeginPopup(popupName.c_str())) {
294 using CacheVectorType = std::tuple<double, ValueType>;
295 static std::vector<CacheVectorType> valueCache;
297 if (pPopupOpen !=
nullptr) {
301 ImGui::PushStyleColor(ImGuiCol_FrameBg, (ImVec4) ImColor(240, 240, 240, 255));
302 ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4) ImColor(0, 0, 0, 255));
303 ImGui::PushItemWidth(-FLT_MIN);
307 ImGui::SetKeyboardFocusHere();
308 for (
const auto& val : pContainer) {
309 valueCache.emplace_back(1, val);
312 if (
ImGui::InputText(
"###FilteredCombo_InputText", searchInputBuffer,
sizeof searchInputBuffer)) {
315 if (searchInputBuffer[0] ==
'\0') {
316 for (
const auto& val : pContainer) {
317 valueCache.emplace_back(1, val);
320 for (
const auto& val : pContainer) {
324 valueCache.emplace_back(ratio, val);
327 std::ranges::sort(valueCache, [](
const CacheVectorType& val1,
const CacheVectorType& val2) {
328 return std::get<0>(val1) > std::get<0>(val2);
338 ImGui::PopStyleColor(2);
340 if (ImGui::ListBoxHeader(
"###FilteredCombo_ItemList")) {
341 for (
const auto& value : valueCache) {
342 const auto& val = std::get<1>(value);
343 const bool itemSelected = (val == pCurrent);
344 if (ImGui::Selectable(
to_string(val).c_str(), itemSelected)) {
347 ImGui::CloseCurrentPopup();
350 ImGui::SetItemDefaultFocus();
352 ImGui::ListBoxFooter();
354 ImGui::PopItemWidth();
360 ImGui::MarkItemEdited(g.CurrentWindow->DC.LastItemId);
370 template<std::ranges::common_range T,
typename ValueType = std::ranges::range_value_t<T>>
371 requires(!std::ranges::viewable_range<T>)
372 bool FilteredCombo(
const char* pLabel,
const T& pContainer, ValueType& pCurrent,
bool* pPopupOpen =
nullptr) {
373 return FilteredCombo(pLabel, std::ranges::views::all(pContainer), pCurrent, pPopupOpen);
std::string_view to_string(Alignment alignment)
Definition arcdps_structs.cpp:7
CornerPosition
Definition arcdps_structs.h:81
Position
Definition arcdps_structs.h:73
Alignment
Definition arcdps_structs.h:64
double ratio(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, double score_cutoff=0)
calculates a simple ratio between two strings
Definition rapidfuzz_amalgamated.hpp:4383
Definition KeyInput.cpp:55
void KeyInput(const char *label, const char *id, char *buffer, size_t bufSize, WPARAM &keyContainer, const char *notSetText)
Definition Widgets.cpp:1199
void TableHeader(const char *label, bool show_label, ImTextureID texture, Alignment alignment)
Definition Widgets.cpp:130
void BeginMenuChild(const char *child_str_id, const char *menu_label, std::function< void()> draw_func)
Definition Widgets.cpp:558
bool BeginTable(const char *str_id, int columns_count, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, ImGuiWindowFlags child_window_flags)
Definition Widgets.cpp:1191
bool Selectable(E &storage, E value)
Definition Widgets.h:64
bool SpinnerAligned(const char *label, float radius, float thickness, const ImU32 &color, Alignment alignment)
Definition Widgets.cpp:59
bool TableIsMouseHoveringCurrentRow()
Definition Widgets.cpp:620
bool FilteredCombo(const char *pLabel, const T &pContainer, ValueType &pCurrent, bool *pPopupOpen=nullptr)
Definition Widgets.h:245
bool EnumRadioButton(int &buttonStorage, E value)
Definition Widgets.h:158
bool EnumCombo(const char *label, E &storage, const R &values, const std::map< E, std::function< std::string()> > &pPopupText={})
Definition Widgets.h:77
bool RadioButton(const char *label, T &v, T v_button)
Definition Widgets.h:176
bool BeginMenu(const char *label, bool enabled, bool &hoveredPar)
Definition Widgets.cpp:403
bool WindowReposition(ImGuiWindow *window, Position position, const ImVec2 &cornerVector, CornerPosition cornerPosition, ImGuiID fromWindowID, CornerPosition anchorPanelCornerPosition, CornerPosition selfPanelCornerPosition)
Definition Widgets.cpp:626
void AlignedTextColumn(Alignment alignment, const char *text,...)
Definition Widgets.cpp:88
void OptionalSetting(std::optional< T > &setting, const char *title, const char *checkboxLabel, std::function< T()> constructValue, std::function< void()> children)
Definition Widgets.h:215
ImRect TableGetCurrentRowRect()
Definition Widgets.cpp:612
void AlignedProgressBar(float fraction, const ImVec2 &size_arg, const char *overlay, Alignment alignment)
Definition Widgets.cpp:325
bool TreeNodeEx(const char *label, ImGuiTreeNodeFlags flags, void *icon)
Definition Widgets.cpp:923
bool Spinner(const char *label, float radius, float thickness, const ImU32 &color)
Definition Widgets.cpp:21
void TextColored(const ImVec4 &col, std::string_view fmt, Args &&... args)
Definition Widgets.h:184
void MenuItemTableColumnVisibility(ImGuiTable *table, int columnIdx)
Definition Widgets.cpp:601
bool BeginPopupContextWindow(const char *str_id, ImGuiPopupFlags popup_flags, ImGuiHoveredFlags hovered_flags)
Definition Widgets.cpp:588
IMGUI_API bool InputText(const char *label, std::string *str, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=nullptr, void *user_data=nullptr)
Definition imgui_stdlib.cpp:38