Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ func BindLabel(l *toolkit.Label, obs *mvvm.Observable[string], invalidate func()
})
}

// BindProgress one-way-binds a float64 observable to a ProgressBar's Fraction
// (field ProgressBar.Fraction; a ProgressBar has no edit callback). Callers
// keep the value in the widget's [0,1] domain.
// BindProgress one-way-binds a float64 observable to a ProgressBar's Fraction()
// Observable (a ProgressBar is display-only, with no edit callback). Callers keep
// the value in the widget's [0,1] domain.
func BindProgress(p *toolkit.ProgressBar, obs *mvvm.Observable[float64], invalidate func()) (unbind func()) {
return mvvm.OneWay(obs, &p.Fraction, invalidate)
p.Fraction().Set(obs.Get()) // seed widget from the source, like mvvm.OneWay
return obs.Subscribe(func(v float64) {
p.Fraction().Set(v)
if invalidate != nil {
invalidate()
}
})
}

// ── Collection bindings (ObservableList → widget []string source) ───────────
Expand Down
8 changes: 4 additions & 4 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ func TestBindProgress(t *testing.T) {
unbind := BindProgress(p, obs, c.inc)
defer unbind()

if p.Fraction != 0.25 {
t.Fatalf("seed: Fraction=%v", p.Fraction)
if p.Fraction().Get() != 0.25 {
t.Fatalf("seed: Fraction=%v", p.Fraction().Get())
}
obs.Set(0.75)
if p.Fraction != 0.75 || c.n != 1 {
t.Fatalf("push: Fraction=%v n=%d", p.Fraction, c.n)
if p.Fraction().Get() != 0.75 || c.n != 1 {
t.Fatalf("push: Fraction=%v n=%d", p.Fraction().Get(), c.n)
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.26.4

require (
github.com/go-widgets/mvvm v0.5.0
github.com/go-widgets/toolkit v0.226.0
github.com/go-widgets/toolkit v0.230.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/go-widgets/mvvm v0.5.0 h1:o5hh6HAxbApONcbZxmyV9q12pCAPGRd6L24aS3gaCbA
github.com/go-widgets/mvvm v0.5.0/go.mod h1:Phdrd434RLxXW1D6dL1PPQH1tABwYLIN2X7jQVC4TbY=
github.com/go-widgets/painter v0.11.0 h1:xsj4zTz8B43rOZnWrx7ZsaUBMgJyvgaE/Pq2FfcG2Sw=
github.com/go-widgets/painter v0.11.0/go.mod h1:IPRLqdUJuJX8sfuHeYLZCzjoLvA0ApbOlyIAVmguJDQ=
github.com/go-widgets/toolkit v0.226.0 h1:emQuzCdVJhC4gT8rlSc/NUFiL+geMffywx0TdZu7PSU=
github.com/go-widgets/toolkit v0.226.0/go.mod h1:dtu0LE6KVnV7U9R85LkCMiZ5bUL1vRT++OSGAUp8IEQ=
github.com/go-widgets/toolkit v0.230.0 h1:6Z0x8QgYZDGmWyJTCWd7UuzRn46uIvx8mwiAChRz78g=
github.com/go-widgets/toolkit v0.230.0/go.mod h1:dtu0LE6KVnV7U9R85LkCMiZ5bUL1vRT++OSGAUp8IEQ=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
Expand Down