Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Dynamic skin changes...
Re: Dynamic skin changes... [message #61201 is a reply to message #61200] Wed, 04 December 2024 07:48 Go to previous messageGo to next message
Tom1
Messages: 1303
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 03 December 2024 21:22
Does not make sense at all.... I guess you want those function to mean something else than I intended...

Anyway, just for you (I guess), I have added Win32 only

void ChHostSkinLight();
void ChHostSkinDark();

Use with Ctrl::SetSkin ... I guess this should solve your problem.

Hi Mirek!

And thank you very much! This is exactly what I needed. Early Christmas this year Smile

Now the dynamic/static theming sample becomes:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MainWindow : public TopWindow{
	MenuBar menu;

	MainWindow() {
		Title("Dynamic Theming Sample").Sizeable();
		AddFrame(menu);
		menu.Set([=](Bar& bar) {
			bar.Sub("Theme",[=](Bar& bar) {
				bar.Add("System",[=] { Ctrl::SetSkin(ChHostSkin); });
#ifdef WIN32
				bar.Add("Light",[=] { Ctrl::SetSkin(ChHostSkinLight); });
				bar.Add("Dark",[=] { Ctrl::SetSkin(ChHostSkinDark); });
#endif
				bar.Add("Custom",[=] { Ctrl::SetSkin(ChStdSkin); });
			});
		});
	}
	
};

GUI_APP_MAIN{
	Ctrl::SkinChangeSensitive(true);
	Ctrl::SetDarkThemeEnabled(true);

	MainWindow().Run();
}


Best regards,

Tom
Re: Dynamic skin changes... [message #61204 is a reply to message #61201] Wed, 04 December 2024 12:48 Go to previous messageGo to next message
Tom1
Messages: 1303
Registered: March 2007
Ultimate Contributor
Hi,

For those looking for rapid theme switching on Windows, I composed a tray utility to does just that. You may wish to put it in auto start, so it will be always available...
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#ifndef WIN32
#error Sorry, but this program is only available for Windows at this time.
#endif

struct App : TrayIcon {
    typedef App CLASSNAME;
	
	bool IsSystemThemeDark(){
		return !GetWinRegInt("AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
	}
	
	void SetDarkTheme(){
		SetWinRegInt(0, "SystemUsesLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
		SetWinRegInt(0, "AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
		SetWinRegInt(0, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
		Sleep(500);
		SetWinRegInt(0xff1d3f58, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
	}
	
	void SetLightTheme(){
		SetWinRegInt(1, "SystemUsesLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
		SetWinRegInt(1, "AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
		SetWinRegInt(0, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
		Sleep(500);
		SetWinRegInt(0xff1d3f58, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
	}
	
	virtual void LeftUp() {
		if(IsSystemThemeDark()) SetLightTheme();
		else SetDarkTheme();
	}

	virtual void Menu(Bar& bar) {
		bool dark = IsSystemThemeDark();
		bar.Add("Light", [=](){ SetLightTheme(); }).Check(!dark);
		bar.Add("Dark", [=](){ SetDarkTheme(); }).Check(dark);
		bar.Separator();
		bar.Add("Exit", [=](){ Break(); });
	}

	App() {
		Icon(Image::Hand());
	}
};

GUI_APP_MAIN
{
	Ctrl::SetDarkThemeEnabled(true);
#if (UPP_VERSION>=0x20241100)
	Ctrl::SkinChangeSensitive(true);
#endif
	App().Run();
}

Feel free to include this in U++ or use wherever you need it.

Best regards,

Tom

EDIT: You may also wish to give it a nice tray icon instead of "Image::Hand()" Smile

[Updated on: Wed, 04 December 2024 12:50]

Report message to a moderator

Re: Dynamic skin changes... [message #61363 is a reply to message #61204] Thu, 02 January 2025 04:30 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
Great! It works beautifully with virtually no effort on u++ library users.

IMHO though,

	Ctrl::SkinChangeSensitive(true);
	Ctrl::SetDarkThemeEnabled(true);

deserves to be default. For example, a native gnome app will do exactly that. With these the default behavior, the dynamic color/theme is truly effortless to u++ library users.
Re: Dynamic skin changes... [message #61364 is a reply to message #61363] Thu, 02 January 2025 04:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
Lance wrote on Thu, 02 January 2025 04:30
Great! It works beautifully with virtually no effort on u++ library users.

IMHO though,

	Ctrl::SkinChangeSensitive(true);
	Ctrl::SetDarkThemeEnabled(true);

deserves to be default. For example, a native gnome app will do exactly that. With these the default behavior, the dynamic color/theme is truly effortless to u++ library users.


Dark theme IS default.

I am hesitant to make SkinChangeSensitive default as that really requires quite a bit more coding and testing in each app.
Re: Dynamic skin changes... [message #61371 is a reply to message #61364] Thu, 02 January 2025 15:12 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
I see. So one line is required at the moment. That's half the work I thought was required. I am happy with that. Now everything (including Assist++ documentation) fits together naturally and smooth as silk. Great job, Mirek!
Re: Dynamic skin changes... [message #61373 is a reply to message #61371] Thu, 02 January 2025 18:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
Lance wrote on Thu, 02 January 2025 15:12
I see. So one line is required at the moment. That's half the work I thought was required. I am happy with that. Now everything (including Assist++ documentation) fits together naturally and smooth as silk. Great job, Mirek!


No, actually, that is the problem. Many many lines are required for it to work properly.... Smile
Re: Dynamic skin changes... [message #61374 is a reply to message #61373] Thu, 02 January 2025 18:58 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
I understand. A good library takes a great deal of effort from the library develpers' side in order to make the library users' life easier. The dark theme(color/image) integration into u++ certainly is one of the example.
Re: Dynamic skin changes... [message #61376 is a reply to message #61374] Thu, 02 January 2025 20:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
Lance wrote on Thu, 02 January 2025 18:58
I understand. A good library takes a great deal of effort from the library develpers' side in order to make the library users' life easier. The dark theme(color/image) integration into u++ certainly is one of the example.


Oh, I did not mean library developer effort. I mean that your code has to be adjusted and tested for skin changes, otherwise it will have wrong colors after the change. Which means a lot of changes and code added to your code (in addition to that one line activation).
Re: Dynamic skin changes... [message #61382 is a reply to message #61376] Fri, 03 January 2025 14:58 Go to previous message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
I see now. I am the lucky one as I don't go deep enough to have lots of Blend(...) and Style with customized Color.
Previous Topic: Github workflow files for building U++ on Windows, Linux & MacOS
Next Topic: Refactoring Moveable
Goto Forum:
  


Current Time: Thu Jun 12 20:34:45 CEST 2025

Total time taken to generate the page: 0.04995 seconds