Skip to content

Commit

Permalink
Added Dynamic UI style (default) following the OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Feb 18, 2024
1 parent 8e54b32 commit 4d1624c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 54 deletions.
9 changes: 9 additions & 0 deletions include/SKIF.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ enum PopupState {
PopupState_Opened
};

enum UIStyle {
UIStyle_Dynamic,
UIStyle_SKIF_Dark,
UIStyle_SKIF_Light,
UIStyle_ImGui_Classic,
UIStyle_ImGui_Dark,
UIStyle_COUNT // Total number of elements in enum (technically against Microsoft's enum design guidelines, but whatever)
};

enum UIMode {
UIMode_Normal,
UIMode_VRR_Compatibility,
Expand Down
10 changes: 9 additions & 1 deletion include/utility/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <sstream>
#include <vector>



struct SKIF_RegistrySettings {

// TODO: Rework this whole thing to not only hold a registry path but
Expand Down Expand Up @@ -433,10 +435,15 @@ struct SKIF_RegistrySettings {
SKIF_MakeRegKeyI ( LR"(Control Panel\Accessibility\)",
LR"(MessageDuration)" );

// Notification duration
KeyValue <int> regKVWindowUseLightTheme =
SKIF_MakeRegKeyI ( LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\)",
LR"(AppsUseLightTheme)" );

// Default settings (multiple options)
int iNotifications = 2; // 0 = Never, 1 = Always, 2 = When unfocused
int iGhostVisibility = 0; // 0 = Never, 1 = Always, 2 = While service is running
int iStyle = 0; // 0 = SKIF Dark, 1 = ImGui Dark, 2 = SKIF Light, 3 = ImGui Classic
int iStyle = 0; // 0 = Dynamic, 1 = SKIF Dark, 2 = SKIF Light, 3 = ImGui Classic, 4 = ImGui Dark
int iStyleTemp = 0; // Used to temporary hold changes in the style during the current session
int iDimCovers = 0; // 0 = Never, 1 = Always, 2 = On mouse hover
int iCheckForUpdates = 1; // 0 = Never, 1 = Weekly, 2 = On each launch
Expand Down Expand Up @@ -522,6 +529,7 @@ struct SKIF_RegistrySettings {
bool _sRGBColors = false;
bool _LibraryHidden = false; // Do not show hidden games by default
bool _EfficiencyMode = false;
bool _StyleLightMode = false; // Indicates whether we are currently using a light theme or not

// Functions
static SKIF_RegistrySettings& GetInstance (void)
Expand Down
18 changes: 15 additions & 3 deletions src/SKIF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ wWinMain ( _In_ HINSTANCE hInstance,
{
_registry.iStyle = (_registry.iStyleTemp != _registry.iStyle)
? _registry.iStyleTemp
: (_registry.iStyle + 1) % 4;
: (_registry.iStyle + 1) % UIStyle_COUNT;
_registry.regKVStyle.putData (_registry.iStyle);

ImGuiStyle newStyle;
Expand Down Expand Up @@ -2402,7 +2402,7 @@ wWinMain ( _In_ HINSTANCE hInstance,

static bool closeButtonHoverActive = false;

if (_registry.iStyle == 2 && closeButtonHoverActive)
if (_registry._StyleLightMode && closeButtonHoverActive)
ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg)); //ImVec4 (0.9F, 0.9F, 0.9F, 1.0f));

if (ImGui::Button (ICON_FA_XMARK, ImVec2 ( 30.0f * SKIF_ImGui_GlobalDPIScale, 0.0f ) ) ||
Expand All @@ -2426,7 +2426,7 @@ wWinMain ( _In_ HINSTANCE hInstance,
}
}

if (_registry.iStyle == 2)
if (_registry._StyleLightMode)
{
if (closeButtonHoverActive)
ImGui::PopStyleColor ( );
Expand Down Expand Up @@ -4061,6 +4061,18 @@ SKIF_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
SKIF_Shutdown = true;
break;

case WM_SETTINGCHANGE:
if (_registry.iStyle == 0 && _wcsicmp (L"ImmersiveColorSet", reinterpret_cast<wchar_t*> (lParam)) == 0)
{
PLOG_VERBOSE << "Theme was changed";

ImGuiStyle newStyle;
SKIF_ImGui_SetStyle (&newStyle);
ImGui_ImplWin32_UpdateDWMBorders ( );
}

break;

case WM_POWERBROADCAST:
if (wParam == PBT_APMSUSPEND)
{
Expand Down
8 changes: 4 additions & 4 deletions src/tabs/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ SKIF_UI_Tab_DrawAbout (void)
ImGui::Spacing ( );
ImGui::SameLine ( );
ImGui::TextColored (
(_registry.iStyle == 2) ? ImGui::GetStyleColorVec4(ImGuiCol_SKIF_Yellow) : ImVec4 (ImColor (247, 241, 169)),
(_registry._StyleLightMode) ? ImGui::GetStyleColorVec4(ImGuiCol_SKIF_Yellow) : ImVec4 (ImColor (247, 241, 169)),
ICON_FA_DISCOURSE " " );
ImGui::SameLine ( );

Expand Down Expand Up @@ -377,7 +377,7 @@ SKIF_UI_Tab_DrawAbout (void)
ImGui::Spacing ( );
ImGui::SameLine ( );
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
ICON_FA_GITHUB " " );
ImGui::SameLine ( );
if (ImGui::Selectable ("GitHub"))
Expand All @@ -392,7 +392,7 @@ SKIF_UI_Tab_DrawAbout (void)
ImGui::SameLine (0.0f, 10.0f * SKIF_ImGui_GlobalDPIScale);
//ImGui::SetCursorPosX (ImGui::GetCursorPosX ( ) + 1.0f);
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
ICON_FA_FILE_CONTRACT " ");
ImGui::SameLine (0.0f, 10.0f);
if (ImGui::Selectable ("Privacy Policy"))
Expand All @@ -407,7 +407,7 @@ SKIF_UI_Tab_DrawAbout (void)
ImGui::SameLine (0.0f, 10.0f * SKIF_ImGui_GlobalDPIScale);
//ImGui::SetCursorPosX (ImGui::GetCursorPosX ( ) + 1.0f);
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
ICON_FA_FILE_CONTRACT " ");
ImGui::SameLine (0.0f, 10.0f);
if (ImGui::Selectable ("Licenses"))
Expand Down
2 changes: 1 addition & 1 deletion src/tabs/common_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void SKIF_UI_DrawShellyTheGhost (void)
0.5f * (std::sin(6 * (fGhostTime / 2.5f + 2.0f / 3.0f)) + 1)
);

if (_registry.iStyle == 2)
if (_registry._StyleLightMode)
vGhostColor = vGhostColor * ImVec4 (0.8f, 0.8f, 0.8f, 1.0f);

// Non-static as it needs to be updated constantly due to mixed-DPI monitor configs
Expand Down
45 changes: 25 additions & 20 deletions src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,11 @@ DrawGameContextMenu (app_record_s* pApp)
ImGui::SetCursorPos (iconPos);

ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
(_registry._StyleLightMode) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
ICON_FA_BARS_STAGGERED );

ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
(_registry._StyleLightMode) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
ICON_FA_GAMEPAD );

ImGui::TextColored (
Expand Down Expand Up @@ -2315,7 +2315,7 @@ DrawGameContextMenu (app_record_s* pApp)
else if (pApp->store == app_record_s::Store::Steam)
{
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
(_registry._StyleLightMode) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
ICON_FA_STEAM_SYMBOL );

ImGui::TextColored (
Expand Down Expand Up @@ -2963,15 +2963,15 @@ DrawSpecialKContextMenu (app_record_s* pApp)
ICON_FA_DISCORD
);
ImGui::TextColored (
(_registry.iStyle == 2) ? ImGui::GetStyleColorVec4(ImGuiCol_SKIF_Yellow) : ImVec4 (ImColor (247, 241, 169)),
(_registry._StyleLightMode) ? ImGui::GetStyleColorVec4(ImGuiCol_SKIF_Yellow) : ImVec4 (ImColor (247, 241, 169)),
ICON_FA_DISCOURSE
);
ImGui::TextColored (
ImColor (249, 104, 84),
ICON_FA_PATREON
);
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255), // ImColor (226, 67, 40)
ICON_FA_GITHUB
);

Expand All @@ -2984,7 +2984,7 @@ DrawSpecialKContextMenu (app_record_s* pApp)

if (SKIF_STEAM_OWNER)
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
(_registry._StyleLightMode) ? ImColor(0, 0, 0) : ImColor(255, 255, 255),
ICON_FA_STEAM_SYMBOL );

ImGui::Separator ( ); // ==============================
Expand Down Expand Up @@ -5812,7 +5812,7 @@ SKIF_UI_Tab_DrawLibrary (void)
sizeCover.y * SKIF_ImGui_GlobalDPIScale),
vecCoverUv0_old, // Top Left coordinates
vecCoverUv1_old, // Bottom Right coordinates
(_registry.iStyle == 2) ? ImVec4 (1.0f, 1.0f, 1.0f, fGammaCorrectedTint * AdjustAlpha (fAlphaPrev)) : ImVec4 (fTint, fTint, fTint, fAlphaPrev), // Alpha transparency
(_registry._StyleLightMode) ? ImVec4 (1.0f, 1.0f, 1.0f, fGammaCorrectedTint * AdjustAlpha (fAlphaPrev)) : ImVec4 (fTint, fTint, fTint, fAlphaPrev), // Alpha transparency
(_registry.bUIBorders) ? ImGui::GetStyleColorVec4 (ImGuiCol_Border) : ImVec4 (0.0f, 0.0f, 0.0f, 0.0f) // Border
);

Expand All @@ -5825,7 +5825,7 @@ SKIF_UI_Tab_DrawLibrary (void)
sizeCover.y * SKIF_ImGui_GlobalDPIScale),
vecCoverUv0, // Top Left coordinates
vecCoverUv1, // Bottom Right coordinates
(_registry.iStyle == 2) ? ImVec4 (1.0f, 1.0f, 1.0f, fGammaCorrectedTint * AdjustAlpha (fAlpha)) : ImVec4 (fTint, fTint, fTint, fAlpha), // Alpha transparency (2024-01-01, removed fGammaCorrectedTint * fAlpha for the light style)
(_registry._StyleLightMode) ? ImVec4 (1.0f, 1.0f, 1.0f, fGammaCorrectedTint * AdjustAlpha (fAlpha)) : ImVec4 (fTint, fTint, fTint, fAlpha), // Alpha transparency (2024-01-01, removed fGammaCorrectedTint * fAlpha for the light style)
(_registry.bUIBorders) ? ImGui::GetStyleColorVec4 (ImGuiCol_Border) : ImVec4 (0.0f, 0.0f, 0.0f, 0.0f) // Border
);

Expand Down Expand Up @@ -6223,11 +6223,16 @@ SKIF_UI_Tab_DrawLibrary (void)
if (sort_changed && selection.category == tmpCategory)
ImGui::SetNextItemOpen (true);

ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled));
ImGui::PushStyleColor (ImGuiCol_Header, ImGui::GetStyleColorVec4 (ImGuiCol_Header) * ImVec4 (0.7f, 0.7f, 0.7f, 1.0f));
if (! _registry._StyleLightMode)
{
ImGui::PushStyleColor (ImGuiCol_Header, ImGui::GetStyleColorVec4 (ImGuiCol_Header) * ImVec4 (0.7f, 0.7f, 0.7f, 1.0f));

ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled));
}
category_opened = ImGui::CollapsingHeader ((tmpCategory.empty() ? "Games" : tmpCategory.c_str()), (showClearBtn) ? ImGuiTreeNodeFlags_DefaultOpen : 0); // ImGuiTreeNodeFlags_DefaultOpen
ImGui::PopStyleColor ( );
ImGui::PopStyleColor ( );

if (! _registry._StyleLightMode)
ImGui::PopStyleColor (2);

if (! tmpCategory.empty() && tmpCategory != "Favorites")
{
Expand Down Expand Up @@ -6906,23 +6911,23 @@ SKIF_UI_Tab_DrawLibrary (void)
ImGui::SetCursorPos (iconPos);

ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
ICON_FA_FILE_IMAGE
);

if (pApp->tex_cover.isCustom)
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
ICON_FA_ROTATE_LEFT
);
else if (pApp->tex_cover.isManaged)
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
ICON_FA_ROTATE
);
else if (resetVisible) // If texture is neither custom nor managed
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (128, 128, 128) : ImColor (128, 128, 128),
(_registry._StyleLightMode) ? ImColor (128, 128, 128) : ImColor (128, 128, 128),
ICON_FA_ROTATE
);

Expand Down Expand Up @@ -7147,24 +7152,24 @@ SKIF_UI_Tab_DrawLibrary (void)
ImGui::SetCursorPos (iconPos);

ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
ICON_FA_FILE_IMAGE
);

if (pApp->tex_icon.isCustom)
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
ICON_FA_ROTATE_LEFT
);

else if (pApp->tex_icon.isManaged)
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
(_registry._StyleLightMode) ? ImColor (0, 0, 0) : ImColor (255, 255, 255),
ICON_FA_ROTATE
);
else if (resetVisible) // If texture is neither custom nor managed
ImGui::TextColored (
(_registry.iStyle == 2) ? ImColor (128, 128, 128) : ImColor (128, 128, 128),
(_registry._StyleLightMode) ? ImColor (128, 128, 128) : ImColor (128, 128, 128),
ICON_FA_ROTATE
);

Expand Down
32 changes: 17 additions & 15 deletions src/tabs/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,12 @@ SKIF_UI_Tab_DrawSettings (void)
ImGui::SetColumnWidth (0, 480.0f * SKIF_ImGui_GlobalDPIScale) //SKIF_vecCurrentMode.x / 2.0f)
);

const char* StyleItems[] = { "SKIF Dark",
"ImGui Dark",
"SKIF Light",
"ImGui Classic"
constexpr char* StyleItems[UIStyle_COUNT] =
{ "Dynamic",
"SKIF Dark",
"SKIF Light",
"ImGui Classic",
"ImGui Dark"
};
static const char*
StyleItemsCurrent;
Expand All @@ -894,15 +896,15 @@ SKIF_UI_Tab_DrawSettings (void)

if (ImGui::BeginCombo ("###_registry.iStyleCombo", StyleItemsCurrent)) // The second parameter is the label previewed before opening the combo.
{
for (int n = 0; n < IM_ARRAYSIZE (StyleItems); n++)
{
bool is_selected = (StyleItemsCurrent == StyleItems[n]); // You can store your selection however you want, outside or inside your objects
if (ImGui::Selectable (StyleItems[n], is_selected))
_registry.iStyleTemp = n; // We apply the new style at the beginning of the next frame to prevent any PushStyleColor/Var from causing issues
if (is_selected)
ImGui::SetItemDefaultFocus ( ); // You may set the initial focus when opening the combo (scrolling + for keyboard navigation support)
}
ImGui::EndCombo ( );
for (int n = 0; n < UIStyle_COUNT; n++)
{
bool is_selected = (StyleItemsCurrent == StyleItems[n]); // You can store your selection however you want, outside or inside your objects
if (ImGui::Selectable (StyleItems[n], is_selected))
_registry.iStyleTemp = n; // We apply the new style at the beginning of the next frame to prevent any PushStyleColor/Var from causing issues
if (is_selected)
ImGui::SetItemDefaultFocus ( ); // You may set the initial focus when opening the combo (scrolling + for keyboard navigation support)
}
ImGui::EndCombo ( );
}

ImGui::TreePop ( );
Expand Down Expand Up @@ -1707,8 +1709,8 @@ SKIF_UI_Tab_DrawSettings (void)

ImGui::SameLine ();
ImGui::BeginGroup ();
ImGui::TextColored ((_registry.iStyle == 2) ? ImColor(0, 0, 0) : ImColor(255, 255, 255), ICON_FA_WINDOWS);
//ImGui::TextColored ((_registry.iStyle == 2) ? ImColor(0, 0, 0) : ImColor(255, 255, 255), ICON_FA_XBOX);
ImGui::TextColored ((_registry._StyleLightMode) ? ImColor(0, 0, 0) : ImColor(255, 255, 255), ICON_FA_WINDOWS);
//ImGui::TextColored ((_registry._StyleLightMode) ? ImColor(0, 0, 0) : ImColor(255, 255, 255), ICON_FA_XBOX);
ImGui::EndGroup ();

ImGui::SameLine ();
Expand Down
32 changes: 22 additions & 10 deletions src/utility/skif_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,22 +1087,34 @@ SKIF_ImGui_SetStyle (ImGuiStyle* dst)
if (dst == nullptr)
dst = &ImGui::GetStyle ( );

_registry._StyleLightMode = false;

// Setup Dear ImGui style
switch (_registry.iStyle)
{
case 3:
case UIStyle_ImGui_Dark:
ImGui::StyleColorsDark (dst);
break;
case UIStyle_ImGui_Classic:
ImGui::StyleColorsClassic (dst);
break;
case 2:
case UIStyle_SKIF_Light:
SKIF_ImGui_StyleColorsLight (dst);
_registry._StyleLightMode = true;
break;
case 1:
ImGui::StyleColorsDark (dst);
case UIStyle_SKIF_Dark:
SKIF_ImGui_StyleColorsDark (dst);
break;
case 0:
case UIStyle_Dynamic:
default:
SKIF_ImGui_StyleColorsDark (dst);
_registry.iStyle = 0;
_registry.iStyle = 0;
_registry._StyleLightMode = static_cast<bool> (_registry.regKVWindowUseLightTheme.getData ( ));

if (_registry._StyleLightMode)
SKIF_ImGui_StyleColorsLight (dst);
else
SKIF_ImGui_StyleColorsDark (dst);
break;
}

// Override the style with a few tweaks of our own
Expand Down Expand Up @@ -1145,9 +1157,9 @@ SKIF_ImGui_PushDisableState (void)
ImGui::PushItemFlag (ImGuiItemFlags_Disabled, true);
//ImGui::PushStyleVar (ImGuiStyleVar_Alpha, ImGui::GetStyle ().Alpha * 0.5f); // [UNUSED]
ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled));
ImGui::PushStyleColor (ImGuiCol_SliderGrab, SKIF_ImGui_ImDerp (ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg), ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled), (_registry.iStyle == 2) ? 0.75f : 0.25f));
ImGui::PushStyleColor (ImGuiCol_CheckMark, SKIF_ImGui_ImDerp (ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg), ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled), (_registry.iStyle == 2) ? 0.75f : 0.25f));
ImGui::PushStyleColor (ImGuiCol_FrameBg, SKIF_ImGui_ImDerp (ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg), ImGui::GetStyleColorVec4 (ImGuiCol_FrameBg), (_registry.iStyle == 2) ? 0.75f : 0.15f));
ImGui::PushStyleColor (ImGuiCol_SliderGrab, SKIF_ImGui_ImDerp (ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg), ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled), (_registry._StyleLightMode) ? 0.75f : 0.25f));
ImGui::PushStyleColor (ImGuiCol_CheckMark, SKIF_ImGui_ImDerp (ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg), ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled), (_registry._StyleLightMode) ? 0.75f : 0.25f));
ImGui::PushStyleColor (ImGuiCol_FrameBg, SKIF_ImGui_ImDerp (ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg), ImGui::GetStyleColorVec4 (ImGuiCol_FrameBg), (_registry._StyleLightMode) ? 0.75f : 0.15f));
}

void
Expand Down

0 comments on commit 4d1624c

Please sign in to comment.