Object Theme Library (for Dark or Light Theme)

Share your advanced PureBasic knowledge/code with the community.
User avatar
ChrisR
Addict
Addict
Posts: 1156
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

Object Theme Library (for Dark or Light Theme) (For Windows only)

This library will add and apply a theme color for All Windows and Gadgets
And for All possible color attributes (BackColor, FrontColor, TitleBackColor,...) for each of them
All gadgets will still work in the same way as PureBasic Gadget

How tu use:
Add: XIncludeFile "ObjectTheme.pbi"
Add: UseModule ObjectTheme (Mandatory)
And apply a theme with the function:
. SetObjectTheme(#ObjectTheme [, WindowColor]) - With #ObjectTheme = #ObjectTheme_DarkBlue, #ObjectTheme_DarkRed, #ObjectTheme_LightBlue or #ObjectTheme_Auto
Easy ;) That's all :)

It's a complete redesign of ObjectColor, colors and brushes are defined, calculated and created at initialization time in a Map for each Gadgets.
This Map is directly used in callbacks, with no need to calculate colors or create brushes in these callbacks, unlike ObjectColor.
It should be much more powerful, with the ability to define all possible theme colors or let the program set them for you with the #PB_Default values.

SetObjectTheme(#ObjectTheme_DarkBlue):

Image


Supported Gadget:
Window, Button, ButtonImage, Calendar, CheckBox, ComboBox, Container, Date, Editor, ExplorerList, ExplorerTree,Frame, HyperLink,
ListIcon, ListView, Option, Panel, ProgressBar, ScrollArea, ScrollBar, Spin, Splitter, String, Text, TrackBar, Tree

Note that you can SetObjectTheme(Theme [, WindowColor]) anywhere you like in your source, before or after creating the Window, Gadget's.
But note the special case for the ComboBox Gadget:
- Either you call the SetObjectTheme() function at the beginning of the program before creating the Windows and ComboBoxes
- Or add the flags #CBS_HASSTRINGS | #CBS_OWNERDRAWFIXED to the ComboBoxes (but Not to the Combox Images) so that the drop-down List is painted

See ObjectTheme_DataSection.pbi for the theme color attribute for each GadgetType
  • It uses the same attributes as SetGadgetColor()
    #PB_Gadget_FrontColor, #PB_Gadget_BackColor, #PB_Gadget_LineColor, #PB_Gadget_TitleFrontColor, #PB_Gadget_TitleBackColor, #PB_Gadget_GrayTextColor
  • With new attributes
    #PB_Gadget_DarkMode, #PB_Gadget_ActiveTab, #PB_Gadget_InactiveTab, #PB_Gadget_HighLightColor, #PB_Gadget_EditBoxColor, #PB_Gadget_OuterColor, #PB_Gadget_CornerColor, #PB_Gadget_GrayBackColor, #PB_Gadget_EnableShadow, #PB_Gadget_ShadowColor, #PB_Gadget_BorderColor, #PB_Gadget_RoundX, #PB_Gadget_RoundY, #PB_Gadget_SplitterBorder, #PB_Gadget_SplitterBorderColor, #PB_Gadget_UseUxGripper, #PB_Gadget_GripperColor, #PB_Gadget_LargeGripper

Usage:

Add: XIncludeFile "ObjectTheme.pbi"
Add: UseModule ObjectTheme (Mandatory)
  • SetObjectTheme(#ObjectTheme [, WindowColor])
    . Apply or change a Theme. Optional WindowColor, the new color to use for the window background
    • Ex: SetObjectTheme(#ObjectTheme_DarkBlue)
    • Ex: SetObjectTheme(#ObjectTheme_Auto, #Black)
  • GetObjectTheme()
    . Get the current theme
  • IsObjectTheme(#Gadget)
    . Is the Gadget included in ObjectTheme ?
  • SetObjectThemeAttribute(ObjectType, #Attribut, Value)
    . Changes a theme color attribute value
    . Dependent color attributes with #PB_Default value, will be recalculated according to this new color
    • Ex: SetObjectThemeAttribute(#PB_GadgetType_Button, #PB_Gadget_BackColor, #Blue) to change the theme Button back color attribute in blue
  • GetObjectThemeAttribute(ObjectType, #Attribut)
    . Returns a theme color attribute value
    • Ex: GetObjectThemeAttribute(#PB_GadgetType_Button, #PB_Gadget_BackColor)
  • SetObjectTypeColor(ObjectType, Attribute, Value)
    . Changes a color attribute value for a gadget type. The Theme color attribute value is preserved
    . Dependent color attributes with #PB_Default value, will be recalculated according to this new color
    • Ex: SetObjectTypeColor(#PB_GadgetType_Button, #PB_Gadget_BackColor, #Blue) to change the back color for each Button in blue
  • SetObjectColor(#Gadget, #Attribut, Value)
    . Changes a color attribute on the given gadget
    . Dependent color attributes with #PB_Default value, will be recalculated according to this new color
    • Ex: SetObjectColor(#Gadget, #PB_Gadget_BackColor, #Blue) to change the Gadget back color in blue
  • GetObjectColor(#Gadget, #Attribut)
    . Returns a Gadget color attribute value
    • Ex: GetObjectColor(#Gadget, #PB_Gadget_BackColor)
Last edited by ChrisR on Thu Nov 23, 2023 5:41 pm, edited 11 times in total.
User avatar
ChrisR
Addict
Addict
Posts: 1156
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

I am not a UI specialist to build beautiful themes, if you play with building a beautiful color Theme, thank you for sharing it :wink:
And thank you for your feedback, comments ... :)

SetObjectTheme(#ObjectTheme_DarkRed):

Image

SetObjectTheme(#ObjectTheme_LightBlue):

Image

SetObjectTheme(#ObjectTheme_Auto, #Black)

Image
Last edited by ChrisR on Sat Nov 18, 2023 2:28 am, edited 1 time in total.
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

Chris, this is very cool! Or hot, if I use lots of red. :mrgreen:
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Object Theme Library (for Dark or Light Theme)

Post by Kuron »

Who needs Santa, when we have Chris? Thank you, Chris. You do so much to help folks here and it is greatly appreciated.
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
idle
Always Here
Always Here
Posts: 5098
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Object Theme Library (for Dark or Light Theme)

Post by idle »

looks good thanks
User avatar
ChrisR
Addict
Addict
Posts: 1156
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

Thanks guys 8)
jacdelad wrote: Fri Nov 17, 2023 11:06 pm Chris, this is very cool! Or hot, if I use lots of red. :mrgreen:
I've added a new theme in dark red tones #ObjectTheme_DarkRed to be less hot and not get burnt.
See screenshot in 2nd post.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Object Theme Library (for Dark or Light Theme)

Post by Little John »

This is very cool, and creating it certainly was a lot of work. Thank you very much for sharing!
User avatar
CDXbow
User
User
Posts: 32
Joined: Mon Aug 12, 2019 5:32 am
Location: Oz

Re: Object Theme Library (for Dark or Light Theme)

Post by CDXbow »

That is really great work, thank you very much for sharing. Such an easy and lightweight way to give a more modern look to a desktop app. I'm going to have to find something to give back to the PB community - would anyone like my ex wife?
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

CDXbow wrote: Sat Nov 18, 2023 12:07 pm would anyone like my ex wife?
Depends on what languages she can code...
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
CDXbow
User
User
Posts: 32
Joined: Mon Aug 12, 2019 5:32 am
Location: Oz

Re: Object Theme Library (for Dark or Light Theme)

Post by CDXbow »

She's skilled in Entitlment++, Visual Narcissism and PureGreed. That covers most of the bases.
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

CDXbow wrote: Sat Nov 18, 2023 2:57 pm She's skilled in Entitlment++, Visual Narcissism and PureGreed. That covers most of the bases.
Nah...i'll pass.
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
ChrisR
Addict
Addict
Posts: 1156
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

CDXbow wrote: Sat Nov 18, 2023 2:57 pm She's skilled in Entitlment++, Visual Narcissism and PureGreed. That covers most of the bases.
Is there any way I can introduce her to one of my former bosses :D
He loved me, Me neither...
Far from the love story and erotic song between of Serge Gainsbourg and Jane Birkin I love you, Me neither
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

I started the demo and after showing the window for about a second it crashes with something like "executable stopped unexpectedly". The demo within the include itself also crashes.

Another thing (and maybe I'm wrong): You use .i for the data in the DataSection of ObjectTheme_DataSection.pbi. Wouldn't it be better to use .l? Afaik all the constants are longs and the colors you define, too. This would save some space on x64 systems.
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
ChrisR
Addict
Addict
Posts: 1156
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Object Theme Library (for Dark or Light Theme)

Post by ChrisR »

You're right about the long, it should be enough with .l for the colors.
I've changed it in the DataSection and also for the 2 structures ObjectBTN_INFO and ObjectInfo_INFO and also with some Byte .b.
On the other hand, I keep the constants as they are. It's in the continuation of PB ColorType constants (#PB_Gadget_BackColor, #PB_Gadget_ActiveTabColor,...)

Damn, a bug, you weren't in debug to get a little more indication ? are you reproducing it too with ObjectTheme_DemoButton.pb ?
As you can guess, I've tested and retested, and retested again, to get the program right, but I haven't encountered any crach or error so far.
Without further indication and without being able to reproduce, I'm not sure where to look for error(s).

Well, for now, I've added OnErrorCall(), if the program isn't in debug mode and with #EnableOnError constant to enable or disable it.
Hoping for more information for your crash.

I've updated on GitHub, v1.1, with also SetGadgetColor() updated to work for all gadget type, attribute (same as SetObjetColor() now) and also some cleanup, comments...

Thanks for your tests and feedback jacdelad, even if the crash isn't a good news :wink:
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Object Theme Library (for Dark or Light Theme)

Post by jacdelad »

I was in debug mode, but due to the crash I don't know how to gather information. The Button-Demo works.
I'll try some things today, wouldn't be the first time something works for everyone but not for me...and it suddenly works.
I'll keep you updated if I find out something.
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply