我有同样的问题,但我暂时用 gtk 按钮修复了。使用取消信号释放。它对我有用。
func (c *Control) topCenter() *gtk.Box {
boxroot := gtk.NewBox(gtk.OrientationHorizontal, 0)
boxroot.SetHExpand(true)
root := gtk.NewOverlay()
root.SetCSSClasses([]string{"player-control-scale"})
root.SetHExpand(true)
c.cacheadjustment = gtk.NewAdjustment(0, 0, 1, 1, 10, 0)
c.cacheprocess = gtk.NewScale(gtk.OrientationHorizontal, c.cacheadjustment)
c.cacheprocess.AddCSSClass("timescalebuffer")
root.SetChild(c.cacheprocess)
c.timeadjustment = gtk.NewAdjustment(0, 0, 1, 1, 10, 0)
c.timeprocess = gtk.NewScale(gtk.OrientationHorizontal, c.timeadjustment)
c.timeprocess.AddCSSClass("timescale")
tsstext := gtk.NewLabel("testing")
timepopover := gtk.NewPopover()
timepopover.SetSizeRequest(80, 0)
timepopover.SetChild(tsstext)
timepopover.SetPosition(gtk.PosTop)
timepopover.SetAutohide(false)
boxroot.Append(timepopover)
timepopover.AddCSSClass("timePopup")
motionctrl := gtk.NewEventControllerMotion()
c.timeprocess.AddController(motionctrl)
motionctrl.ConnectEnter(func(x, y float64) {
glib.IdleAddPriority(glib.PRIORITY_HIGH_IDLE, func() {
rect := gdk.NewRectangle(int(x), 0, 0, 0)
timepopover.SetPointingTo(&rect)
timepopover.Show()
})
})
motionctrl.ConnectLeave(func() {
glib.IdleAddPriority(glib.PRIORITY_HIGH_IDLE, func() {
timepopover.Hide()
})
})
motionctrl.ConnectMotion(func(x, y float64) {
glib.IdleAddPriority(glib.PRIORITY_HIGH_IDLE, func() {
rect := gdk.NewRectangle(int(x), 0, 0, 0)
timepopover.SetPointingTo(&rect)
prr := math.Round(percent.PercentOf(int(x), c.timeprocess.AllocatedWidth()))
step := c.timeadjustment.StepIncrement()
value := (step*math.Round(prr*(c.duration-0)/step) + 0) / 100
drtime, _ := time.ParseDuration(fmt.Sprintf("%fs", value))
c.Lock()
c.lastValPos = drtime
c.Unlock()
currentTime := parsing.NewTime().Duration(drtime)
tsstext.SetText(currentTime)
if drtime.Seconds() < 0 {
timepopover.Hide()
} else if drtime.Seconds() > c.duration {
timepopover.Hide()
} else {
if !timepopover.IsVisible() {
timepopover.Show()
}
}
})
})
root.AddOverlay(c.timeprocess)
// add button for temp fixed when gtk scale not emitted release signal
c.btntracks = gtk.NewButton()
c.btntracks.SetCSSClasses([]string{"transparent-btn"})
clickges := gtk.NewGestureClick()
c.timeprocess.AddController(clickges)
clickges.ConnectPressed(func(nPress int, x, y float64) {
fmt.Println("ConnectPressed")
c.Lock()
c.seekOnHold = true
c.Unlock()
})
// use cancel for release signal
clickges.ConnectCancel(func(sequence *gdk.EventSequence) {
fmt.Println("ConnectCancel")
c.Lock()
c.seekOnHold = false
c.Unlock()
glib.IdleAddPriority(glib.PRIORITY_HIGH_IDLE, func() {
c.Lock()
val := c.lastValPos.Seconds()
c.Unlock()
c.timeadjustment.SetValue(val)
c.main.player.Bridge().Seek(val)
})
})
c.btntracks.SetChild(root)
c.timeprocess.SetSensitive(false)
c.cacheprocess.SetSensitive(false)
c.btntracks.SetSensitive(false)
boxroot.Append(c.btntracks)
return boxroot
}
并为透明按钮添加css
.transparent-btn{
background:transparent;
box-shadow: none;
border-radius: 0px;
border: 0px;
text-shadow: none;
-gtk-icon-shadow: none;
padding: 0px;
&:hover{
box-shadow: none;
background: transparent;
}
}