9#include <imgui/imgui.h>
10#include <imgui/imgui_internal.h>
15 bool Spinner(
const char* label,
float radius,
float thickness,
const ImU32& color);
20 bool BeginMenu(
const char* label,
bool enabled,
bool& hovered);
21 void BeginMenuChild(
const char* child_str_id,
const char* menu_label, std::function<
void()> draw_func);
22 void BeginMenu(
const char* menu_label, std::function<
void()> draw_func);
25 bool TreeNodeEx(
const char* label, ImGuiTreeNodeFlags flags,
void* icon);
32 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);
50 requires std::is_enum_v<E>
52 const bool selected = ImGui::Selectable(
to_string(value).c_str());
62 template<
typename E, std::ranges::range R>
63 requires(std::is_enum_v<E> && std::same_as<std::ranges::range_value_t<R>, E>)
64 bool EnumCombo(
const char* label, E& storage,
const R& values,
const std::map<E, std::function<
const std::string&()>>& pPopupText = {}) {
65 if (ImGui::BeginCombo(label,
to_string(storage).c_str())) {
66 bool selected =
false;
67 for (
const E& val : values) {
72 if (ImGui::IsItemHovered()) {
73 if (
const auto& iterator = pPopupText.find(val); iterator != pPopupText.end()) {
74 const auto& second = iterator->second();
75 ImGui::SetTooltip(
"%s", second.c_str());
89 requires(std::is_enum_v<E>)
90 bool EnumCombo(
const char* label, E& storage,
const std::initializer_list<E>& values,
const std::map<E, std::function<
const std::string&()>>& pPopupText = {}) {
91 if (ImGui::BeginCombo(label,
to_string(storage).c_str())) {
92 bool selected =
false;
93 for (
const E& val : values) {
98 if (ImGui::IsItemHovered()) {
99 if (
const auto& iterator = pPopupText.find(val); iterator != pPopupText.end()) {
100 ImGui::SetTooltip(
"%s", iterator->second().c_str());
120 requires std::is_enum_v<E>
121 bool EnumCombo(
const char* label, E& storage, E lastElement,
const std::map<uint64_t, std::function<
const std::string&()>>& pPopupText = {}) {
122 if (ImGui::BeginCombo(label,
to_string(storage).c_str())) {
123 bool selected =
false;
124 for (uint64_t i = 0; i < static_cast<uint64_t>(lastElement); ++i) {
129 if (ImGui::IsItemHovered()) {
130 if (
const auto& iterator = pPopupText.find(i); iterator != pPopupText.end()) {
131 ImGui::SetTooltip(
"%s", iterator->second().c_str());
144 requires std::is_enum_v<E>
146 return ImGui::RadioButton(
to_string(value).c_str(), &buttonStorage,
static_cast<int>(value));
150 requires std::is_enum_v<E>
164 const bool pressed = ImGui::RadioButton(label, v == v_button);
170 template<
class... Args>
171 void TextColored(
const ImVec4& col,
const std::string& fmt, Args&&... args) {
172 ImGui::PushStyleColor(ImGuiCol_Text, col);
173 ImGui::TextEx(std::vformat(fmt, std::make_format_args(args...)).c_str(), NULL, ImGuiTextFlags_NoWidthForLargeClippedText);
174 ImGui::PopStyleColor();
189 void KeyInput(
const char* label,
const char*
id,
char* buffer,
size_t bufSize, WPARAM& keyContainer,
const char* notSetText);
198 template<std::ranges::viewable_range T,
typename ValueType = std::ranges::views::all_t<T>>
200 bool FilteredCombo(
const char* pLabel,
const T& pContainer, ValueType& pCurrent,
bool* pPopupOpen =
nullptr) {
204 ImGuiContext& g = *GImGui;
206 ImGuiWindow* window = ImGui::GetCurrentWindow();
207 if (window->SkipItems)
210 static char searchInputBuffer[256] = {0};
212 std::string popupName = std::format(
"###FilteredCombo_popup_name_{}", pLabel);
216 bool valueChanged =
false;
218 const float expectedWidth = ImGui::CalcItemWidth();
219 bool isNewOpen =
false;
220 float frameHeight = ImGui::GetFrameHeight();
221 ImVec2 size(frameHeight, frameHeight);
222 ImVec2 CursorPos = window->DC.CursorPos;
223 ImVec2 pos = CursorPos + ImVec2(expectedWidth - frameHeight, 0);
224 const ImRect bb(pos, pos + size);
226 float ButtonTextAlignX = g.Style.ButtonTextAlign.x;
227 g.Style.ButtonTextAlign.x = 0;
228 if (ImGui::Button(std::format(
"{}###FilteredCombo_button_label_{}",
to_string(pCurrent), pLabel).c_str(), ImVec2(expectedWidth, 0))) {
229 ImGui::OpenPopup(popupName.c_str());
231 memset(searchInputBuffer, 0,
sizeof searchInputBuffer);
233 g.Style.ButtonTextAlign.x = ButtonTextAlignX;
241 const ImU32 textColor = ImGui::GetColorU32(ImGuiCol_Text);
242 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);
244 ImVec2 item_max = ImGui::GetItemRectMax();
245 ImGui::SetNextWindowPos({CursorPos.x, item_max.y});
246 ImGui::SetNextWindowSize({ImGui::GetItemRectSize().x, 0});
248 if (ImGui::BeginPopup(popupName.c_str())) {
249 using CacheVectorType = std::tuple<double, ValueType>;
250 static std::vector<CacheVectorType> valueCache;
252 if (pPopupOpen !=
nullptr) {
256 ImGui::PushStyleColor(ImGuiCol_FrameBg, (ImVec4) ImColor(240, 240, 240, 255));
257 ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4) ImColor(0, 0, 0, 255));
258 ImGui::PushItemWidth(-FLT_MIN);
262 ImGui::SetKeyboardFocusHere();
263 for (
const auto& val : pContainer) {
264 valueCache.emplace_back(1, val);
267 if (
ImGui::InputText(
"###FilteredCombo_InputText", searchInputBuffer,
sizeof searchInputBuffer)) {
270 if (searchInputBuffer[0] ==
'\0') {
271 for (
const auto& val : pContainer) {
272 valueCache.emplace_back(1, val);
275 for (
const auto& val : pContainer) {
279 valueCache.emplace_back(ratio, val);
282 std::ranges::sort(valueCache, [](
const CacheVectorType& val1,
const CacheVectorType& val2) {
283 return std::get<0>(val1) > std::get<0>(val2);
293 ImGui::PopStyleColor(2);
295 if (ImGui::ListBoxHeader(
"###FilteredCombo_ItemList")) {
296 for (
const auto& value : valueCache) {
297 const auto& val = std::get<1>(value);
298 const bool itemSelected = (val == pCurrent);
299 if (ImGui::Selectable(
to_string(val).c_str(), itemSelected)) {
302 ImGui::CloseCurrentPopup();
305 ImGui::SetItemDefaultFocus();
307 ImGui::ListBoxFooter();
309 ImGui::PopItemWidth();
315 ImGui::MarkItemEdited(g.CurrentWindow->DC.LastItemId);
325 template<std::ranges::common_range T,
typename ValueType = std::ranges::range_value_t<T>>
326 requires(!std::ranges::viewable_range<T>)
327 bool FilteredCombo(
const char* pLabel,
const T& pContainer, ValueType& pCurrent,
bool* pPopupOpen =
nullptr) {
328 return FilteredCombo(pLabel, std::ranges::views::all(pContainer), pCurrent, pPopupOpen);
std::string to_string(Alignment alignment)
Definition arcdps_structs.cpp:6
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:46
void KeyInput(const char *label, const char *id, char *buffer, size_t bufSize, WPARAM &keyContainer, const char *notSetText)
Definition Widgets.cpp:1197
void TableHeader(const char *label, bool show_label, ImTextureID texture, Alignment alignment)
Definition Widgets.cpp:128
void BeginMenuChild(const char *child_str_id, const char *menu_label, std::function< void()> draw_func)
Definition Widgets.cpp:556
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:1189
bool Selectable(E &storage, E value)
Definition Widgets.h:51
bool SpinnerAligned(const char *label, float radius, float thickness, const ImU32 &color, Alignment alignment)
Definition Widgets.cpp:57
bool TableIsMouseHoveringCurrentRow()
Definition Widgets.cpp:618
bool FilteredCombo(const char *pLabel, const T &pContainer, ValueType &pCurrent, bool *pPopupOpen=nullptr)
Definition Widgets.h:200
bool EnumRadioButton(int &buttonStorage, E value)
Definition Widgets.h:145
bool RadioButton(const char *label, T &v, T v_button)
Definition Widgets.h:163
bool BeginMenu(const char *label, bool enabled, bool &hoveredPar)
Definition Widgets.cpp:401
bool WindowReposition(ImGuiWindow *window, Position position, const ImVec2 &cornerVector, CornerPosition cornerPosition, ImGuiID fromWindowID, CornerPosition anchorPanelCornerPosition, CornerPosition selfPanelCornerPosition)
Definition Widgets.cpp:624
void AlignedTextColumn(Alignment alignment, const char *text,...)
Definition Widgets.cpp:86
bool EnumCombo(const char *label, E &storage, const R &values, const std::map< E, std::function< const std::string &()> > &pPopupText={})
Definition Widgets.h:64
void TextColored(const ImVec4 &col, const std::string &fmt, Args &&... args)
Definition Widgets.h:171
ImRect TableGetCurrentRowRect()
Definition Widgets.cpp:610
void AlignedProgressBar(float fraction, const ImVec2 &size_arg, const char *overlay, Alignment alignment)
Definition Widgets.cpp:323
bool TreeNodeEx(const char *label, ImGuiTreeNodeFlags flags, void *icon)
Definition Widgets.cpp:921
bool Spinner(const char *label, float radius, float thickness, const ImU32 &color)
Definition Widgets.cpp:19
void MenuItemTableColumnVisibility(ImGuiTable *table, int columnIdx)
Definition Widgets.cpp:599
bool BeginPopupContextWindow(const char *str_id, ImGuiPopupFlags popup_flags, ImGuiHoveredFlags hovered_flags)
Definition Widgets.cpp:586
IMGUI_API bool InputText(const char *label, std::string *str, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition imgui_stdlib.cpp:36