Skip to content

Commit

Permalink
Bind Settings to active instead of state (#1370)
Browse files Browse the repository at this point in the history
When binding to `state` the `Switch` can be in a wrong position where it is colored to be active, but the slider is at the wrong spot. As per advice in the GTK-chat, one should instead bind to the active-property.
  • Loading branch information
Schmiddiii authored Apr 13, 2023
1 parent c4fd92f commit c1119a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion book/listings/settings/2/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn build_ui(app: &Application) {

// ANCHOR: settings_bind
settings
.bind("is-switch-enabled", &switch, "state")
.bind("is-switch-enabled", &switch, "active")
.flags(SettingsBindFlags::DEFAULT)
.build();
// ANCHOR_END: settings_bind
Expand Down
2 changes: 1 addition & 1 deletion book/src/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master

The `Switch` now retains its state even after closing the application.
But we can make this even better.
The `Switch` has a property "state" and `Settings` allows us to bind properties to a specific setting.
The `Switch` has a property "active" and `Settings` allows us to bind properties to a specific setting.
So let's do exactly that.

We can remove the [`boolean`](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gio/prelude/trait.SettingsExt.html#tymethod.boolean) call before initializing the `Switch` as well as the [`connect_state_set`](../docs/gtk4/struct.Switch.html#method.connect_state_set) call.
Expand Down

0 comments on commit c1119a0

Please sign in to comment.