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);
174 std::unordered_map<int32_t, const char*>
comboMap = {};
336 bool Button(
const char* label,
const ButtonOptions& options = {});
337 bool WindowButton(
const char* label,
const char* cvarName, std::shared_ptr<Ship::GuiWindow> windowPtr,
const ButtonOptions& options = {});
342 void RenderText(ImVec2 pos,
const char* text,
const char* text_end,
bool hide_text_after_hash);
436 template <
typename T>
437 bool Combobox(
const char* label, T* value,
const std::unordered_map<T, const char*>& comboMap,
const ComboboxOptions& options = {}) {
439 float startX = ImGui::GetCursorPosX();
440 std::string invisibleLabelStr =
"##" + std::string(label);
441 const char* invisibleLabel = invisibleLabelStr.c_str();
442 ImGui::PushID(label);
444 ImGui::BeginDisabled(options.disabled);
448 ImGui::Text(
"%s", label);
449 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
451 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2);
453 ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboMap.at(*value)).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x);
458 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
459 ImGui::Text(
"%s", label);
460 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
462 ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2);
463 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
465 float width = ImGui::CalcTextSize(comboMap.at(*value)).x + ImGui::GetStyle().FramePadding.x * 4;
466 ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
467 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
470 if (ImGui::BeginCombo(invisibleLabel, comboMap.at(*value), options.flags)) {
471 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f));
472 for (
const auto& pair : comboMap) {
473 if (
strlen(pair.second) > 1) {
474 if (ImGui::Selectable(pair.second, pair.first == *value)) {
480 ImGui::PopStyleVar();
486 ImGui::Text(
"%s", label);
488 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
489 ImGui::Text(
"%s", label);
493 ImGui::SameLine(startX);
494 ImGui::Text(
"%s", label);
498 ImGui::EndDisabled();
500 if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.disabledTooltip)) {
501 ImGui::SetTooltip(
"%s",
WrappedText(options.disabledTooltip).c_str());
502 }
else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.tooltip)) {
503 ImGui::SetTooltip(
"%s",
WrappedText(options.tooltip).c_str());
509 template <
typename T =
size_t>
510 bool Combobox(
const char* label, T* value,
const std::vector<const char*>& comboVector,
const ComboboxOptions& options = {}) {
512 float startX = ImGui::GetCursorPosX();
513 size_t currentValueIndex =
static_cast<size_t>(*value);
514 std::string invisibleLabelStr =
"##" + std::string(label);
515 const char* invisibleLabel = invisibleLabelStr.c_str();
516 ImGui::PushID(label);
518 ImGui::BeginDisabled(options.disabled);
523 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
525 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2);
527 ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboVector.at(currentValueIndex)).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x);
532 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
534 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
536 ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2);
537 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
539 float width = ImGui::CalcTextSize(comboVector.at(currentValueIndex)).x + ImGui::GetStyle().FramePadding.x * 4;
540 ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
541 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
544 if (ImGui::BeginCombo(invisibleLabel, comboVector.at(currentValueIndex), options.flags)) {
545 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f));
546 for (
size_t i = 0; i < comboVector.size(); ++i) {
547 auto newValue =
static_cast<T
>(i);
548 if (
strlen(comboVector.at(i)) > 1) {
549 if (ImGui::Selectable(comboVector.at(i), newValue == *value)) {
555 ImGui::PopStyleVar();
563 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
568 ImGui::SameLine(startX);
573 ImGui::EndDisabled();
575 if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.disabledTooltip)) {
576 ImGui::SetTooltip(
"%s",
WrappedText(options.disabledTooltip).c_str());
577 }
else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.tooltip)) {
578 ImGui::SetTooltip(
"%s",
WrappedText(options.tooltip).c_str());
584 template <
typename T =
size_t,
size_t N>
587 float startX = ImGui::GetCursorPosX();
588 size_t currentValueIndex =
static_cast<size_t>(*value);
589 if (currentValueIndex >= N) {
590 currentValueIndex = 0;
592 std::string invisibleLabelStr =
"##" + std::string(label);
593 const char* invisibleLabel = invisibleLabelStr.c_str();
594 ImGui::PushID(label);
596 ImGui::BeginDisabled(options.disabled);
600 ImGui::Text(
"%s", label);
601 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
603 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2);
605 ImGui::SetNextItemWidth(ImGui::CalcTextSize(comboArray[currentValueIndex]).x + ImGui::GetStyle().FramePadding.x * 4 + ImGui::GetStyle().ItemSpacing.x);
610 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
611 ImGui::Text(
"%s", label);
612 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
614 ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2);
615 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
617 float width = ImGui::CalcTextSize(comboArray[currentValueIndex]).x + ImGui::GetStyle().FramePadding.x * 4;
618 ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
619 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
622 if (ImGui::BeginCombo(invisibleLabel, comboArray[currentValueIndex], options.flags)) {
623 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10.0f, 10.0f));
624 for (
size_t i = 0; i < N; ++i) {
625 auto newValue =
static_cast<T
>(i);
626 if (
strlen(comboArray[i]) > 1) {
627 if (ImGui::Selectable(comboArray[i], newValue == *value)) {
633 ImGui::PopStyleVar();
639 ImGui::Text(
"%s", label);
641 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x);
642 ImGui::Text(
"%s", label);
646 ImGui::SameLine(startX);
647 ImGui::Text(
"%s", label);
651 ImGui::EndDisabled();
653 if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.disabledTooltip)) {
654 ImGui::SetTooltip(
"%s",
WrappedText(options.disabledTooltip).c_str());
655 }
else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !
Ship_IsCStringEmpty(options.tooltip)) {
656 ImGui::SetTooltip(
"%s",
WrappedText(options.tooltip).c_str());
662 template <
typename T =
int32_t>
663 bool CVarCombobox(
const char* label,
const char* cvarName,
const std::unordered_map<T, const char*>& comboMap,
const ComboboxOptions& options = {}) {
665 int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
666 if (
Combobox<T>(label, &value, comboMap, options)) {
667 CVarSetInteger(cvarName, value);
668 Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
674 template <
typename T =
int32_t>
677 int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
678 if (
Combobox<T>(label, &value, comboVector, options)) {
679 CVarSetInteger(cvarName, value);
680 Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
686 template <
typename T =
int32_t,
size_t N>
689 int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
690 if (
Combobox<T>(label, &value, comboArray, options)) {
691 CVarSetInteger(cvarName, value);
692 Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
704 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