8#define IMGUI_DEFINE_MATH_OPERATORS
10#include <libultraship/libultraship.h>
11#include <unordered_map>
20 if (data->EventChar < 256 &&
strchr(
"1234567890", (
char)data->EventChar)) {
27 const char* alphanum =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";
28 if (data->EventChar < 256 &&
strchr(alphanum, (
char)data->EventChar)) {
35 std::string
WrappedText(
const char* text,
unsigned int charactersPerLine = 60);
36 std::string
WrappedText(
const std::string& text,
unsigned int charactersPerLine = 60);
90 const ImVec2
Inline = ImVec2(0.0f, 0.0f);
91 const ImVec2
Fill = ImVec2(-1.0f, 0.0f);
179 std::unordered_map<int32_t, const char*>
comboMap = {};
341 bool Button(
const char* label,
const ButtonOptions& options = {});
342 bool WindowButton(
const char* label,
const char* cvarName, std::shared_ptr<Ship::GuiWindow> windowPtr,
const ButtonOptions& options = {});
347 void RenderText(ImVec2 pos,
const char* text,
const char* text_end,
bool hide_text_after_hash);
441 template <
typename T>
442 bool Combobox(
const char* label, T* value,
const std::unordered_map<T, const char*>& comboMap,
const ComboboxOptions& options = {}) {
444 float startX = ImGui::GetCursorPosX();
445 std::string invisibleLabelStr =
"##" + std::string(label);
446 const char* invisibleLabel = invisibleLabelStr.c_str();
447 ImGui::PushID(label);
449 ImGui::BeginDisabled(options.disabled);
453 ImGui::Text(
"%s", label);
454 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
456 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2);
458 ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboMap.at(*value)).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x);
463 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
464 ImGui::Text(
"%s", label);
465 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
467 ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2);
468 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
470 float width = ImGui::CalcTextSize(comboMap.at(*value)).x + ImGui::GetStyle().FramePadding.x * 4;
471 ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
472 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
475 if (ImGui::BeginCombo(invisibleLabel, comboMap.at(*value), options.flags)) {
476 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f));
477 for (
const auto& pair : comboMap) {
478 if (
strlen(pair.second) > 1) {
479 if (ImGui::Selectable(pair.second, pair.first == *value)) {
485 ImGui::PopStyleVar();
491 ImGui::Text(
"%s", label);
493 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
494 ImGui::Text(
"%s", label);
498 ImGui::SameLine(startX);
499 ImGui::Text(
"%s", label);
503 ImGui::EndDisabled();
505 if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.disabledTooltip)) {
506 ImGui::SetTooltip(
"%s",
WrappedText(options.disabledTooltip).c_str());
507 }
else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.tooltip)) {
508 ImGui::SetTooltip(
"%s",
WrappedText(options.tooltip).c_str());
514 template <
typename T =
size_t>
515 bool Combobox(
const char* label, T* value,
const std::vector<const char*>& comboVector,
const ComboboxOptions& options = {}) {
517 float startX = ImGui::GetCursorPosX();
518 size_t currentValueIndex =
static_cast<size_t>(*value);
519 std::string invisibleLabelStr =
"##" + std::string(label);
520 const char* invisibleLabel = invisibleLabelStr.c_str();
521 ImGui::PushID(label);
523 ImGui::BeginDisabled(options.disabled);
528 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
530 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2);
532 ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboVector.at(currentValueIndex)).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x);
537 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
539 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
541 ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2);
542 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
544 float width = ImGui::CalcTextSize(comboVector.at(currentValueIndex)).x + ImGui::GetStyle().FramePadding.x * 4;
545 ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
546 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
549 if (ImGui::BeginCombo(invisibleLabel, comboVector.at(currentValueIndex), options.flags)) {
550 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f));
551 for (
size_t i = 0; i < comboVector.size(); ++i) {
552 auto newValue =
static_cast<T
>(i);
553 if (
strlen(comboVector.at(i)) > 1) {
554 if (ImGui::Selectable(comboVector.at(i), newValue == *value)) {
560 ImGui::PopStyleVar();
568 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
573 ImGui::SameLine(startX);
578 ImGui::EndDisabled();
580 if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.disabledTooltip)) {
581 ImGui::SetTooltip(
"%s",
WrappedText(options.disabledTooltip).c_str());
582 }
else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.tooltip)) {
583 ImGui::SetTooltip(
"%s",
WrappedText(options.tooltip).c_str());
589 template <
typename T =
size_t,
size_t N>
592 float startX = ImGui::GetCursorPosX();
593 size_t currentValueIndex =
static_cast<size_t>(*value);
594 if (currentValueIndex >= N) {
595 currentValueIndex = 0;
597 std::string invisibleLabelStr =
"##" + std::string(label);
598 const char* invisibleLabel = invisibleLabelStr.c_str();
599 ImGui::PushID(label);
601 ImGui::BeginDisabled(options.disabled);
605 ImGui::Text(
"%s", label);
606 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
608 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2);
610 ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboArray[currentValueIndex]).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x);
615 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
616 ImGui::Text(
"%s", label);
617 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
619 ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2);
620 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
622 float width = ImGui::CalcTextSize(comboArray[currentValueIndex]).x + ImGui::GetStyle().FramePadding.x * 4;
623 ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
624 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
627 if (ImGui::BeginCombo(invisibleLabel, comboArray[currentValueIndex], options.flags)) {
628 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f));
629 for (
size_t i = 0; i < N; ++i) {
630 auto newValue =
static_cast<T
>(i);
631 if (
strlen(comboArray[i]) > 1) {
632 if (ImGui::Selectable(comboArray[i], newValue == *value)) {
638 ImGui::PopStyleVar();
644 ImGui::Text(
"%s", label);
646 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
647 ImGui::Text(
"%s", label);
651 ImGui::SameLine(startX);
652 ImGui::Text(
"%s", label);
656 ImGui::EndDisabled();
658 if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.disabledTooltip)) {
659 ImGui::SetTooltip(
"%s",
WrappedText(options.disabledTooltip).c_str());
660 }
else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.tooltip)) {
661 ImGui::SetTooltip(
"%s",
WrappedText(options.tooltip).c_str());
667 template <
typename T =
int32_t>
668 bool CVarCombobox(
const char* label,
const char* cvarName,
const std::unordered_map<T, const char*>& comboMap,
const ComboboxOptions& options = {}) {
670 int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
671 if (
Combobox<T>(label, &value, comboMap, options)) {
672 CVarSetInteger(cvarName, value);
673 Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
679 template <
typename T =
int32_t>
682 int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
683 if (
Combobox<T>(label, &value, comboVector, options)) {
684 CVarSetInteger(cvarName, value);
685 Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
691 template <
typename T =
int32_t,
size_t N>
694 int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
695 if (
Combobox<T>(label, &value, comboArray, options)) {
696 CVarSetInteger(cvarName, value);
697 Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
709 bool CVarColorPicker(
const char* label,
const char* cvarName, Color_RGBA8 defaultColor);
bool Ship_IsCStringEmpty(const char *str)
Definition ShipUtils.cpp:10
#define NULL
Definition miniaudio.h:3851
size_t strlen(const char *str)
Definition string.c:14
char * strchr(const char *str, s32 ch)
Definition string.c:22
Definition UIWidgets.h:18
static int FilterAlphaNum(ImGuiInputTextCallbackData *data)
Definition UIWidgets.h:26
static int FilterNumbers(ImGuiInputTextCallbackData *data)
Definition UIWidgets.h:19