ObjectColor (Dark Mode)

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

Re: ObjectColor

Post by ChrisR »

BarryG wrote: Sat Apr 16, 2022 10:19 am Can the first post please be kept updated with the most recent code? Because when I copy and paste it, the EditorGadget and StringGadget are still white instead of dark as in the screenshot, and I can't see where to fix it. Thanks!
It's normal, wanted here :wink:
If you want the parent's background color for String and Editor also, you need to comment the line SetObjectColorType("NoEdit") = All supported Gadget except String and Editor.

Otherwise, as it should be, I try to always update the code in the first post, in the Tips and Tricks section.

I just updated it, with the ComboBox in addition, thanks to Rashad.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

breeze4me wrote: Sat Apr 16, 2022 11:17 am It seems that the dark mode of the combobox can be set as the code below on Windows 10+.
But the image combobox is only partially possible.
Unfortunately only Windows 10, otherwise it's fine with the DarkMode theme.
Except indeed for editable image Combobox.
I just noted that the cursor is lost when hovering the Editable Combobox 0
breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: ObjectColor

Post by breeze4me »

ChrisR wrote: Sat Apr 16, 2022 12:32 pm I just noted that the cursor is lost when hovering the Editable Combobox 0
It's because of the background color. The code has been updated to use a brighter color.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ObjectColor

Post by RASHAD »

Hi ChrisR
PureBasic Combobox Gadget is a special enhanced Gadget propriety of Fred & crew :D
It's not based directly on OS API
It is been discussed several times in the forum
Be happy with what you achieved for now :lol:

For the Header if you mean ListIcon header search the forum for Colored header by srod,NM,RASHAD
Good luck
Egypt my love
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

Just before going out, it's not bad for the comboBox with your WM_DRAWITEM.
Themed or not, I think I'll forget the combo images.

However, if SetDarkTheme() is called, it may be a good to use the DarkMode_CFD theme for combos and forget about Cbs_OwnerDrawFixed.
But I don't know how to see if the DarkTheme is applied, GetWindowTheme_(GadgetID(0)) returns 0

I will look for ListIcon header, we miss Mr srod :)
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

To note that it works almost here because the enumeration in the demo is done in the right order, Container then childrens.

I should be able to improve it with my last code GetParent() to browse the gadgets in the right hierarchical order.
For a bit later :wink:
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

I have revised the way of defining the background colors and text colors of the Gadgets.
These colors are transmitted now by reading the hierarchical list of Windows, Children and GrandChildren.
This hierarchical list is built once at the 1st call.
So the colors of a window or a container are automatically passed to its Children at initialization, when calling SetObjectColor.
And the Gadgets are drawn using these colors without the need to search for the parent's color. It works much better this way.

I also added the color for the ListIcon and ExplorerList Gadget column header.

Usage:

Code: Select all

SetObjectColor([#Window, #Gadget, BackColor, TextColor])

  #Window     | #PB_All = All Window (Default).
              | The Window number to use.
              |
  #Gadget     | #PB_All = All Supported Gadgets (Default).
              | The Gadget number to use.
              |
  BackColor   | #PB_Auto = Same as parent container's color (Default).
              | The new backgound color. RGB() can be used to get a valid color value.
              | #PB_Default = to go back to the default system backgound color.
              |
  TextColor   | #PB_Auto = White or Black depending on whether the background color is dark or light (Default).
              | The new text color. RGB() can be used to get a valid color value.
              | #PB_Default: to go back to the default system text color.

For all gadgets with automatic background color and text color use: SetObjectColor() 

Example here with the containers drawn in another color:

Image

The code is updated on the 1st post.
Last edited by ChrisR on Wed Apr 27, 2022 11:34 am, edited 2 times in total.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

I cut the code into ObjectColor.pbi and ObjectColorDemo.pb.

And i added another simple demo to show that it is easy to give another skin to your app to make it look more "Modern" :)

Image
Last edited by ChrisR on Tue Apr 26, 2022 1:16 pm, edited 1 time in total.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: ObjectColor

Post by Caronte3D »

Thanks! ChrisR, very nice :wink:

Would be possible to change also the color of the borders?
By default it's too much brighter if we used a dark background :?
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

Hi Caronte3D,

Yes, It would be nice change the border color too, I'm not sure if it can be done simply and for all gadgets.
It seems it can be done with WM_NCPAINT message, an example would be welcome.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: ObjectColor

Post by Caronte3D »

ChrisR wrote: Tue Apr 26, 2022 1:43 pm ...an example would be welcome.
Unfortunately, I know almost nothing about WinApi and callbacks :?
Maybe some guru on the forum can help on that (RASHAD, the magician?) :lol:
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

I fixed an error when applying the dark theme.
And made some small adjustments, for the panel inactive tabs, change the style of the ListView, spin and string (+Ws_Border -Ws_Ex_ClientEdge) to have a thinner border.
It's a little better for bright borders when using a dark background :wink:
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor

Post by ChrisR »

I have updated by also managing the disabled Gadgets now.
Thanks to Rashad for his help :)

And in just a few minutes, I was able to add the full dark mode and the light theme to IceDesign, except for the design part :wink:

Image
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: ObjectColor

Post by BarryG »

Suggestion: Edit the topic title from "ObjectColor" to something like "ObjectColor / Dark Mode" because it's not obvious that this topic is about giving a dark mode to your apps. (I originally overlooked this topic because of this).
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ObjectColor (Dark Mode)

Post by ChrisR »

You are right, it is done :)

However I could not update the code, it is too big now:
Your message contains 68942 characters.
The maximum number of allowed characters is 60000.
I'll upload it on GitHub but tomorrow it's late.
Post Reply