Refactor code

This commit is contained in:
Grinch_ 2021-12-08 13:52:47 -06:00
parent e8374ceac7
commit 7146bc17f4

View File

@ -226,36 +226,35 @@ void Ui::CenterdText(const std::string& text)
void Ui::DrawHeaders(CallbackTable& data) void Ui::DrawHeaders(CallbackTable& data)
{ {
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); static void* pCallback;
static int buttonInRow = 3;
static ImVec2 size = GetSize(buttonInRow, false);
ImGuiStyle &style = ImGui::GetStyle();
ImVec4 buttonCol = style.Colors[ImGuiCol_Button];
short i = 1; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
auto colors = ImGui::GetStyle().Colors;
ImVec4 btn_col = colors[ImGuiCol_Button];
static void* func;
ImGui::PushFont(FontMgr::GetFont("header")); ImGui::PushFont(FontMgr::GetFont("header"));
for (auto it = data.begin(); it != data.end(); ++it) for (int i = 0; i < data.size(); ++i)
{ {
const char* btn_text = it->first.c_str(); const char* btn_text = data[i].first.c_str();
if (btn_text == m_HeaderId) if (btn_text == m_HeaderId)
{ {
colors[ImGuiCol_Button] = colors[ImGuiCol_ButtonActive]; style.Colors[ImGuiCol_Button] = style.Colors[ImGuiCol_ButtonActive];
func = it->second; pCallback = data[i].second;
} }
if (ImGui::Button(btn_text, size))
if (ImGui::Button(btn_text, GetSize(3, false)))
{ {
m_HeaderId = btn_text; m_HeaderId = btn_text;
gConfig.SetValue("window.id", m_HeaderId); gConfig.SetValue("window.id", m_HeaderId);
func = it->second; pCallback = data[i].second;
} }
style.Colors[ImGuiCol_Button] = buttonCol;
colors[ImGuiCol_Button] = btn_col; if (i % 3 != 2)
{
if (i % 3 != 0)
ImGui::SameLine(); ImGui::SameLine();
i++; }
} }
ImGui::PopFont(); ImGui::PopFont();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@ -273,12 +272,16 @@ void Ui::DrawHeaders(CallbackTable& data)
ImGui::TextWrapped("Please ensure you have the latest version from GitHub."); ImGui::TextWrapped("Please ensure you have the latest version from GitHub.");
ImGui::NewLine(); ImGui::NewLine();
if (ImGui::Button("Discord server", ImVec2(GetSize(2)))) if (ImGui::Button("Discord server", ImVec2(GetSize(2))))
{
ShellExecute(nullptr, "open", DISCORD_INVITE, nullptr, nullptr, SW_SHOWNORMAL); ShellExecute(nullptr, "open", DISCORD_INVITE, nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("GitHub repo", ImVec2(GetSize(2)))) if (ImGui::Button("GitHub repo", ImVec2(GetSize(2))))
{
ShellExecute(nullptr, "open", GITHUB_LINK, nullptr, nullptr, SW_SHOWNORMAL); ShellExecute(nullptr, "open", GITHUB_LINK, nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::NewLine(); ImGui::NewLine();
ImGui::TextWrapped("If you find bugs or have suggestions, you can let me know on discord :)"); ImGui::TextWrapped("If you find bugs or have suggestions, you can let me know on discord :)");
@ -287,9 +290,9 @@ void Ui::DrawHeaders(CallbackTable& data)
} }
else else
{ {
if (func != nullptr && ImGui::BeginChild("TABSBAR")) if (pCallback != nullptr && ImGui::BeginChild("TABSBAR"))
{ {
static_cast<void(*)()>(func)(); static_cast<void(*)()>(pCallback)();
ImGui::EndChild(); ImGui::EndChild();
} }
} }