Skip to content

Commit

Permalink
[ADD] : add a ImCoolBar Metrics Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Jun 3, 2024
1 parent d841445 commit 5760d8c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 45 deletions.
25 changes: 12 additions & 13 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
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
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
Expand All @@ -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
Expand All @@ -46,7 +46,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 250
ColumnLimit: 170
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -142,7 +142,6 @@ SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion ImCoolBar
Submodule ImCoolBar updated 2 files
+214 −100 ImCoolbar.cpp
+3 −2 ImCoolbar.h
81 changes: 52 additions & 29 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ typedef std::vector<std::pair<std::string, GLuint>> 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;
};

Expand Down Expand Up @@ -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") {
Expand All @@ -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;
}
}
}
Expand All @@ -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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -244,46 +253,54 @@ 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();
if (window) {
// 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()) {
Expand All @@ -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");
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 5760d8c

Please sign in to comment.