Added override for scrollbar color.

This commit is contained in:
Sander Schobers 2020-12-12 14:43:07 +01:00
parent b0a13d1a3c
commit 7d5168614e
2 changed files with 33 additions and 6 deletions

View File

@ -23,11 +23,17 @@ type overflow struct {
ver *Scrollbar
}
func Overflow(content Control) Control {
type ScrollControl interface {
Control
SetScrollbarColor(bar color.Color, hover color.Color)
}
func Overflow(content Control) ScrollControl {
return OverflowBackground(content, nil)
}
func OverflowBackground(content Control, back color.Color) Control {
func OverflowBackground(content Control, back color.Color) ScrollControl {
var o = &overflow{Proxy: Proxy{Content: content}, Background: back}
o.hor = BuildScrollbar(OrientationHorizontal, func(*Scrollbar) {})
o.ver = BuildScrollbar(OrientationVertical, func(*Scrollbar) {})
@ -152,3 +158,10 @@ func (o *overflow) Render(ctx Context) {
bar.Render(ctx)
})
}
func (o *overflow) SetScrollbarColor(bar color.Color, hover color.Color) {
o.hor.BarColor = bar
o.hor.BarHoverColor = hover
o.ver.BarColor = bar
o.ver.BarHoverColor = hover
}

View File

@ -1,6 +1,8 @@
package ui
import (
"image/color"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg"
)
@ -10,6 +12,8 @@ type Scrollbar struct {
Orientation Orientation
BarColor color.Color
BarHoverColor color.Color
ContentLength float32
ContentOffset float32
@ -58,7 +62,7 @@ func (s *Scrollbar) Handle(ctx Context, e Event) bool {
func (s *Scrollbar) Render(ctx Context) {
ctx.Renderer().FillRectangle(s.bounds, zntg.RGBA(0, 0, 0, 1))
s.handle.Render(ctx)
s.handle.Render(ctx, s)
}
func (s *Scrollbar) updateBar(ctx Context) {
@ -83,12 +87,22 @@ type ScrollbarHandle struct {
ControlBase
}
func (h *ScrollbarHandle) Render(ctx Context) {
func (h *ScrollbarHandle) Render(ctx Context, s *Scrollbar) {
h.RenderBackground(ctx)
p := ctx.Style().Palette
fill := p.Primary
var fill color.Color
if h.over {
fill = p.PrimaryLight
if s.BarHoverColor == nil {
fill = p.PrimaryLight
} else {
fill = s.BarHoverColor
}
} else {
if s.BarColor == nil {
fill = p.Primary
} else {
fill = s.BarColor
}
}
ctx.Renderer().FillRectangle(h.bounds.Inset(1), fill)
}