Skip to content

Commit

Permalink
Make main menu scrollable and make styles a bit more compact
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasZ committed Dec 28, 2024
1 parent ed80700 commit 993124f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 48 deletions.
24 changes: 2 additions & 22 deletions ZHMModSDK/Src/ModSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,29 +655,9 @@ void ModSDK::ThreadedStartup() {
void ModSDK::OnDrawMenu() {
m_ModLoader->LockRead();

auto cursorPosX = ImGui::GetCursorPosX();
auto width = ImGui::GetWindowWidth();
auto height = ImGui::GetWindowHeight();

ImGui::PushClipRect(ImVec2(cursorPosX, 0), ImVec2(width, height), true);
ImGui::BeginGroup();
ImGui::SetCursorPosX(cursorPosX - (float)(int)m_LoadedModsUIScrollOffset);

for (auto& s_Mod: m_ModLoader->GetLoadedMods())
for (auto& s_Mod: m_ModLoader->GetLoadedMods()) {
s_Mod->OnDrawMenu();

ImGui::EndGroup();
ImGui::PopClipRect();

auto modMenusWidth = ImGui::GetCursorPosX();

if (ImGui::IsItemHovered())
m_LoadedModsUIScrollOffset += ImGui::GetIO().MouseWheel * -10.0f;

if (m_LoadedModsUIScrollOffset < 0)
m_LoadedModsUIScrollOffset = 0;
if (modMenusWidth < width)
m_LoadedModsUIScrollOffset -= width - modMenusWidth;
}

m_ModLoader->UnlockRead();
}
Expand Down
38 changes: 19 additions & 19 deletions ZHMModSDK/Src/Rendering/Renderers/ImGuiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,24 @@ ImGuiRenderer::ImGuiRenderer()

static constexpr ImWchar c_IconRanges[] = { ICON_MIN_MD, ICON_MAX_16_MD, 0 };

m_FontLight = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoLight_compressed_data, RobotoLight_compressed_size, 32.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 32.f, &s_IconsConfig, c_IconRanges);
m_FontLight = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoLight_compressed_data, RobotoLight_compressed_size, 28.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 28.f, &s_IconsConfig, c_IconRanges);
s_ImGuiIO.Fonts->Build();

m_FontRegular = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoRegular_compressed_data, RobotoRegular_compressed_size, 32.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 32.f, &s_IconsConfig, c_IconRanges);
m_FontRegular = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoRegular_compressed_data, RobotoRegular_compressed_size, 28.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 28.f, &s_IconsConfig, c_IconRanges);
s_ImGuiIO.Fonts->Build();

m_FontMedium = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoMedium_compressed_data, RobotoMedium_compressed_size, 32.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 32.f, &s_IconsConfig, c_IconRanges);
m_FontMedium = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoMedium_compressed_data, RobotoMedium_compressed_size, 28.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 28.f, &s_IconsConfig, c_IconRanges);
s_ImGuiIO.Fonts->Build();

m_FontBold = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoBold_compressed_data, RobotoBold_compressed_size, 32.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 32.f, &s_IconsConfig, c_IconRanges);
m_FontBold = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoBold_compressed_data, RobotoBold_compressed_size, 28.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 28.f, &s_IconsConfig, c_IconRanges);
s_ImGuiIO.Fonts->Build();

m_FontBlack = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoBlack_compressed_data, RobotoBlack_compressed_size, 32.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 32.f, &s_IconsConfig, c_IconRanges);
m_FontBlack = s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(RobotoBlack_compressed_data, RobotoBlack_compressed_size, 28.f);
s_ImGuiIO.Fonts->AddFontFromMemoryCompressedTTF(MaterialIconsRegular_compressed_data, MaterialIconsRegular_compressed_size, 28.f, &s_IconsConfig, c_IconRanges);
s_ImGuiIO.Fonts->Build();

s_ImGuiIO.FontDefault = m_FontRegular;
Expand Down Expand Up @@ -126,15 +126,15 @@ void ImGuiRenderer::SetupStyles()
s_Style.WindowRounding = 0.f;
s_Style.WindowBorderSize = 0.f;

s_Style.WindowPadding = ImVec2(20.f, 20.f);
s_Style.FramePadding = ImVec2(10.f, 10.f);
s_Style.CellPadding = ImVec2(5.f, 5.f);
s_Style.ItemSpacing = ImVec2(20.f, 10.f);
s_Style.WindowPadding = ImVec2(12.f, 12.f);
s_Style.FramePadding = ImVec2(6.f, 6.f);
s_Style.CellPadding = ImVec2(6.f, 3.f);
s_Style.ItemSpacing = ImVec2(10.f, 6.f);
s_Style.ItemInnerSpacing = ImVec2(10.f, 10.f);
s_Style.TouchExtraPadding = ImVec2(0.f, 0.f);
s_Style.IndentSpacing = 20.f;
s_Style.ScrollbarSize = 20.f;
s_Style.GrabMinSize = 20.f;
s_Style.IndentSpacing = 10.f;
s_Style.ScrollbarSize = 12.f;
s_Style.GrabMinSize = 12.f;

s_Style.WindowBorderSize = 0.f;
s_Style.ChildBorderSize = 0.f;
Expand Down Expand Up @@ -459,7 +459,7 @@ bool ImGuiRenderer::SetupRenderer(IDXGISwapChain3* p_SwapChain)
GetClientRect(m_Hwnd, &s_Rect);

s_ImGuiIO.DisplaySize = ImVec2(static_cast<float>(s_Rect.right - s_Rect.left), static_cast<float>(s_Rect.bottom - s_Rect.top));
s_ImGuiIO.FontGlobalScale = (s_ImGuiIO.DisplaySize.y / 2048.f);
s_ImGuiIO.FontGlobalScale = (s_ImGuiIO.DisplaySize.y / 1800.f);
ImGui::GetMainViewport()->PlatformHandleRaw = m_Hwnd;

m_RendererSetup = true;
Expand Down Expand Up @@ -528,7 +528,7 @@ void ImGuiRenderer::PostReset()
GetClientRect(m_Hwnd, &s_Rect);

s_ImGuiIO.DisplaySize = ImVec2(static_cast<float>(s_Rect.right - s_Rect.left), static_cast<float>(s_Rect.bottom - s_Rect.top));
s_ImGuiIO.FontGlobalScale = (s_ImGuiIO.DisplaySize.y / 2048.f);
s_ImGuiIO.FontGlobalScale = (s_ImGuiIO.DisplaySize.y / 1800.f);
ImGui::GetMainViewport()->PlatformHandleRaw = m_Hwnd;
}

Expand Down
2 changes: 1 addition & 1 deletion ZHMModSDK/Src/UI/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Console::Draw(bool p_HasFocus)

const auto& s_ImGuiIO = ImGui::GetIO();
ImGui::SetWindowSize(ImVec2(s_ImGuiIO.DisplaySize.x - 60, 400), ImGuiCond_Always);
ImGui::SetWindowPos(ImVec2(30, 80 * (s_ImGuiIO.DisplaySize.y / 2048.f)), ImGuiCond_Always);
ImGui::SetWindowPos(ImVec2(30, 80 * (s_ImGuiIO.DisplaySize.y / 1800.f)), ImGuiCond_Always);

if (s_Showing)
{
Expand Down
30 changes: 24 additions & 6 deletions ZHMModSDK/Src/UI/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,47 @@
#include <imgui.h>

#include "IconsMaterialDesign.h"
#include "imgui_internal.h"
#include "ModSDK.h"
#include "ModSelector.h"

using namespace UI;

void MainMenu::Draw(bool p_HasFocus)
{
void MainMenu::Draw(bool p_HasFocus) {
if (!p_HasFocus)
return;

ImGui::BeginMainMenuBar();
const auto &s_ImGuiIO = ImGui::GetIO();

ImGui::SetNextWindowSize(ImVec2(s_ImGuiIO.DisplaySize.x, 0.f), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(12.f, 0));

ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.14f, 0.14f, 0.14f, 1.00f));

ImGui::Begin("#MainMenu", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_HorizontalScrollbar);

ImGui::GetCurrentWindow()->DC.LayoutType = ImGuiLayoutType_Horizontal;

ImGui::AlignTextToFramePadding();
ImGui::PushFont(SDK()->GetImGuiBlackFont());
ImGui::Text("ZHM MOD SDK");
ImGui::PopFont();

ImGui::AlignTextToFramePadding();
ImGui::Text("~ or ^ (under ESC) to toggle this menu");

if (ImGui::Button(ICON_MD_TOKEN " MODS"))
{
if (ImGui::Button(ICON_MD_TOKEN " MODS")) {
ModSDK::GetInstance()->GetUIModSelector()->Show();
}

ModSDK::GetInstance()->OnDrawMenu();

ImGui::EndMainMenuBar();
ImGui::End();

ImGui::PopStyleVar(1);
ImGui::PopStyleColor();
}

0 comments on commit 993124f

Please sign in to comment.