diff --git a/ui/overflow.go b/ui/overflow.go index ff465f3..f7cf261 100644 --- a/ui/overflow.go +++ b/ui/overflow.go @@ -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 +} diff --git a/ui/scrollbar.go b/ui/scrollbar.go index db5ee5a..a6e72d1 100644 --- a/ui/scrollbar.go +++ b/ui/scrollbar.go @@ -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) }