Gtk Button Theming 'suggested-action' and 'destructive-action'

New to Gambas? Post your questions here. No question is too silly or too simple.
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by JumpyVB »

In Gambas, how do I define a button to be themed as 'destructive-action' or 'suggested-action'? They should be of different color.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by cogier »

In Gambas, how do I define a button to be themed as 'destructive-action' or 'suggested-action'? They should be of different color.
The best way is to make your own bespoke button. Run this code in a new Graphical Application.

PanelButton As Panel
Label1 As Label

Public Sub Form_Open()
  
  With Me
    .Center
    .Y = 250
    .Height = 75
    .Width = 300
  End With
  
  With PanelButton = New Panel(Me) As "PanelButton"
    .Height = 56
    .Width = 100
    .Arrangement = Arrange.Vertical
    .Background = Color.Yellow
    .Border = Border.Raised
  End With
  
  With Label1 = New Label(PanelButton) As "Label1"
    .Expand = True
    .Font.Size = 18
    .Font.Bold = True
    .Foreground = Color.Red
    .Alignment = Align.Center
    .Text = "Destructive-action!!"
  End With
  
End

Public Sub Label1_MouseDown()
  
  PanelButton.Border = Border.Sunken
  
End

Public Sub Label1_MouseUp()
  
  Message.Warning("This computer will now crash in a fountain of your code!", "OK")
  PanelButton.Border = Border.Raised
  
End
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by JumpyVB »

I appreaciate the humour :D
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by vuott »

JumpyVB wrote: Saturday 9th September 2023 6:10am In Gambas, how do I define a button to be themed as 'destructive-action' or 'suggested-action'? They should be of different color.
Forgive me, but :? I do not quite understand what you want to achieve.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by JumpyVB »

Here's a screenshot illustrating the use of suggested-action style class. On the screenshot I am closing an unsaved document in the xed text editor and the program highlights the "Save As..." button. Gtk Inspector reveals that the button has a suggested-action css style class associated to it. The color in this case is defined in /usr/share/themes/Mint-Yz-Base-Purple/gtk-3.0/gtk.css
suggested-action.png
suggested-action.png (60.42 KiB) Viewed 3417 times
I wan't a specific button on my gambas app to be styled like this. I don't want to hardcode the background. I want the appearance to follow which ever theme the user has specified on their gnu/linux.

PS: I'm using Linux Mint and SebastJava/mint-yz-theme here.

PSS: Maybe this could be achieved in QT as well as in Gtk. I can change my app to using QT. I know you vuott are using QT if I remember correctly from an earlier post.
User avatar
BruceSteers
Posts: 1582
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by BruceSteers »

You can set a buttons Cancel or Default Boolean properties.

btnSaveAs.Default = True
btnExit.Cancel = True
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by JumpyVB »

BruceSteers wrote: Saturday 9th September 2023 9:57pm You can set a buttons Cancel or Default Boolean properties.
btnSaveAs.Default = True
btnExit.Cancel = True
I tried default and cancel but they don't change the appearance - At least on my setup.

I will post a new question about theming QT apps.
User avatar
BruceSteers
Posts: 1582
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by BruceSteers »

It's down to the theme config.

You have to code it yourself if you want it guaranteed.
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by JumpyVB »

BruceSteers wrote: Sunday 10th September 2023 9:37pmIt's down to the theme config.
How should I theme config for a Gambas app?

There seems to be something odd with naming convention of gtk ui elements in Gambas. Here's a screenshot showcasing my image viewer prototype made in Gambas as a GTK+3 Application. For example Gtk Inspector reveals that the proggressbar is called GtkFixed - Which makes it impossible to be themed? I would have expected it to be called GtkProggressBar and have the name ProgressBar1 shown aswell - As compared to gtk3-widget-factory on the right side on the screenshot. Is it possible that proggressbar is not a native gtk component in Gambas?
Inspecting.png
Inspecting.png (229.76 KiB) Viewed 3379 times
User avatar
BruceSteers
Posts: 1582
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gtk Button Theming 'suggested-action' and 'destructive-action'

Post by BruceSteers »

You'd have to ask Benoit about that level of internal detail.

Personally i think it would be easier to just make your own buttons like cogier first suggested.

I'd probably do something like this....

Save this code in my projects .src folder as Form.class

' Gambas class file

Create Static
Export

Public Sub Show()

  SetButtonColors
  Super.Show()

End

Public Sub ShowModal() As Integer

  SetButtonColors
  Return Super.ShowModal()

End

Private Sub SetButtonColors()
  Dim b As Button
 
  For Each c As Control In Me.Controls
    If c Is Button Then
      b = c
      If b.Default Then b.Background = Color.SetAlpha(Color.Green, 220)
      If b.Cancel Then b.Background = Color.SetAlpha(Color.Red, 220)
    Endif
  Next

End



That will make ALL your programs windows buttons (including modal windows like Message.class) show a hint of green if Default or a hint of red if Cancel.

of course you can change the color to your own liking

PS. you need to explicitly use Me.Show in your startup forms Form_Open() method as it does not seem to run Show() itself.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply