From b7d1a0abdd203f522f88233097fa7cc9db9c1601 Mon Sep 17 00:00:00 2001 From: "sashakoshka@tebibyte.media" Date: Tue, 25 Jun 2024 02:33:13 -0400 Subject: [PATCH] Add OnEnter for Slider --- slider.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/slider.go b/slider.go index 1a138e2..46a6d7e 100644 --- a/slider.go +++ b/slider.go @@ -17,6 +17,7 @@ type Slider struct { on struct { slide event.FuncBroadcaster + enter event.FuncBroadcaster } } @@ -89,6 +90,12 @@ func (this *Slider) OnSlide (callback func ()) event.Cookie { return this.on.slide.Connect(callback) } +// OnEnter specifies a function to be called when the user stops moving the +// slider. +func (this *Slider) OnEnter (callback func ()) event.Cookie { + return this.on.enter.Connect(callback) +} + func (this *Slider) handleKeyDown (key input.Key, numpad bool) { var increment float64; if this.layout.vertical { increment = -0.05 @@ -148,17 +155,21 @@ func (this *Slider) handleMouseDown (button input.Button) { if above { this.SetValue(0) this.on.slide.Broadcast() + this.on.enter.Broadcast() } else { this.SetValue(1) this.on.slide.Broadcast() + this.on.enter.Broadcast() } case input.ButtonRight: if above { this.SetValue(this.Value() - this.step) this.on.slide.Broadcast() + this.on.enter.Broadcast() } else { this.SetValue(this.Value() + this.step) this.on.slide.Broadcast() + this.on.enter.Broadcast() } } } @@ -166,6 +177,7 @@ func (this *Slider) handleMouseDown (button input.Button) { func (this *Slider) handleMouseUp (button input.Button) { if button != input.ButtonLeft || !this.dragging { return } this.dragging = false + this.on.enter.Broadcast() } func (this *Slider) handleMouseMove () { @@ -177,6 +189,7 @@ func (this *Slider) handleScroll (x, y float64) { delta := (x + y) * 0.005 this.SetValue(this.Value() + delta) this.on.slide.Broadcast() + this.on.enter.Broadcast() } func (this *Slider) drag () {