Skip to content

Commit

Permalink
impr: Make sidebar look better
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Nov 7, 2023
1 parent 759351c commit 1ca71ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 16 additions & 6 deletions main/gui/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ namespace hex {
}
}

static bool isAnyViewOpen() {
const auto &views = ContentRegistry::Views::impl::getEntries();
return std::any_of(views.begin(), views.end(),
[](const auto &entry) {
return entry.second->getWindowOpenState();
});
}

void Window::frameBegin() {
// Start new ImGui Frame
ImGui_ImplOpenGL3_NewFrame();
Expand All @@ -357,7 +365,7 @@ namespace hex {
auto drawList = ImGui::GetWindowDrawList();
ImGui::PopStyleVar();
auto sidebarPos = ImGui::GetCursorPos();
auto sidebarWidth = ContentRegistry::Interface::impl::getSidebarItems().empty() ? 0 : 30_scaled;
auto sidebarWidth = ContentRegistry::Interface::impl::getSidebarItems().empty() ? 0 : 20_scaled;

ImGui::SetCursorPosX(sidebarWidth);

Expand Down Expand Up @@ -393,7 +401,7 @@ namespace hex {
ImGui::SetCursorPos(sidebarPos);

static i32 openWindow = -1;
u32 index = 0;
u32 index = 0;
ImGui::PushID("SideBarWindows");
for (const auto &[icon, callback] : ContentRegistry::Interface::impl::getSidebarItems()) {
ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index);
Expand All @@ -417,11 +425,11 @@ namespace hex {

bool open = static_cast<u32>(openWindow) == index;
if (open) {
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 2_scaled, 0));
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 1_scaled, 0));
ImGui::SetNextWindowSize(ImVec2(250_scaled, dockSpaceSize.y + ImGui::GetStyle().FramePadding.y + 2_scaled));

ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1);
if (ImGui::Begin("Window", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar)) {
if (ImGui::Begin("SideBarWindow", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar)) {
callback();
}
ImGui::End();
Expand Down Expand Up @@ -501,8 +509,10 @@ namespace hex {

this->beginNativeWindowFrame();

drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth - 2, 0), ImGui::GetWindowPos() + ImGui::GetWindowSize() - ImVec2(dockSpaceSize.x + 2, footerHeight - ImGui::GetStyle().FramePadding.y - 2), ImGui::GetColorU32(ImGuiCol_Separator));
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetWindowPos() + ImVec2(ImGui::GetWindowSize().x, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetColorU32(ImGuiCol_Separator));
if (ImHexApi::Provider::isValid() && isAnyViewOpen()) {
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth - 1_scaled, 0), ImGui::GetWindowPos() + ImGui::GetWindowSize() - ImVec2(dockSpaceSize.x + 1_scaled, footerHeight - ImGui::GetStyle().FramePadding.y - 1_scaled), ImGui::GetColorU32(ImGuiCol_Separator));
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetWindowPos() + ImVec2(ImGui::GetWindowSize().x, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetColorU32(ImGuiCol_Separator));
}
}
ImGui::End();
ImGui::PopStyleVar(2);
Expand Down
10 changes: 7 additions & 3 deletions plugins/builtin/source/content/welcome_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,13 @@ namespace hex::plugin::builtin {
static std::array<char, 256> title;
ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("ImHexMainDock"));
if (ImGui::Begin(title.data())) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10_scaled, 10_scaled));
if (ImGui::Begin("NoViewsBackground", nullptr, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
ImGui::Dummy({});
ImGui::Dummy({});
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, scaled({ 10, 10 }));

ImGui::SetNextWindowScroll({ 0.0F, -1.0F });
ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail() + scaled({ 0, 10 }));
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos() - ImVec2(0, ImGui::GetStyle().FramePadding.y + 2_scaled));
if (ImGui::Begin("Welcome Screen", nullptr, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
auto imageSize = scaled(ImVec2(350, 350));
auto imagePos = (ImGui::GetContentRegionAvail() - imageSize) / 2;

Expand All @@ -368,6 +371,7 @@ namespace hex::plugin::builtin {
loadDefaultLayout();
}
}

ImGui::End();
ImGui::PopStyleVar();
}
Expand Down

0 comments on commit 1ca71ec

Please sign in to comment.