Added double click delay to config
This commit is contained in:
parent
c7cd944ae2
commit
03dfcf02bf
@ -1,8 +1,14 @@
|
|||||||
package tomo
|
package tomo
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Config can return global configuration parameters.
|
// Config can return global configuration parameters.
|
||||||
type Config interface {
|
type Config interface {
|
||||||
// ScrollVelocity returns how many pixels should be scrolled every time
|
// ScrollVelocity returns how many pixels should be scrolled every time
|
||||||
// a scroll button is pressed.
|
// a scroll button is pressed.
|
||||||
ScrollVelocity () int
|
ScrollVelocity () int
|
||||||
|
|
||||||
|
// DoubleClickDelay returns the maximum delay between two clicks for
|
||||||
|
// them to be registered as a double click.
|
||||||
|
DoubleClickDelay () time.Duration
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "time"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
|
|
||||||
// Default specifies default configuration values.
|
// Default specifies default configuration values.
|
||||||
@ -11,17 +12,28 @@ func (Default) ScrollVelocity () int {
|
|||||||
return 16
|
return 16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DoubleClickDelay returns the default double click delay.
|
||||||
|
func (Default) DoubleClickDelay () time.Duration {
|
||||||
|
return time.Second / 2
|
||||||
|
}
|
||||||
|
|
||||||
// Wrapped wraps a configuration and uses Default if it is nil.
|
// Wrapped wraps a configuration and uses Default if it is nil.
|
||||||
type Wrapped struct {
|
type Wrapped struct {
|
||||||
tomo.Config
|
tomo.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollVelocity returns how many pixels should be scrolled every time
|
// ScrollVelocity returns how many pixels should be scrolled every time a scroll
|
||||||
// a scroll button is pressed.
|
// button is pressed.
|
||||||
func (wrapped Wrapped) ScrollVelocity () int {
|
func (wrapped Wrapped) ScrollVelocity () int {
|
||||||
return wrapped.ensure().ScrollVelocity()
|
return wrapped.ensure().ScrollVelocity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DoubleClickDelay returns the maximum delay between two clicks for them to be
|
||||||
|
// registered as a double click.
|
||||||
|
func (wrapped Wrapped) DoubleClickDelay () time.Duration {
|
||||||
|
return wrapped.ensure().DoubleClickDelay()
|
||||||
|
}
|
||||||
|
|
||||||
func (wrapped Wrapped) ensure () (real tomo.Config) {
|
func (wrapped Wrapped) ensure () (real tomo.Config) {
|
||||||
real = wrapped.Config
|
real = wrapped.Config
|
||||||
if real == nil { real = Default { } }
|
if real == nil { real = Default { } }
|
||||||
|
@ -238,6 +238,10 @@ func (element *Directory) partition () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *Directory) Window () tomo.Window {
|
||||||
|
return element.core.Window()
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyMinimumSizeChange notifies the container that the minimum size of a
|
// NotifyMinimumSizeChange notifies the container that the minimum size of a
|
||||||
// child element has changed.
|
// child element has changed.
|
||||||
func (element *Directory) NotifyMinimumSizeChange (child tomo.Element) {
|
func (element *Directory) NotifyMinimumSizeChange (child tomo.Element) {
|
||||||
|
@ -132,7 +132,7 @@ func (element *File) HandleMouseUp (x, y int, button input.Button) {
|
|||||||
element.pressed = false
|
element.pressed = false
|
||||||
within := image.Point { x, y }.
|
within := image.Point { x, y }.
|
||||||
In(element.Bounds())
|
In(element.Bounds())
|
||||||
if time.Since(element.lastClick) < time.Second / 2 {
|
if time.Since(element.lastClick) < element.config.DoubleClickDelay() {
|
||||||
if element.Enabled() && within && element.onChoose != nil {
|
if element.Enabled() && within && element.onChoose != nil {
|
||||||
element.onChoose()
|
element.onChoose()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user