Is there an easy way to put my program in a dark theme?

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
User avatar
gambafeliz
Posts: 144
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Is there an easy way to put my program in a dark theme?

Post by gambafeliz »

Hello everyone

I have my project in light colors since I started it. But now I observe that it is more elegant, more readable and careful to use dark theme to consume less energy.

Anyway, me and my environmentalism. :)

Is there a way to convert my project to a dark theme without dying trying?

I already tried it several times but I gave up because of how huge my project is, full of forms and letters, especially in red and green because they are economic data, as well as icons that I did not take into account their background, etc.

Please, any help would be appreciated.

Greetings
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
User avatar
BruceSteers
Posts: 1874
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Is there an easy way to put my program in a dark theme?

Post by BruceSteers »

I'm not so sure.

Maybe using Color.Invert() in a For loop on the form controls to convert it..


If bDarkMode Then

  For each c as Control In Form.Controls
   c.Foreground = Color.Invert(c.Foreground)
   c.Background = Color.Invert(c.Background)
  Next

Endif



Something a bit like that but probably more advanced 😎
If at first you don't succeed , try doing something differently.
BruceS
User avatar
gambafeliz
Posts: 144
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Re: Is there an easy way to put my program in a dark theme?

Post by gambafeliz »

It would be interesting. I try it and I'll tell you.
:shock: How it works is going to be amazing. :shock:
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
User avatar
gambafeliz
Posts: 144
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Re: Is there an easy way to put my program in a dark theme?

Post by gambafeliz »

I give up. The code works although in my case very partially.

My problem is that I'm going to have to modify everything, everything, the code to resolve the issue to dark.

Nobody's fault. Only me for not having foreseen this possibility.

Note: It occurred to me now, to change the color in the .Form files but I don't know if it is possible. But even if it is possible, I am sure that within the code I assign colors, with which it will continue to be chaos.

Thanks for that attempt to help me, but I'm at a dead end.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
User avatar
BruceSteers
Posts: 1874
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Is there an easy way to put my program in a dark theme?

Post by BruceSteers »

This kinda works for me...
I have this Public function in my StartUp.class...

Public DarkMode As Boolean = True


Public Sub CheckDark(Parent As Object)
  
  If Not DarkMode Then Return

  Try Parent.Foreground = If(Parent.Foreground = -1, Color.White, Color.Invert(Parent.Foreground))
  Try Parent.Background = Color.Invert(Parent.Background)

  For Each o As Object In Parent.Children
    If o Is Container Then 
        CheckDark(o)
    Else
      Try o.Foreground = If(o.Foreground = -1, Color.White, Color.Invert(o.Foreground))
      Try o.Background = Color.Invert(o.Background)
    Endif
  Next
  
End



then for each form class file i just add the following in the Form_Open() method...



Public Sub Form_Open()

  StartUp.CheckDark(Me)

End



It'll need more work though i think to check if the desktop is in dark mode.
I think the following code...
o.Foreground = If(o.Foreground = -1, Color.White, Color.Invert(o.Foreground))
may only work on non dark themes where the text is black
If at first you don't succeed , try doing something differently.
BruceS
User avatar
gambafeliz
Posts: 144
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Re: Is there an easy way to put my program in a dark theme?

Post by gambafeliz »

I haven't tried it yet. I'll tell you, but it works or not. I'm honestly moved and I appreciate your effort. Thanks for your help.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
User avatar
gambafeliz
Posts: 144
Joined: Friday 2nd September 2022 7:50pm
Location: I live in the same city as Picasso

Re: Is there an easy way to put my program in a dark theme?

Post by gambafeliz »

This code works much better. There are little things but it takes less effort to correct my program.

As I always tell you and I will tell you today you have done a little more good than bad. And I hope you are rewarded. Thank you.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Post Reply