Removed redundant HandleWidth parameter from config

The handle width can be specified by themes with padding values.
This also allows for far more granularity of the handle width
adjustment as it can depend on context.
This commit is contained in:
Sasha Koshka 2023-03-31 13:55:45 -04:00
parent d1b5cd863a
commit c7cd944ae2
4 changed files with 12 additions and 37 deletions

View File

@ -2,14 +2,7 @@ package tomo
// Config can return global configuration parameters. // Config can return global configuration parameters.
type Config interface { type Config interface {
// HandleWidth returns how large grab handles should typically be. This
// is important for accessibility reasons.
HandleWidth () int
// 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
// ThemePath returns the directory path to the theme.
ThemePath () string
} }

View File

@ -6,43 +6,22 @@ import "git.tebibyte.media/sashakoshka/tomo"
type Default struct { } type Default struct { }
// HandleWidth returns the default handle width value.
func (Default) HandleWidth () int {
return 15
}
// ScrollVelocity returns the default scroll velocity value. // ScrollVelocity returns the default scroll velocity value.
func (Default) ScrollVelocity () int { func (Default) ScrollVelocity () int {
return 16 return 16
} }
// ThemePath returns the default theme path.
func (Default) ThemePath () (string) {
return ""
}
// 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
} }
// HandleWidth returns how large grab handles should typically be. This
// is important for accessibility reasons.
func (wrapped Wrapped) HandleWidth () int {
return wrapped.ensure().HandleWidth()
}
// 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.
func (wrapped Wrapped) ScrollVelocity () int { func (wrapped Wrapped) ScrollVelocity () int {
return wrapped.ensure().ScrollVelocity() return wrapped.ensure().ScrollVelocity()
} }
// ThemePath returns the directory path to the theme.
func (wrapped Wrapped) ThemePath () string {
return wrapped.ensure().ThemePath()
}
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 { } }

View File

@ -290,15 +290,16 @@ func (element *ScrollBar) recalculateHorizontal () {
} }
func (element *ScrollBar) updateMinimumSize () { func (element *ScrollBar) updateMinimumSize () {
padding := element.theme.Padding(tomo.PatternGutter) gutterPadding := element.theme.Padding(tomo.PatternGutter)
handlePadding := element.theme.Padding(tomo.PatternHandle)
if element.vertical { if element.vertical {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
padding.Horizontal() + element.config.HandleWidth(), gutterPadding.Horizontal() + handlePadding.Horizontal(),
padding.Vertical() + element.config.HandleWidth() * 2) gutterPadding.Vertical() + handlePadding.Vertical() * 2)
} else { } else {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
padding.Horizontal() + element.config.HandleWidth() * 2, gutterPadding.Horizontal() + handlePadding.Horizontal() * 2,
padding.Vertical() + element.config.HandleWidth()) gutterPadding.Vertical() + handlePadding.Vertical())
} }
} }

View File

@ -187,14 +187,16 @@ func (element *Slider) valueFor (x, y int) (value float64) {
} }
func (element *Slider) updateMinimumSize () { func (element *Slider) updateMinimumSize () {
gutterPadding := element.theme.Padding(tomo.PatternGutter)
handlePadding := element.theme.Padding(tomo.PatternHandle)
if element.vertical { if element.vertical {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
element.config.HandleWidth(), gutterPadding.Horizontal() + handlePadding.Horizontal(),
element.config.HandleWidth() * 2) gutterPadding.Vertical() + handlePadding.Vertical() * 2)
} else { } else {
element.core.SetMinimumSize ( element.core.SetMinimumSize (
element.config.HandleWidth() * 2, gutterPadding.Horizontal() + handlePadding.Horizontal() * 2,
element.config.HandleWidth()) gutterPadding.Vertical() + handlePadding.Vertical())
} }
} }