elementary / granite

Library that extends GTK with common widgets and utilities
https://elementary.io
GNU Lesser General Public License v3.0
281 stars 61 forks source link

ModeButton widget no longer part of the library #619

Closed avojak closed 10 months ago

avojak commented 2 years ago

What Happened?

The ModeButton widget was removed for the 7.0.0 release (https://github.com/elementary/granite/commit/53bc599f0eb9fed7c3eb045d1e56a8ad15b68348), however there doesn't appear to be an alternative short of "rolling your own".

Creating groups of ToggleButton is very clumsy, and the ModeButton provided a very easy means of binding the active button in the group to a setting.

Is there a standard replacement? Or can this widget be brought back? It was very handy!

Steps to Reproduce

ModeButton widget no longer available in the 7.0.0 release of Granite.

Expected Behavior

A standard replacement in GTK 4 or Libadwaita (I don't see one, but might be overlooking it), or reintroduced to Granite.

OS Version

7.x (Early Access)

Software Version

Latest release (I have run all updates)

Log Output

No response

Hardware Info

No response

danirabbit commented 2 years ago

If you're looking for a view switcher, you can use usually use Gtk.StackSwitcher

Otherwise you can use grouped Gtk.CheckButtons with Granite.STYLE_CLASS_LINKED. This is what Files does, for example

avojak commented 2 years ago

Eh, looks like that's going to be the same as using a few ToggleButtons all grouped. Either way it's still managing a group of widgets manually vs having a single "container" widget. Binding to a setting would also have to be manual.

In this case I'm not looking to switch views, so the StackSwitcher doesn't apply.

What was the rationale behind removing the widget?

danirabbit commented 2 years ago

@avojak can you point out how/where you're using this? That would really help so I can make a recommendation.

ModeButton was mainly added to Granite as a view switching widget before Gtk.StackSwitcher existed, but after a while it started getting kind of abused and folks were using it in places that really should be radio buttons instead (now grouped CheckButton in Gtk4). Removing it is an easy way to force migration to one of those two solutions, and we figured it was pretty trivial to use linked checkbuttons if there was a legitimate case for using this pattern where Gtk.StackSwitcher wouldn't work

avojak commented 2 years ago

@danrabbit Currently I'm using it in a popover menu in Warble for changing the difficulty, BUT I think what you're saying makes a lot of sense that really I should be using a group of radio buttons. A case of me using a widget not intended for that use, which I think is what you were saying earlier - oops!

I may just create a wrapper around a group of radio buttons to facilitate the binding for the selected one.

danirabbit commented 2 years ago

@avojak Yeah I took a look and I would recommend radio buttons for that.

Not sure if this makes it easier to more complicated for you, but you might want to check out GLib.Settings.bind_with_mapping. You can create custom mapping functions to go from an enum to however you need to manipulate your button selection. I'll create a PR with this solution on one of our repos and you can decide which way is easier for you :)

danirabbit commented 2 years ago

Here you go, if you're interested in seeing a couple different solutions for attaching radios to an enum! https://github.com/elementary/switchboard-plug-pantheon-shell/pull/331

avojak commented 2 years ago

Awesome, I'll take a look - thank you!

danirabbit commented 10 months ago

Gonna go ahead and close this since it sounds like this was solved by using radiobuttons