Added clipping for Overflow/ScrollControl.
This commit is contained in:
parent
c0586c1d8f
commit
5dcecb8cc1
@ -11,6 +11,9 @@ type overflow struct {
|
||||
|
||||
Background color.Color
|
||||
|
||||
ClipHorizontal bool
|
||||
ClipVertical bool
|
||||
|
||||
barWidth float32
|
||||
desired geom.PointF32
|
||||
bounds geom.RectangleF32
|
||||
@ -26,18 +29,30 @@ type overflow struct {
|
||||
type ScrollControl interface {
|
||||
Control
|
||||
|
||||
SetBackgroundColor(color.Color)
|
||||
SetClipHorizontal(bool)
|
||||
SetClipVertical(bool)
|
||||
SetScrollbarColor(bar color.Color, hover color.Color)
|
||||
}
|
||||
|
||||
func BuildOverflow(content Control, build func(c ScrollControl)) ScrollControl {
|
||||
o := &overflow{Proxy: Proxy{Content: content}}
|
||||
o.hor = BuildScrollbar(OrientationHorizontal, func(*Scrollbar) {})
|
||||
o.ver = BuildScrollbar(OrientationVertical, func(*Scrollbar) {})
|
||||
if build != nil {
|
||||
build(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func Overflow(content Control) ScrollControl {
|
||||
return OverflowBackground(content, nil)
|
||||
}
|
||||
|
||||
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) {})
|
||||
return o
|
||||
return BuildOverflow(content, func(c ScrollControl) {
|
||||
c.SetBackgroundColor(back)
|
||||
})
|
||||
}
|
||||
|
||||
func (o *overflow) shouldScroll(bounds geom.RectangleF32) (hor bool, ver bool) {
|
||||
@ -53,6 +68,8 @@ func (o *overflow) shouldScroll(bounds geom.RectangleF32) (hor bool, ver bool) {
|
||||
if hor && !ver {
|
||||
ver = scroll(size.Y+o.barWidth, bounds.Dy())
|
||||
}
|
||||
hor = hor && !o.ClipHorizontal
|
||||
ver = ver && !o.ClipVertical
|
||||
return
|
||||
}
|
||||
|
||||
@ -158,6 +175,17 @@ func (o *overflow) Render(ctx Context) {
|
||||
bar.Render(ctx)
|
||||
})
|
||||
}
|
||||
func (o *overflow) SetBackgroundColor(c color.Color) {
|
||||
o.Background = c
|
||||
}
|
||||
|
||||
func (o *overflow) SetClipHorizontal(clip bool) {
|
||||
o.ClipHorizontal = clip
|
||||
}
|
||||
|
||||
func (o *overflow) SetClipVertical(clip bool) {
|
||||
o.ClipVertical = clip
|
||||
}
|
||||
|
||||
func (o *overflow) SetScrollbarColor(bar color.Color, hover color.Color) {
|
||||
o.hor.BarColor = bar
|
||||
|
Loading…
Reference in New Issue
Block a user