crownengine / crown

The flexible game engine.
https://www.crownengine.org
Other
2.14k stars 154 forks source link

tools: use GTK's "suggested-action" and "destructive-action" style context classes in buttons #132

Closed dbartolini closed 1 year ago

dbartolini commented 1 year ago

See: https://docs.gtk.org/gtk3/const.STYLE_CLASS_SUGGESTED_ACTION.html

SeanKuehl commented 1 year ago

Hello, I'm looking to handle this issue. Could you maybe direct me to some relevant files?

dbartolini commented 1 year ago

https://github.com/crownengine/crown/blob/8b591151fa73abb84cda0e71dc7718213b81b051/tools/level_editor/level_editor.vala#L2019-L2021

One could substitute the previous lines with the following:

Gtk.Widget btn;
btn = md.add_button("Close _without Saving", ResponseType.NO);
btn.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
md.add_button("_Cancel", ResponseType.CANCEL);
btn = md.add_button("_Save", ResponseType.YES);
btn.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION);

There is a number of similar occurrences in level_editor.vala. There could be more somewhere in the tools folder; try to grep for MessageDialog, Button etc.

SeanKuehl commented 1 year ago

I notice that the "_Cancel" button does not have the destructive action added to it. I'm new to GTK, could you provide how I'll know which buttons I should or should not add the destructive action to and how to add this to MessageDialogs and which of these I should do?

dbartolini commented 1 year ago

how I'll know which buttons I should or should not add the destructive action to

You use the destructive style class on an action that is supposed to destroy the user's work. Especially when that destructive action cannot be reversed. If you close a file without saving there's not much I can do beside showing you a big red button as a warning sign.

how to add this to MessageDialogs

You can either do it like I've shown above, or by other means which are up to you.

which of these I should do?

That is also up to you to discover.