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:
parent
d1b5cd863a
commit
c7cd944ae2
@ -2,14 +2,7 @@ package tomo
|
||||
|
||||
// Config can return global configuration parameters.
|
||||
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
|
||||
// a scroll button is pressed.
|
||||
ScrollVelocity () int
|
||||
|
||||
// ThemePath returns the directory path to the theme.
|
||||
ThemePath () string
|
||||
}
|
||||
|
@ -6,43 +6,22 @@ import "git.tebibyte.media/sashakoshka/tomo"
|
||||
type Default struct { }
|
||||
|
||||
|
||||
// HandleWidth returns the default handle width value.
|
||||
func (Default) HandleWidth () int {
|
||||
return 15
|
||||
}
|
||||
|
||||
// ScrollVelocity returns the default scroll velocity value.
|
||||
func (Default) ScrollVelocity () int {
|
||||
return 16
|
||||
}
|
||||
|
||||
// ThemePath returns the default theme path.
|
||||
func (Default) ThemePath () (string) {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Wrapped wraps a configuration and uses Default if it is nil.
|
||||
type Wrapped struct {
|
||||
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
|
||||
// a scroll button is pressed.
|
||||
func (wrapped Wrapped) ScrollVelocity () int {
|
||||
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) {
|
||||
real = wrapped.Config
|
||||
if real == nil { real = Default { } }
|
||||
|
@ -290,15 +290,16 @@ func (element *ScrollBar) recalculateHorizontal () {
|
||||
}
|
||||
|
||||
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 {
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + element.config.HandleWidth(),
|
||||
padding.Vertical() + element.config.HandleWidth() * 2)
|
||||
gutterPadding.Horizontal() + handlePadding.Horizontal(),
|
||||
gutterPadding.Vertical() + handlePadding.Vertical() * 2)
|
||||
} else {
|
||||
element.core.SetMinimumSize (
|
||||
padding.Horizontal() + element.config.HandleWidth() * 2,
|
||||
padding.Vertical() + element.config.HandleWidth())
|
||||
gutterPadding.Horizontal() + handlePadding.Horizontal() * 2,
|
||||
gutterPadding.Vertical() + handlePadding.Vertical())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,14 +187,16 @@ func (element *Slider) valueFor (x, y int) (value float64) {
|
||||
}
|
||||
|
||||
func (element *Slider) updateMinimumSize () {
|
||||
gutterPadding := element.theme.Padding(tomo.PatternGutter)
|
||||
handlePadding := element.theme.Padding(tomo.PatternHandle)
|
||||
if element.vertical {
|
||||
element.core.SetMinimumSize (
|
||||
element.config.HandleWidth(),
|
||||
element.config.HandleWidth() * 2)
|
||||
gutterPadding.Horizontal() + handlePadding.Horizontal(),
|
||||
gutterPadding.Vertical() + handlePadding.Vertical() * 2)
|
||||
} else {
|
||||
element.core.SetMinimumSize (
|
||||
element.config.HandleWidth() * 2,
|
||||
element.config.HandleWidth())
|
||||
gutterPadding.Horizontal() + handlePadding.Horizontal() * 2,
|
||||
gutterPadding.Vertical() + handlePadding.Vertical())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user