From 5760d8c4cea8ce7cd0023a4b65e43c44fc11880f Mon Sep 17 00:00:00 2001 From: aiekick Date: Mon, 3 Jun 2024 02:29:18 +0200 Subject: [PATCH] [ADD] : add a ImCoolBar Metrics Windows --- .clang-format | 25 ++++++++-------- CMakeLists.txt | 9 ++++-- ImCoolBar | 2 +- main.cpp | 81 ++++++++++++++++++++++++++++++++------------------ 4 files changed, 72 insertions(+), 45 deletions(-) diff --git a/.clang-format b/.clang-format index 1d625f8..95c8d59 100644 --- a/.clang-format +++ b/.clang-format @@ -1,17 +1,17 @@ --- BasedOnStyle: Google Language: Cpp -Standard: Cpp03 +Standard: Latest AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: true +AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left -AlignOperands: true +AlignOperands: false AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false @@ -19,8 +19,8 @@ AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: true -BinPackParameters: true +BinPackArguments: false +BinPackParameters: false BraceWrapping: AfterClass: false AfterControlStatement: false @@ -34,9 +34,9 @@ BraceWrapping: BeforeCatch: false BeforeElse: false IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false @@ -46,7 +46,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 250 +ColumnLimit: 170 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true @@ -89,9 +89,9 @@ ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakComment: 300 +PenaltyBreakComment: 200 PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 +PenaltyBreakString: 200 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 @@ -142,7 +142,6 @@ SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Auto StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION diff --git a/CMakeLists.txt b/CMakeLists.txt index 1727601..970a46e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ set(PROJECT ImCoolBarApp) enable_language(C CXX) project(${PROJECT} CXX) +option(ENABLED_DEBUG "Enable the debug mode" OFF) + include(cmake/3rdparty.cmake) if(MSVC) @@ -18,7 +20,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) ## some defines for debug mode (before 3rdparty.cmake) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DENABLE_DEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") + +if (ENABLED_DEBUG) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLE_IMCOOLBAR_DEBUG") +endif() set(FINAL_BIN_DIR ${CMAKE_SOURCE_DIR}/bin) set(CMAKE_PDB_OUTPUT_DIRECTORY_DEBUG "${FINAL_BIN_DIR}/debug") @@ -32,7 +38,6 @@ set(CMAKE_INSTALL_BINDIR .) add_definitions(${GLFW_DEFINITIONS}) add_definitions(-D_CRT_SECURE_NO_WARNINGS) - ## for group smake targets in the dir CmakeTargets set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CmakeTargets") diff --git a/ImCoolBar b/ImCoolBar index 2f70ef2..6354580 160000 --- a/ImCoolBar +++ b/ImCoolBar @@ -1 +1 @@ -Subproject commit 2f70ef2653ee63792786b01cfd90d1928ed474f4 +Subproject commit 6354580607534f1e92629bd7a35a8f3dc2c1d6b4 diff --git a/main.cpp b/main.cpp index 93845ca..57d94ff 100644 --- a/main.cpp +++ b/main.cpp @@ -110,7 +110,8 @@ typedef std::vector> TexturesContainer; struct AppDatas { bool show_app_metrics = false; bool show_app_demo = false; - bool show_graph_demo = false; + bool show_graph_demo = false; + bool show_imcoolbar_metrics = false; TexturesContainer textures; }; @@ -140,13 +141,17 @@ void drawCoolBar(AppDatas& vAppDatas, const size_t& vMaxIcons, const char* vLabe for (const auto& arr : vAppDatas.textures) { if (idx++ < vMaxIcons) { if (ImGui::CoolBarItem()) { - float w = ImGui::GetCoolBarItemWidth(); +#ifndef ENABLE_IMCOOLBAR_DEBUG ImGui::PushStyleColor(ImGuiCol_Button, ImVec4()); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4()); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2()); +#endif + float w = ImGui::GetCoolBarItemWidth() - ImGui::GetStyle().FramePadding.x * 2.0f; bool res = ImGui::ImageButton(arr.first.c_str(), (ImTextureID)(size_t)arr.second, ImVec2(w, w)); +#ifndef ENABLE_IMCOOLBAR_DEBUG ImGui::PopStyleVar(); ImGui::PopStyleColor(2); +#endif if (res) { if (arr.first == "Settings") { @@ -155,6 +160,8 @@ void drawCoolBar(AppDatas& vAppDatas, const size_t& vMaxIcons, const char* vLabe vAppDatas.show_graph_demo = !vAppDatas.show_graph_demo; } else if (arr.first == "Magnet") { vAppDatas.show_app_metrics = !vAppDatas.show_app_metrics; + } else if (arr.first == "Blender") { + vAppDatas.show_imcoolbar_metrics = !vAppDatas.show_imcoolbar_metrics; } } } @@ -167,14 +174,16 @@ void drawCoolBar(AppDatas& vAppDatas, const size_t& vMaxIcons, const char* vLabe int main(int, char**) { glfwSetErrorCallback(glfw_error_callback); - if (!glfwInit()) return 1; + if (!glfwInit()) + return 1; const char* glsl_version = "#version 130"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); GLFWwindow* window = glfwCreateWindow(1280, 720, "ImToolbar", NULL, NULL); - if (window == NULL) return 1; + if (window == NULL) + return 1; glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync @@ -206,7 +215,7 @@ int main(int, char**) { ImGui::GetIO().Fonts->AddFontDefault(); static const ImWchar icons_ranges[] = {ICON_MIN_IGFD, ICON_MAX_IGFD, 0}; ImFontConfig icons_config; - icons_config.MergeMode = true; + icons_config.MergeMode = true; icons_config.PixelSnapH = true; ImGui::GetIO().Fonts->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_IGFD, 50.0f, &icons_config, icons_ranges); @@ -244,32 +253,40 @@ int main(int, char**) { drawBackground(background_id); - drawCoolBar(_appDatas, 11, "Top##CoolBarMainWin", ImCoolBarFlags_Horizontal, {ImVec2(0.5f, 0.0f), 50.0f, 100.0f}); - drawCoolBar(_appDatas, 6, "Left##CoolBarMainWin", ImCoolBarFlags_Vertical, {ImVec2(0.0f, 0.5f), 50.0f, 100.0f}); - drawCoolBar(_appDatas, 6, "Right##CoolBarMainWin", ImCoolBarFlags_Vertical, {ImVec2(1.0f, 0.5f), 50.0f, 100.0f}); + static ImGui::ImCoolBarConfig _config; + _config.normal_size = 50.0f; + _config.hovered_size = 200.0f; + _config.anchor = ImVec2(0.5f, 1.0f); +#ifdef ENABLE_IMCOOLBAR_DEBUG + _config.anim_step = 0.005; +#endif + + _config.anchor = ImVec2(0.5f, 0.0f); + drawCoolBar(_appDatas, 11, "Top##CoolBarMainWin", ImCoolBarFlags_Horizontal, _config); + + _config.anchor = ImVec2(0.0f, 0.5f); + drawCoolBar(_appDatas, 6, "Left##CoolBarMainWin", ImCoolBarFlags_Vertical, _config); + + _config.anchor = ImVec2(1.0f, 0.5f); + drawCoolBar(_appDatas, 6, "Right##CoolBarMainWin", ImCoolBarFlags_Vertical, _config); const float& ref_font_scale = ImGui::GetIO().Fonts->Fonts[0]->Scale; - auto coolbar_button = [ref_font_scale](const char* label) { - float w = ImGui::GetCoolBarItemWidth(); - auto font_ptr = ImGui::GetIO().Fonts->Fonts[0]; - //font_ptr->Scale = ref_font_scale; + auto coolbar_button = [ref_font_scale](const char* label) -> bool { + float w = ImGui::GetCoolBarItemWidth(); + auto font_ptr = ImGui::GetIO().Fonts->Fonts[0]; ImGui::PushFont(font_ptr); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2()); - ImGui::PopStyleVar(); font_ptr->Scale = ImGui::GetCoolBarItemScale(); - ImGui::Button(label, ImVec2(w, w)); + const auto res = ImGui::Button(label, ImVec2(w, w)); font_ptr->Scale = ref_font_scale; ImGui::PopFont(); + return res; }; - static ImGui::ImCoolBarConfig _config; - _config.normal_size = 25.0f; - _config.hovered_size = 100.0f; - _config.anchor = ImVec2(0.5f, 1.0f); - + _config.normal_size = 25.0f; + _config.anchor = ImVec2(0.5f, 1.0f); ImGui::GetIO().Fonts->Fonts[0]->Scale = ref_font_scale; - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings ; + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings; if (ImGui::BeginViewportSideBar("BottomBar", ImGui::GetMainViewport(), ImGuiDir_Down, 40.0f, window_flags)) { if (ImGui::BeginCoolBar("Bottom##CoolBarMainWin", ImCoolBarFlags_Horizontal, _config)) { auto window = ImGui::GetCurrentWindow(); @@ -277,13 +294,13 @@ int main(int, char**) { // correct the rect of the window. maybe a bug on imgui !? // the workrect can cause issue when click around // this thing correct the issue - const auto& rc = window->Rect(); - window->WorkRect = rc; - window->OuterRectClipped = rc; - window->InnerRect = rc; - window->InnerClipRect = rc; - window->ParentWorkRect = rc; - window->ClipRect = rc; + const auto& rc = window->Rect(); + window->WorkRect = rc; + window->OuterRectClipped = rc; + window->InnerRect = rc; + window->InnerClipRect = rc; + window->ParentWorkRect = rc; + window->ClipRect = rc; window->ContentRegionRect = rc; } if (ImGui::CoolBarItem()) { @@ -296,7 +313,9 @@ int main(int, char**) { coolbar_button("C"); } if (ImGui::CoolBarItem()) { - coolbar_button("D"); + if (coolbar_button("D")) { + _appDatas.show_imcoolbar_metrics = !_appDatas.show_imcoolbar_metrics; + } } if (ImGui::CoolBarItem()) { coolbar_button("E"); @@ -342,6 +361,10 @@ int main(int, char**) { ImPlot::ShowDemoWindow(&_appDatas.show_graph_demo); } + if (_appDatas.show_imcoolbar_metrics) { + ImGui::ShowCoolBarMetrics(&_appDatas.show_imcoolbar_metrics); + } + // Cpu Zone : prepare ImGui::Render();