Skip to content

Commit

Permalink
Improve Theme window (deprecated some private api)
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jul 2, 2024
1 parent 7bec671 commit 004a648
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/hello_imgui/hello_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "hello_imgui/hello_imgui_logger.h"
#include "hello_imgui/image_from_asset.h"
#include "hello_imgui/imgui_theme.h"
#include "hello_imgui/hello_imgui_theme.h"
#include "hello_imgui/hello_imgui_font.h"
#include "hello_imgui/runner_params.h"
#include "hello_imgui/hello_imgui_widgets.h"
Expand Down
3 changes: 1 addition & 2 deletions src/hello_imgui/hello_imgui_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@

namespace HelloImGui
{
void Theme_WindowGui(ImGuiTheme::ImGuiTweakedTheme& tweakedTheme);
void Theme_MenuGui(ImGuiTheme::ImGuiTweakedTheme& tweakedTheme);
void ShowThemeTweakGuiWindow(bool* p_open = nullptr);
}
37 changes: 10 additions & 27 deletions src/hello_imgui/impl/hello_imgui_theme.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
#include "hello_imgui/hello_imgui_theme.h"
#include "hello_imgui/hello_imgui.h"

namespace HelloImGui
{
bool gShowTweakWindow = false;

void Theme_WindowGui(ImGuiTheme::ImGuiTweakedTheme& tweakedTheme)
void ShowThemeTweakGuiWindow(bool* p_open)
{
if (gShowTweakWindow)
bool showWindow = true;
if (p_open != nullptr)
showWindow = *p_open;

if (showWindow)
{
ImGui::SetNextWindowSize(ImVec2(600.f, 750.f), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Theme Tweaks", &gShowTweakWindow))
auto& tweakedTheme = HelloImGui::GetRunnerParams()->imGuiWindowParams.tweakedTheme;
ImGui::SetNextWindowSize(HelloImGui::EmToVec2(20.f, 46.f), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Theme Tweaks", p_open))
{
if (ImGuiTheme::ShowThemeTweakGui(&tweakedTheme))
{
ApplyTweakedTheme(tweakedTheme);
}
}
ImGui::End();
}
}

void Theme_MenuGui(ImGuiTheme::ImGuiTweakedTheme& tweakedTheme)
{
if (ImGui::BeginMenu("Theme"))
{
if (ImGui::MenuItem("Theme tweak window", nullptr, gShowTweakWindow))
gShowTweakWindow = !gShowTweakWindow;
ImGui::Separator();
for (int i = 0; i < ImGuiTheme::ImGuiTheme_Count; ++i)
{
ImGuiTheme::ImGuiTheme_ theme = (ImGuiTheme::ImGuiTheme_)(i);
bool selected = (theme == tweakedTheme.Theme);
if (ImGui::MenuItem(ImGuiTheme::ImGuiTheme_Name(theme), nullptr, selected))
{
tweakedTheme.Theme = theme;
ImGuiTheme::ApplyTheme(theme);
}
}
ImGui::EndMenu();
}
}
} // namespace HellImGui
12 changes: 3 additions & 9 deletions src/hello_imgui/impl/imgui_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,9 @@ namespace ImGuiTheme
bool _ShowThemeSelector(ImGuiTheme_* theme)
{
bool changed = false;
ImVec2 listboxSize = ImVec2(0.f, ImGuiTheme_Count * (ImGui::GetFontSize() + ImGui::GetStyle().ItemInnerSpacing.y) );
if (ImGui::BeginListBox("Available_themes", listboxSize))
ImVec2 listboxSize = ImVec2(15.f * ImGui::GetFontSize(), ImGuiTheme_Count * (ImGui::GetFontSize() + ImGui::GetStyle().ItemInnerSpacing.y) );
ImGui::Text("Available Themes");
if (ImGui::BeginListBox("##Available_themes", listboxSize))
{
int nbThemes = ImGuiTheme_Count;
// We start at 3 because we want to place the older themes at the end
Expand Down Expand Up @@ -1181,13 +1182,6 @@ namespace ImGuiTheme
}

}

ImGui::TextWrapped(R"(
Note:
This theme tweaks window is a part of HelloImGuI, but can be reused: see
https://github.com/pthom/hello_imgui/blob/master/src/hello_imgui/imgui_theme.h
)");

return changed;
}

Expand Down
5 changes: 4 additions & 1 deletion src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void setFinalAppWindowScreenshotRgbBuffer(const ImageBuffer& b);
bool _reloadAllDpiResponsiveFonts();
bool ShouldRemoteDisplay();

// Encapsulated inside docking_details.cpp
void ShowThemeTweakGuiWindow_Static();


struct AbstractRunnerStatics
{
Expand Down Expand Up @@ -858,7 +861,7 @@ void AbstractRunner::RenderGui()
if (params.imGuiWindowParams.showStatusBar)
Menu_StatusBar::ShowStatusBar(params);

Theme_WindowGui(params.imGuiWindowParams.tweakedTheme);
ShowThemeTweakGuiWindow_Static();

if (params.callbacks.PostRenderDockableWindows)
params.callbacks.PostRenderDockableWindows();
Expand Down
36 changes: 33 additions & 3 deletions src/hello_imgui/internal/docking_details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,40 @@ namespace HelloImGui
bool ShouldRemoteDisplay();


void _Themes_MenuGui(RunnerParams& runnerParams); // see hello_imgui_themes.cpp

std::map<DockSpaceName, ImGuiID> gImGuiSplitIDs;


static bool gShowTweakWindow = false;

void ShowThemeTweakGuiWindow_Static()
{
ShowThemeTweakGuiWindow(&gShowTweakWindow);
}

void MenuTheme()
{
auto& tweakedTheme = HelloImGui::GetRunnerParams()->imGuiWindowParams.tweakedTheme;

if (ImGui::BeginMenu("Theme"))
{
if (ImGui::MenuItem("Theme tweak window", nullptr, gShowTweakWindow))
gShowTweakWindow = !gShowTweakWindow;
ImGui::Separator();
for (int i = 0; i < ImGuiTheme::ImGuiTheme_Count; ++i)
{
ImGuiTheme::ImGuiTheme_ theme = (ImGuiTheme::ImGuiTheme_)(i);
bool selected = (theme == tweakedTheme.Theme);
if (ImGui::MenuItem(ImGuiTheme::ImGuiTheme_Name(theme), nullptr, selected))
{
tweakedTheme.Theme = theme;
ImGuiTheme::ApplyTheme(theme);
}
}
ImGui::EndMenu();
}
}


namespace DockingDetails
{
bool _makeImGuiWindowTabVisible(const std::string& windowName)
Expand Down Expand Up @@ -186,7 +216,7 @@ void MenuView_Misc(RunnerParams& runnerParams)
}

if (runnerParams.imGuiWindowParams.showMenu_View_Themes)
Theme_MenuGui(runnerParams.imGuiWindowParams.tweakedTheme);
MenuTheme();
}

void ShowViewMenu(RunnerParams & runnerParams)
Expand Down

0 comments on commit 004a648

Please sign in to comment.