From 03dfcf02bf33902e9ed8bc0c31eff29d21052807 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 31 Mar 2023 14:02:56 -0400 Subject: [PATCH] Added double click delay to config --- config.go | 6 ++++++ default/config/config.go | 16 ++++++++++++++-- elements/file/directory.go | 4 ++++ elements/file/file.go | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index bcbcf7d..7011aa3 100644 --- a/config.go +++ b/config.go @@ -1,8 +1,14 @@ package tomo +import "time" + // Config can return global configuration parameters. type Config interface { // ScrollVelocity returns how many pixels should be scrolled every time // a scroll button is pressed. ScrollVelocity () int + + // DoubleClickDelay returns the maximum delay between two clicks for + // them to be registered as a double click. + DoubleClickDelay () time.Duration } diff --git a/default/config/config.go b/default/config/config.go index 249de4e..0d35567 100644 --- a/default/config/config.go +++ b/default/config/config.go @@ -1,5 +1,6 @@ package config +import "time" import "git.tebibyte.media/sashakoshka/tomo" // Default specifies default configuration values. @@ -11,17 +12,28 @@ func (Default) ScrollVelocity () int { 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. type Wrapped struct { tomo.Config } -// ScrollVelocity returns how many pixels should be scrolled every time -// a scroll button is pressed. +// ScrollVelocity returns how many pixels should be scrolled every time a scroll +// button is pressed. func (wrapped Wrapped) ScrollVelocity () int { 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) { real = wrapped.Config if real == nil { real = Default { } } diff --git a/elements/file/directory.go b/elements/file/directory.go index b1bca08..df352cf 100644 --- a/elements/file/directory.go +++ b/elements/file/directory.go @@ -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 // child element has changed. func (element *Directory) NotifyMinimumSizeChange (child tomo.Element) { diff --git a/elements/file/file.go b/elements/file/file.go index b3a1db8..9c6a743 100644 --- a/elements/file/file.go +++ b/elements/file/file.go @@ -132,7 +132,7 @@ func (element *File) HandleMouseUp (x, y int, button input.Button) { element.pressed = false within := image.Point { x, y }. 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 { element.onChoose() }