Skip to content

Commit

Permalink
slider: Improve handling value updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
roblillack committed May 27, 2024
1 parent 98b5500 commit d24e6b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
19 changes: 9 additions & 10 deletions ui/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package ui
import "github.com/roblillack/spot"

type Slider struct {
X int
Y int
Width int
Height int
Min float64
Max float64
Value float64
// Type goFltk.SliderType
// Type gocoa.SliderType
X int
Y int
Width int
Height int
Min float64
Max float64
Value float64
OnValueChanged func(float64)
ref nativeTypeSlider

ref nativeTypeSlider
}

var _ spot.Component = &Slider{}
Expand Down
31 changes: 21 additions & 10 deletions ui/slider_cocoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func (b *Slider) Update(nextComponent spot.Control) bool {
b.ref.SetValue(b.Value)
}

// if next.Type != b.Type {
// b.Type = next.Type
// b.ref.SetSliderType(b.Type)
// }
b.OnValueChanged = next.OnValueChanged

return true
}
Expand All @@ -51,16 +48,30 @@ func (b *Slider) Mount(parent spot.Control) any {
b.ref.SetMaximumValue(b.Max)
b.ref.SetMinimumValue(b.Min)
b.ref.SetValue(b.Value)
// b.ref.SetSliderType(b.Type)
b.ref.OnSliderValueChanged(func() {
if b.OnValueChanged != nil {
b.OnValueChanged(b.ref.Value())
}
})
b.ref.OnSliderValueChanged(b.callback)

if window, ok := parent.(*Window); ok && window != nil && window.ref != nil {
window.ref.AddSlider(b.ref)
}

return b.ref
}

func (c *Slider) Unmount() {
if c.ref == nil {
return
}

c.ref.Remove()
c.ref = nil
}

func (c *Slider) callback() {
if c.ref == nil {
return
}

if c.OnValueChanged != nil {
c.OnValueChanged(c.ref.Value())
}
}
1 change: 0 additions & 1 deletion ui/slider_fltk.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (c *Slider) Mount(parent spot.Control) any {

func (c *Slider) Unmount() {
if c.ref != nil {
// c.ref.Parent().Remove(c.ref)
c.ref.Destroy()
c.ref = nil
}
Expand Down

0 comments on commit d24e6b8

Please sign in to comment.