clang-format .hpp files (#5307)

* Add hpp files to clang-format script

* clang-format hpp files
This commit is contained in:
Archez 2025-04-03 23:33:35 -04:00 committed by GitHub
parent 2deea6e105
commit f37c3aa228
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 1048 additions and 1058 deletions

View file

@ -37,7 +37,7 @@ if (-not (Test-Path $clangFormatFilePath) -or ($currentVersion -ne $requiredVers
$basePath = (Resolve-Path .).Path $basePath = (Resolve-Path .).Path
$files = Get-ChildItem -Path $basePath\soh -Recurse -File ` $files = Get-ChildItem -Path $basePath\soh -Recurse -File `
| Where-Object { ($_.Extension -eq '.c' -or $_.Extension -eq '.cpp' -or ` | Where-Object { ($_.Extension -eq '.c' -or $_.Extension -eq '.cpp' -or `
($_.Extension -eq '.h' -and ` (($_.Extension -eq '.h' -or $_.Extension -eq '.hpp') -and `
(-not ($_.FullName -like "*\soh\src\*" -or $_.FullName -like "*\soh\include\*")))) -and ` (-not ($_.FullName -like "*\soh\src\*" -or $_.FullName -like "*\soh\include\*")))) -and `
(-not ($_.FullName -like "*\soh\assets\*")) } (-not ($_.FullName -like "*\soh\assets\*")) }

View file

@ -10,8 +10,8 @@
# -name "*.c" -o -name "*.cpp" # -name "*.c" -o -name "*.cpp"
# find all .c and .cpp files # find all .c and .cpp files
# #
# -name "*.h" ! -path "soh/src/**.h" ! -path "soh/include/**.h" # ( -name "*.h" -o -name "*.hpp" ) ! -path "soh/src/**.h" ! -path "soh/include/**.h"
# find all .h files that aren't in soh/src or soh/include # find all .h and .hpp files that aren't in soh/src or soh/include
# this is because zret decomp only runs clang-format on c files # this is because zret decomp only runs clang-format on c files
# https://github.com/zeldaret/mm/blob/b7e5468ca16315a7e322055eff3d97fe980bbc25/format.py#L182 # https://github.com/zeldaret/mm/blob/b7e5468ca16315a7e322055eff3d97fe980bbc25/format.py#L182
# #
@ -26,4 +26,4 @@
# and pass it as an argument to clang-format # and pass it as an argument to clang-format
# verbose to print files being formatted and X out of Y status # verbose to print files being formatted and X out of Y status
find soh -type f \( -name "*.c" -o -name "*.cpp" -o \( -name "*.h" ! -path "soh/src/**.h" ! -path "soh/include/**.h" \) \) ! -path "soh/assets/*" -print0 | xargs -0 clang-format-14 -i --verbose find soh -type f \( -name "*.c" -o -name "*.cpp" -o \( \( -name "*.h" -o -name "*.hpp" \) ! -path "soh/src/*" ! -path "soh/include/*" \) \) ! -path "soh/assets/*" -print0 | xargs -0 clang-format-14 -i --verbose

View file

@ -30,4 +30,4 @@ namespace CustomMessages {
std::string IF_NOT_MQ(); std::string IF_NOT_MQ();
std::string MQ_ELSE(); std::string MQ_ELSE();
std::string MQ_END(); std::string MQ_END();
} } // namespace CustomMessages

View file

@ -64,7 +64,9 @@ std::vector<RandomizerCheck> GetEmptyLocations(std::vector<RandomizerCheck> allo
void ProcessRegion(Region* region, GetAccessibleLocationsStruct& gals, RandomizerGet ignore = RG_NONE, void ProcessRegion(Region* region, GetAccessibleLocationsStruct& gals, RandomizerGet ignore = RG_NONE,
bool stopOnBeatable = false, bool addToPlaythrough = false); bool stopOnBeatable = false, bool addToPlaythrough = false);
std::vector<RandomizerCheck> ReachabilitySearch(const std::vector<RandomizerCheck>& allowedLocations, RandomizerGet ignore=RG_NONE, bool calculatingAvailableChecks=false); std::vector<RandomizerCheck> ReachabilitySearch(const std::vector<RandomizerCheck>& allowedLocations,
RandomizerGet ignore = RG_NONE,
bool calculatingAvailableChecks = false);
void GeneratePlaythrough(); void GeneratePlaythrough();

View file

@ -33,7 +33,8 @@ struct HintSetting {
class HintText { class HintText {
public: public:
HintText() = default; HintText() = default;
HintText(CustomMessage clearText_, std::vector<CustomMessage> ambiguousText_ = {}, std::vector<CustomMessage> obscureText_ = {}); HintText(CustomMessage clearText_, std::vector<CustomMessage> ambiguousText_ = {},
std::vector<CustomMessage> obscureText_ = {});
const CustomMessage& GetClear() const; const CustomMessage& GetClear() const;
const CustomMessage& GetObscure() const; const CustomMessage& GetObscure() const;
const CustomMessage& GetObscure(uint8_t selection) const; const CustomMessage& GetObscure(uint8_t selection) const;
@ -64,9 +65,10 @@ struct StaticHintInfo{
int num; int num;
StaticHintInfo() = default; StaticHintInfo() = default;
StaticHintInfo(HintType _type, std::vector<RandomizerHintTextKey> _hintKeys, RandomizerSettingKey _setting, std::variant<bool, uint8_t> _condition, StaticHintInfo(HintType _type, std::vector<RandomizerHintTextKey> _hintKeys, RandomizerSettingKey _setting,
std::vector<RandomizerCheck> _targetChecks, std::vector<RandomizerGet> _targetItems = {}, std::variant<bool, uint8_t> _condition, std::vector<RandomizerCheck> _targetChecks,
std::vector<RandomizerCheck> _hintChecks = {}, bool _yourPocket = false, int _num = 0); std::vector<RandomizerGet> _targetItems = {}, std::vector<RandomizerCheck> _hintChecks = {},
bool _yourPocket = false, int _num = 0);
}; };
RandomizerHintTextKey GetRandomJunkHint(); RandomizerHintTextKey GetRandomJunkHint();

View file

@ -13,4 +13,5 @@
#define DELETE_PRESET 6 #define DELETE_PRESET 6
#define RESET_TO_DEFAULTS 8 #define RESET_TO_DEFAULTS 8
bool GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks, std::string seedInput); bool GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks,
std::string seedInput);

View file

@ -4,6 +4,8 @@
#include "../context.h" #include "../context.h"
namespace Playthrough { namespace Playthrough {
int Playthrough_Init(uint32_t seed, std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks); int Playthrough_Init(uint32_t seed, std::set<RandomizerCheck> excludedLocations,
int Playthrough_Repeat(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks, int count = 1); std::set<RandomizerTrick> enabledTricks);
} int Playthrough_Repeat(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks,
int count = 1);
} // namespace Playthrough

View file

@ -5,8 +5,7 @@
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
template <typename T, typename Predicate> template <typename T, typename Predicate> static void erase_if(std::vector<T>& vector, Predicate pred) {
static void erase_if(std::vector<T>& vector, Predicate pred) {
vector.erase(std::remove_if(begin(vector), end(vector), pred), end(vector)); vector.erase(std::remove_if(begin(vector), end(vector), pred), end(vector));
} }
@ -27,13 +26,11 @@ std::vector<T> FilterAndEraseFromPool(std::vector<T>& vector, Predicate pred) {
return FilterFromPool(vector, pred, true); return FilterFromPool(vector, pred, true);
} }
template <typename T, typename FromPool> template <typename T, typename FromPool> void AddElementsToPool(std::vector<T>& toPool, const FromPool& fromPool) {
void AddElementsToPool(std::vector<T>& toPool, const FromPool& fromPool) {
toPool.insert(toPool.end(), std::cbegin(fromPool), std::cend(fromPool)); toPool.insert(toPool.end(), std::cbegin(fromPool), std::cend(fromPool));
} }
template <typename T, typename Container> template <typename T, typename Container> bool ElementInContainer(T& element, const Container& container) {
bool ElementInContainer(T& element, const Container& container) {
return std::find(container.begin(), container.end(), element) != container.end(); return std::find(container.begin(), container.end(), element) != container.end();
} }

View file

@ -3,5 +3,6 @@
#include <set> #include <set>
namespace RandoMain { namespace RandoMain {
void GenerateRando(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks, std::string seedInput); void GenerateRando(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks,
std::string seedInput);
} }

View file

@ -12,8 +12,7 @@ uint32_t Random(int min, int max);
double RandomDouble(); double RandomDouble();
// Get a random element from a vector or array // Get a random element from a vector or array
template <typename T> template <typename T> T RandomElement(std::vector<T>& vector, bool erase) {
T RandomElement(std::vector<T>& vector, bool erase) {
const auto idx = Random(0, vector.size()); const auto idx = Random(0, vector.size());
const T selected = vector[idx]; const T selected = vector[idx];
if (erase) { if (erase) {
@ -21,17 +20,14 @@ T RandomElement(std::vector<T>& vector, bool erase) {
} }
return selected; return selected;
} }
template <typename Container> template <typename Container> auto& RandomElement(Container& container) {
auto& RandomElement(Container& container) {
return container[Random(0, std::size(container))]; return container[Random(0, std::size(container))];
} }
template <typename Container> template <typename Container> const auto& RandomElement(const Container& container) {
const auto& RandomElement(const Container& container) {
return container[Random(0, std::size(container))]; return container[Random(0, std::size(container))];
} }
template <typename T> template <typename T> const T RandomElementFromSet(const std::set<T>& set) {
const T RandomElementFromSet(const std::set<T>& set) {
if (set.size() == 1) { if (set.size() == 1) {
return *set.begin(); return *set.begin();
} }
@ -46,17 +42,13 @@ const T RandomElementFromSet(const std::set<T>& set) {
// Shuffle items within a vector or array // Shuffle items within a vector or array
// RANDOTODO There's probably a more efficient way to do what this does. // RANDOTODO There's probably a more efficient way to do what this does.
template <typename T> template <typename T> void Shuffle(std::vector<T>& vector) {
void Shuffle(std::vector<T>& vector) { for (std::size_t i = 0; i + 1 < vector.size(); i++) {
for (std::size_t i = 0; i + 1 < vector.size(); i++)
{
std::swap(vector[i], vector[Random(i, vector.size())]); std::swap(vector[i], vector[Random(i, vector.size())]);
} }
} }
template <typename T, std::size_t size> template <typename T, std::size_t size> void Shuffle(std::array<T, size>& arr) {
void Shuffle(std::array<T, size>& arr) { for (std::size_t i = 0; i + 1 < arr.size(); i++) {
for (std::size_t i = 0; i + 1 < arr.size(); i++)
{
std::swap(arr[i], arr[Random(i, arr.size())]); std::swap(arr[i], arr[Random(i, arr.size())]);
} }
} }

View file

@ -16,16 +16,10 @@ struct PriceSettingsStruct {
RandomizerSettingKey tycoonWallet; RandomizerSettingKey tycoonWallet;
RandomizerSettingKey affordable; RandomizerSettingKey affordable;
PriceSettingsStruct(RandomizerSettingKey _main, PriceSettingsStruct(RandomizerSettingKey _main, RandomizerSettingKey _fixedPrice, RandomizerSettingKey _range1,
RandomizerSettingKey _fixedPrice, RandomizerSettingKey _range2, RandomizerSettingKey _noWallet, RandomizerSettingKey _childWallet,
RandomizerSettingKey _range1, RandomizerSettingKey _adultWallet, RandomizerSettingKey _giantWallet,
RandomizerSettingKey _range2, RandomizerSettingKey _tycoonWallet, RandomizerSettingKey _affordable);
RandomizerSettingKey _noWallet,
RandomizerSettingKey _childWallet,
RandomizerSettingKey _adultWallet,
RandomizerSettingKey _giantWallet,
RandomizerSettingKey _tycoonWallet,
RandomizerSettingKey _affordable);
}; };
extern void PlaceVanillaShopItems(); extern void PlaceVanillaShopItems();
@ -34,5 +28,3 @@ extern uint16_t GetRandomPrice(Rando::Location* loc, PriceSettingsStruct priceSe
extern uint16_t GetCheapBalancedPrice(); extern uint16_t GetCheapBalancedPrice();
extern int GetShopsanityReplaceAmount(); extern int GetShopsanityReplaceAmount();
extern Text GetIceTrapName(uint8_t id); extern Text GetIceTrapName(uint8_t id);

View file

@ -10,19 +10,17 @@ class Text {
public: public:
Text() = default; Text() = default;
Text(std::string english_, std::string french_, std::string spanish_) Text(std::string english_, std::string french_, std::string spanish_)
: english(std::move(english_)), : english(std::move(english_)), french(std::move(french_)), spanish(std::move(spanish_)),
french(std::move(french_)),
spanish(std::move(spanish_)),
german(std::move("")) { german(std::move("")) {
// german defaults to english text until a translation is provided. // german defaults to english text until a translation is provided.
german = english; german = english;
} }
Text(std::string english_, std::string french_, std::string spanish_, std::string german_) Text(std::string english_, std::string french_, std::string spanish_, std::string german_)
: english(std::move(english_)), : english(std::move(english_)), french(std::move(french_)), spanish(std::move(spanish_)),
french(std::move(french_)), german(std::move(german_)) {
spanish(std::move(spanish_)), }
german(std::move(german_)) {} Text(std::string english_)
Text(std::string english_) : english(std::move(english_)), french(std::move("")), spanish(std::move("")), german(std::move("")) { : english(std::move(english_)), french(std::move("")), spanish(std::move("")), german(std::move("")) {
// default unprovided languages to english text // default unprovided languages to english text
french = spanish = german = english; french = spanish = german = english;
} }

View file

@ -36,10 +36,11 @@ namespace SohGui {
void SetupGuiElements(); void SetupGuiElements();
void Draw(); void Draw();
void Destroy(); void Destroy();
void RegisterPopup(std::string title, std::string message, std::string button1 = "OK", std::string button2 = "", std::function<void()> button1callback = nullptr, std::function<void()> button2callback = nullptr); void RegisterPopup(std::string title, std::string message, std::string button1 = "OK", std::string button2 = "",
std::function<void()> button1callback = nullptr, std::function<void()> button2callback = nullptr);
void ShowRandomizerSettingsMenu(); void ShowRandomizerSettingsMenu();
UIWidgets::Colors GetMenuThemeColor(); UIWidgets::Colors GetMenuThemeColor();
} } // namespace SohGui
#define THEME_COLOR SohGui::GetMenuThemeColor() #define THEME_COLOR SohGui::GetMenuThemeColor()

View file

@ -35,7 +35,8 @@ namespace UIWidgets {
std::string WrappedText(const char* text, unsigned int charactersPerLine = 80); std::string WrappedText(const char* text, unsigned int charactersPerLine = 80);
std::string WrappedText(const std::string& text, unsigned int charactersPerLine = 80); std::string WrappedText(const std::string& text, unsigned int charactersPerLine = 80);
void PaddedSeparator(bool padTop = true, bool padBottom = true, float extraVerticalTopPadding = 0.0f, float extraVerticalBottomPadding = 0.0f); void PaddedSeparator(bool padTop = true, bool padBottom = true, float extraVerticalTopPadding = 0.0f,
float extraVerticalBottomPadding = 0.0f);
void Tooltip(const char* text); void Tooltip(const char* text);
typedef enum ColorPickerModifiers { typedef enum ColorPickerModifiers {
@ -71,39 +72,26 @@ namespace UIWidgets {
NoColor NoColor
}; };
enum InputTypes { enum InputTypes { String, Scalar };
String,
Scalar
};
const std::unordered_map<Colors, ImVec4> ColorValues = { const std::unordered_map<Colors, ImVec4> ColorValues = {
{ Colors::Pink, ImVec4(0.87f, 0.3f, 0.87f, 1.0f) }, { Colors::Pink, ImVec4(0.87f, 0.3f, 0.87f, 1.0f) }, { Colors::Red, ImVec4(0.55f, 0.0f, 0.0f, 1.0f) },
{ Colors::Red, ImVec4(0.55f, 0.0f, 0.0f, 1.0f) }, { Colors::DarkRed, ImVec4(0.3f, 0.0f, 0.0f, 1.0f) }, { Colors::Orange, ImVec4(0.85f, 0.55f, 0.0f, 1.0f) },
{ Colors::DarkRed, ImVec4(0.3f, 0.0f, 0.0f, 1.0f) }, { Colors::Yellow, ImVec4(0.95f, 0.95f, 0.0f, 1.0f) }, { Colors::Green, ImVec4(0.0f, 0.55f, 0.0f, 1.0f) },
{ Colors::Orange, ImVec4(0.85f, 0.55f, 0.0f, 1.0f) }, { Colors::DarkGreen, ImVec4(0.0f, 0.3f, 0.0f, 1.0f) }, { Colors::Cyan, ImVec4(0.0f, 0.9f, 0.9f, 1.0f) },
{ Colors::Yellow, ImVec4(0.95f, 0.95f, 0.0f, 1.0f) }, { Colors::LightBlue, ImVec4(0.0f, 0.24f, 0.8f, 1.0f) }, { Colors::Blue, ImVec4(0.08f, 0.03f, 0.65f, 1.0f) },
{ Colors::Green, ImVec4(0.0f, 0.55f, 0.0f, 1.0f) }, { Colors::DarkBlue, ImVec4(0.03f, 0.0f, 0.5f, 1.0f) }, { Colors::Indigo, ImVec4(0.35f, 0.0f, 0.87f, 1.0f) },
{ Colors::DarkGreen, ImVec4(0.0f, 0.3f, 0.0f, 1.0f) }, { Colors::Violet, ImVec4(0.5f, 0.0f, 0.9f, 1.0f) }, { Colors::Purple, ImVec4(0.31f, 0.0f, 0.67f, 1.0f) },
{ Colors::Cyan, ImVec4(0.0f, 0.9f, 0.9f, 1.0f) }, { Colors::Brown, ImVec4(0.37f, 0.18f, 0.0f, 1.0f) }, { Colors::LightGray, ImVec4(0.75f, 0.75f, 0.75f, 1.0f) },
{ Colors::LightBlue, ImVec4(0.0f, 0.24f, 0.8f, 1.0f) }, { Colors::Gray, ImVec4(0.45f, 0.45f, 0.45f, 1.0f) }, { Colors::DarkGray, ImVec4(0.15f, 0.15f, 0.15f, 1.0f) },
{ Colors::Blue, ImVec4(0.08f, 0.03f, 0.65f, 1.0f) }, { Colors::Black, ImVec4(0.0f, 0.0f, 0.0f, 1.0f) }, { Colors::White, ImVec4(1.0f, 1.0f, 1.0f, 1.0f) },
{ Colors::DarkBlue, ImVec4(0.03f, 0.0f, 0.5f, 1.0f) },
{ Colors::Indigo, ImVec4(0.35f, 0.0f, 0.87f, 1.0f) },
{ Colors::Violet, ImVec4(0.5f, 0.0f, 0.9f, 1.0f) },
{ Colors::Purple, ImVec4(0.31f, 0.0f, 0.67f, 1.0f) },
{ Colors::Brown, ImVec4(0.37f, 0.18f, 0.0f, 1.0f) },
{ Colors::LightGray, ImVec4(0.75f, 0.75f, 0.75f, 1.0f) },
{ Colors::Gray, ImVec4(0.45f, 0.45f, 0.45f, 1.0f) },
{ Colors::DarkGray, ImVec4(0.15f, 0.15f, 0.15f, 1.0f) },
{ Colors::Black, ImVec4(0.0f, 0.0f, 0.0f, 1.0f)},
{ Colors::White, ImVec4(1.0f, 1.0f, 1.0f, 1.0f) },
{ Colors::NoColor, ImVec4(0.0f, 0.0f, 0.0f, 0.0f) }, { Colors::NoColor, ImVec4(0.0f, 0.0f, 0.0f, 0.0f) },
}; };
namespace Sizes { namespace Sizes {
const ImVec2 Inline = ImVec2(0.0f, 0.0f); const ImVec2 Inline = ImVec2(0.0f, 0.0f);
const ImVec2 Fill = ImVec2(-1.0f, 0.0f); const ImVec2 Fill = ImVec2(-1.0f, 0.0f);
} } // namespace Sizes
enum LabelPositions { enum LabelPositions {
Near, Near,
@ -491,7 +479,8 @@ namespace UIWidgets {
void PushStyleButton(Colors color = Colors::Gray, ImVec2 padding = ImVec2(10.0f, 8.0f)); void PushStyleButton(Colors color = Colors::Gray, ImVec2 padding = ImVec2(10.0f, 8.0f));
void PopStyleButton(); void PopStyleButton();
bool Button(const char* label, const ButtonOptions& options = {}); bool Button(const char* label, const ButtonOptions& options = {});
bool WindowButton(const char* label, const char* cvarName, std::shared_ptr<Ship::GuiWindow> windowPtr, const WindowButtonOptions& options = {}); bool WindowButton(const char* label, const char* cvarName, std::shared_ptr<Ship::GuiWindow> windowPtr,
const WindowButtonOptions& options = {});
void PushStyleCheckbox(const ImVec4& color); void PushStyleCheckbox(const ImVec4& color);
void PushStyleCheckbox(Colors color = Colors::LightBlue); void PushStyleCheckbox(Colors color = Colors::LightBlue);
@ -523,7 +512,8 @@ namespace UIWidgets {
float CalcComboWidth(const char* preview_value, ImGuiComboFlags flags); float CalcComboWidth(const char* preview_value, ImGuiComboFlags flags);
template <typename T> template <typename T>
bool Combobox(const char* label, T* value, const std::unordered_map<T, const char*>& comboMap, const ComboboxOptions& options = {}) { bool Combobox(const char* label, T* value, const std::unordered_map<T, const char*>& comboMap,
const ComboboxOptions& options = {}) {
bool dirty = false; bool dirty = false;
float startX = ImGui::GetCursorPosX(); float startX = ImGui::GetCursorPosX();
std::string invisibleLabelStr = "##" + std::string(label); std::string invisibleLabelStr = "##" + std::string(label);
@ -593,7 +583,8 @@ namespace UIWidgets {
PopStyleCombobox(); PopStyleCombobox();
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::EndGroup(); ImGui::EndGroup();
if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) &&
!Ship_IsCStringEmpty(options.disabledTooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str());
} else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str());
@ -603,7 +594,8 @@ namespace UIWidgets {
} }
template <typename T = size_t> template <typename T = size_t>
bool Combobox(const char* label, T* value, const std::vector<const char*>& comboVector, const ComboboxOptions& options = {}) { bool Combobox(const char* label, T* value, const std::vector<const char*>& comboVector,
const ComboboxOptions& options = {}) {
bool dirty = false; bool dirty = false;
size_t currentValueIndex = static_cast<size_t>(*value); size_t currentValueIndex = static_cast<size_t>(*value);
std::string invisibleLabelStr = "##" + std::string(label); std::string invisibleLabelStr = "##" + std::string(label);
@ -675,7 +667,8 @@ namespace UIWidgets {
PopStyleCombobox(); PopStyleCombobox();
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::EndGroup(); ImGui::EndGroup();
if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) &&
!Ship_IsCStringEmpty(options.disabledTooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str());
} else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str());
@ -685,7 +678,8 @@ namespace UIWidgets {
} }
template <typename T = size_t> template <typename T = size_t>
bool Combobox(const char* label, T* value, const std::vector<std::string>& comboVector, const ComboboxOptions& options = {}) { bool Combobox(const char* label, T* value, const std::vector<std::string>& comboVector,
const ComboboxOptions& options = {}) {
bool dirty = false; bool dirty = false;
size_t currentValueIndex = static_cast<size_t>(*value); size_t currentValueIndex = static_cast<size_t>(*value);
std::string invisibleLabelStr = "##" + std::string(label); std::string invisibleLabelStr = "##" + std::string(label);
@ -747,7 +741,8 @@ namespace UIWidgets {
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("%s", label); ImGui::Text("%s", label);
} else if (options.labelPosition == LabelPositions::Far) { } else if (options.labelPosition == LabelPositions::Far) {
float width = ImGui::CalcTextSize(comboVector.at(*value).c_str()).x + ImGui::GetStyle().FramePadding.x * 2; float width =
ImGui::CalcTextSize(comboVector.at(*value).c_str()).x + ImGui::GetStyle().FramePadding.x * 2;
ImGui::SameLine(ImGui::GetContentRegionAvail().x - width); ImGui::SameLine(ImGui::GetContentRegionAvail().x - width);
ImGui::Text("%s", label); ImGui::Text("%s", label);
} }
@ -757,7 +752,8 @@ namespace UIWidgets {
PopStyleCombobox(); PopStyleCombobox();
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::EndGroup(); ImGui::EndGroup();
if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) &&
!Ship_IsCStringEmpty(options.disabledTooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str());
} else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str());
@ -841,7 +837,8 @@ namespace UIWidgets {
PopStyleCombobox(); PopStyleCombobox();
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::EndGroup(); ImGui::EndGroup();
if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) &&
!Ship_IsCStringEmpty(options.disabledTooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str());
} else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) {
ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str());
@ -851,7 +848,8 @@ namespace UIWidgets {
} }
template <typename T = int32_t> template <typename T = int32_t>
bool CVarCombobox(const char* label, const char* cvarName, const std::unordered_map<T, const char*>& comboMap, const ComboboxOptions& options = {}) { bool CVarCombobox(const char* label, const char* cvarName, const std::unordered_map<T, const char*>& comboMap,
const ComboboxOptions& options = {}) {
bool dirty = false; bool dirty = false;
int32_t value = CVarGetInteger(cvarName, options.defaultIndex); int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
if (Combobox<T>(label, &value, comboMap, options)) { if (Combobox<T>(label, &value, comboMap, options)) {
@ -864,7 +862,8 @@ namespace UIWidgets {
} }
template <typename T = int32_t> template <typename T = int32_t>
bool CVarCombobox(const char* label, const char* cvarName, const std::vector<const char*>& comboVector, const ComboboxOptions& options = {}) { bool CVarCombobox(const char* label, const char* cvarName, const std::vector<const char*>& comboVector,
const ComboboxOptions& options = {}) {
bool dirty = false; bool dirty = false;
int32_t value = CVarGetInteger(cvarName, options.defaultIndex); int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
if (Combobox<T>(label, &value, comboVector, options)) { if (Combobox<T>(label, &value, comboVector, options)) {
@ -877,7 +876,8 @@ namespace UIWidgets {
} }
template <typename T = int32_t, size_t N> template <typename T = int32_t, size_t N>
bool CVarCombobox(const char* label, const char* cvarName, const char* (&comboArray)[N], const ComboboxOptions& options = {}) { bool CVarCombobox(const char* label, const char* cvarName, const char* (&comboArray)[N],
const ComboboxOptions& options = {}) {
bool dirty = false; bool dirty = false;
int32_t value = CVarGetInteger(cvarName, options.defaultIndex); int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
if (Combobox<T>(label, &value, comboArray, options)) { if (Combobox<T>(label, &value, comboArray, options)) {
@ -899,10 +899,12 @@ namespace UIWidgets {
bool CVarInputString(const char* label, const char* cvarName, const InputOptions& options = {}); bool CVarInputString(const char* label, const char* cvarName, const InputOptions& options = {});
bool InputInt(const char* label, int32_t* value, const InputOptions& options = {}); bool InputInt(const char* label, int32_t* value, const InputOptions& options = {});
bool CVarInputInt(const char* label, const char* cvarName, const InputOptions& options = {}); bool CVarInputInt(const char* label, const char* cvarName, const InputOptions& options = {});
bool CVarColorPicker(const char* label, const char* cvarName, Color_RGBA8 defaultColor, bool hasAlpha = false, uint8_t modifiers = 0, UIWidgets::Colors themeColor = UIWidgets::Colors::LightBlue); bool CVarColorPicker(const char* label, const char* cvarName, Color_RGBA8 defaultColor, bool hasAlpha = false,
uint8_t modifiers = 0, UIWidgets::Colors themeColor = UIWidgets::Colors::LightBlue);
bool RadioButton(const char* label, bool active); bool RadioButton(const char* label, bool active);
bool CVarRadioButton(const char* text, const char* cvarName, int32_t id, const RadioButtonsOptions& options); bool CVarRadioButton(const char* text, const char* cvarName, int32_t id, const RadioButtonsOptions& options);
bool StateButton(const char* str_id, const char* label, ImVec2 size, UIWidgets::ButtonOptions options, ImGuiButtonFlags flags = ImGuiButtonFlags_None); bool StateButton(const char* str_id, const char* label, ImVec2 size, UIWidgets::ButtonOptions options,
ImGuiButtonFlags flags = ImGuiButtonFlags_None);
void DrawFlagArray32(const std::string& name, uint32_t& flags, Colors color = Colors::LightBlue); void DrawFlagArray32(const std::string& name, uint32_t& flags, Colors color = Colors::LightBlue);
void DrawFlagArray16(const std::string& name, uint16_t& flags, Colors color = Colors::LightBlue); void DrawFlagArray16(const std::string& name, uint16_t& flags, Colors color = Colors::LightBlue);
void DrawFlagArray8(const std::string& name, uint8_t& flags, Colors color = Colors::LightBlue); void DrawFlagArray8(const std::string& name, uint8_t& flags, Colors color = Colors::LightBlue);
@ -910,7 +912,7 @@ namespace UIWidgets {
void InsertHelpHoverText(const std::string& text); void InsertHelpHoverText(const std::string& text);
void InsertHelpHoverText(const char* text); void InsertHelpHoverText(const char* text);
} } // namespace UIWidgets
ImVec4 GetRandomValue(); ImVec4 GetRandomValue();
Color_RGBA8 RGBA8FromVec(ImVec4 vec); Color_RGBA8 RGBA8FromVec(ImVec4 vec);