clang-format

This commit is contained in:
Guillaume Meunier
2024-03-30 17:00:34 +01:00
parent bb660cfb3f
commit 9cceaac648
122 changed files with 2904 additions and 2783 deletions
+43 -56
View File
@@ -21,11 +21,11 @@
#include "application.h"
#include "imgui.h"
#include "implot.h"
#include "imgui_internal.h"
#include "implot.h"
#include "lobby.h"
#include "version.h"
#include "stream.h"
#include "version.h"
#include <spdlog/fmt/fmt.h>
#include <utils/strings.h>
@@ -35,7 +35,7 @@
#include "IconsFontAwesome6.h"
static void CenterTextH(const std::string& text)
static void CenterTextH(const std::string & text)
{
float win_width = ImGui::GetWindowSize().x;
float text_width = ImGui::CalcTextSize(text.c_str()).x;
@@ -44,20 +44,20 @@ static void CenterTextH(const std::string& text)
ImGui::Text("%s", text.c_str());
}
static void CenterTextHV(const std::string& text)
static void CenterTextHV(const std::string & text)
{
ImVec2 size = ImGui::GetWindowSize();
std::vector<std::string> lines = utils::split(text);
float text_height = 0;
for(const auto& i: lines)
for (const auto & i: lines)
text_height += ImGui::CalcTextSize(i.c_str()).y;
ImGui::SetCursorPosY((size.y - text_height) / 2);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 0});
for(const auto& i: lines)
for (const auto & i: lines)
{
float text_width = ImGui::CalcTextSize(i.c_str()).x;
ImGui::SetCursorPosX((size.x - text_width) / 2);
@@ -98,7 +98,6 @@ void scenes::lobby::gui_connecting()
ImGui::Dummy({1000, 1});
ImGui::PushFont(imgui_ctx->large_font);
CenterTextH(fmt::format("Connection to {}", server_name));
ImGui::PopFont();
@@ -175,19 +174,17 @@ void scenes::lobby::gui_add_server()
if (ImGui::Button("Save", button_size))
{
current_tab = tab::server_list;
server_data data
{
.manual = true,
.service = {
.name = add_server_window_prettyname,
.hostname = add_server_window_hostname,
.port = add_server_window_port,
},
server_data data{
.manual = true,
.service = {
.name = add_server_window_prettyname,
.hostname = add_server_window_hostname,
.port = add_server_window_port,
},
};
servers.emplace("manual-" + data.service.name, data);
save_config();
}
vibrate_on_hover();
}
@@ -196,14 +193,14 @@ void scenes::lobby::gui_server_list()
{
// Build an index of the cookies sorted by server name
std::multimap<std::string, std::string> sorted_cookies;
for(auto&& [cookie, data]: servers)
for (auto && [cookie, data]: servers)
{
sorted_cookies.emplace(data.service.name, cookie);
}
const ImVec2 button_size(220, 80);
const float list_item_height = 100;
auto& style = ImGui::GetStyle();
auto & style = ImGui::GetStyle();
std::string cookie_to_remove;
if (sorted_cookies.empty())
@@ -220,9 +217,9 @@ void scenes::lobby::gui_server_list()
ImGui::PushStyleColor(ImGuiCol_Header, 0);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, 0);
ImGui::PushStyleColor(ImGuiCol_HeaderActive, 0);
for(const auto& [name, cookie]: sorted_cookies)
for (const auto & [name, cookie]: sorted_cookies)
{
server_data& data = servers.at(cookie);
server_data & data = servers.at(cookie);
bool is_selected = (cookie == selected_item);
ImGui::SetCursorPos(pos);
@@ -247,7 +244,7 @@ void scenes::lobby::gui_server_list()
// TODO
// if (ImGui::IsItemHovered())
// {
// ImGui::SetTooltip("Tooltip");
// ImGui::SetTooltip("Tooltip");
// }
ImVec2 button_position(ImGui::GetWindowContentRegionMax().x - style.WindowPadding.x - 20, pos.y + (list_item_height - button_size.y) / 2);
@@ -259,15 +256,15 @@ void scenes::lobby::gui_server_list()
ImGui::BeginDisabled(!enable_connect_button);
if (enable_connect_button)
{
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.8f, 0.3f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.8f, 0.3f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.8f, 0.3f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 1.0f, 0.2f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 1.0f, 0.2f, 1.00f));
}
else
{
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.3f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.3f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.4f, 0.3f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 1.00f));
}
if (ImGui::Button(("Connect##" + cookie).c_str(), button_size))
{
@@ -291,9 +288,9 @@ void scenes::lobby::gui_server_list()
if (data.manual)
{
ImGui::SetCursorPos(button_position);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
if (ImGui::Button(("Remove##" + cookie).c_str(), button_size))
cookie_to_remove = cookie;
@@ -316,13 +313,10 @@ void scenes::lobby::gui_server_list()
if ((async_session.valid() || next_scene) && !ImGui::IsPopupOpen("connecting"))
ImGui::OpenPopup("connecting");
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20,20));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 10);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 2);
if (ImGui::BeginPopupModal("connecting", nullptr,
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove))
if (ImGui::BeginPopupModal("connecting", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove))
{
gui_connecting();
ImGui::EndPopup();
@@ -404,11 +398,9 @@ void scenes::lobby::gui_settings()
float win_width = ImGui::GetWindowSize().x;
float win_height = ImGui::GetWindowSize().y;
ImVec2 plot_size{
win_width / 2 - style.ItemSpacing.x / 2,
win_height / 2
};
win_width / 2 - style.ItemSpacing.x / 2,
win_height / 2};
static std::array<float, 300> cpu_time;
static std::array<float, 300> gpu_time;
@@ -417,7 +409,6 @@ void scenes::lobby::gui_settings()
float min_v = 0;
float max_v = 20;
cpu_time[offset] = application::get_cpu_time().count() * 1.0e-6;
gpu_time[offset] = renderer->get_gpu_time() * 1'000;
offset = (offset + 1) % cpu_time.size();
@@ -428,7 +419,7 @@ void scenes::lobby::gui_settings()
ImPlot::PushStyleColor(ImPlotCol_AxisBgActive, IM_COL32(0, 0, 0, 0));
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, IM_COL32(0, 0, 0, 0));
if (ImPlot::BeginPlot("CPU time", plot_size, ImPlotFlags_CanvasOnly|ImPlotFlags_NoChild))
if (ImPlot::BeginPlot("CPU time", plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
{
auto col = ImPlot::GetColormapColor(0);
@@ -442,11 +433,11 @@ void scenes::lobby::gui_settings()
ImGui::SameLine();
if (ImPlot::BeginPlot("GPU time", plot_size, ImPlotFlags_CanvasOnly|ImPlotFlags_NoChild))
if (ImPlot::BeginPlot("GPU time", plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
{
auto col = ImPlot::GetColormapColor(1);
ImPlot::SetupAxes(nullptr,"GPU time [ms]", ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxes(nullptr, "GPU time [ms]", ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxesLimits(0, gpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
ImPlot::SetNextLineStyle(col);
ImPlot::SetNextFillStyle(col, 0.25);
@@ -512,7 +503,7 @@ static bool RadioButtonWithoutCheckBox(const char * label, bool active, ImVec2 s
return pressed;
}
template<typename T>
template <typename T>
static bool RadioButtonWithoutCheckBox(const char * label, T * v, T v_button, ImVec2 size_arg)
{
const bool pressed = RadioButtonWithoutCheckBox(label, *v == v_button, size_arg);
@@ -524,8 +515,8 @@ static bool RadioButtonWithoutCheckBox(const char * label, T * v, T v_button, Im
static void ScrollWhenDraggingOnVoid(ImVec2 delta)
{
// https://github.com/ocornut/imgui/issues/3379#issuecomment-1678718752
ImGuiContext& g = *ImGui::GetCurrentContext();
ImGuiWindow* window = g.CurrentWindow;
ImGuiContext & g = *ImGui::GetCurrentContext();
ImGuiWindow * window = g.CurrentWindow;
bool hovered = false;
bool held = false;
ImGuiID id = window->GetID("##scrolldraggingoverlay");
@@ -567,10 +558,7 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
// ImGui::SetNextWindowPos({0, 0});
// ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size);
ImGui::Begin("WiVRn", nullptr,
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove);
ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
ImGui::SetCursorPos({MinTabWidth + 20, 0});
@@ -579,7 +567,7 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
ImGui::SetCursorPosY(20);
switch(current_tab)
switch (current_tab)
{
case tab::server_list:
gui_server_list();
@@ -607,7 +595,7 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
ImGui::SetScrollY(0);
}
ImGui::Dummy(ImVec2(0,20));
ImGui::Dummy(ImVec2(0, 20));
ImVec2 mouse_delta = ImGui::GetIO().MouseDelta;
ScrollWhenDraggingOnVoid(ImVec2(0.0f, -mouse_delta.y));
@@ -622,21 +610,20 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
static float TabWidth = MinTabWidth;
ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y});
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10,10));
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " Server list", &current_tab, tab::server_list, {TabWidth, 0});
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " Server list", &current_tab, tab::server_list, {TabWidth, 0});
vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_GEARS " Settings", &current_tab, tab::settings, {TabWidth, 0});
RadioButtonWithoutCheckBox(ICON_FA_GEARS " Settings", &current_tab, tab::settings, {TabWidth, 0});
vibrate_on_hover();
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2*ImGui::GetCurrentContext()->FontSize - 4*style.FramePadding.y - style.ItemSpacing.y - style.WindowPadding.y);
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2 * ImGui::GetCurrentContext()->FontSize - 4 * style.FramePadding.y - style.ItemSpacing.y - style.WindowPadding.y);
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " About", &current_tab, tab::about, {TabWidth, 0});
vibrate_on_hover();
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " Exit", &current_tab, tab::exit, {TabWidth, 0});
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " Exit", &current_tab, tab::exit, {TabWidth, 0});
vibrate_on_hover();
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left))
{
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
@@ -651,7 +638,7 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
ImGui::End();
ImGui::PopStyleColor(); // ImGuiCol_WindowBg
ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_ScrollbarSize
ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_ScrollbarSize
if (hovered_item != last_hovered && hovered_item != 0)
{