2018-09-09 19:07:53 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"opslag.de/schobers/geom"
|
2018-09-23 07:42:23 +00:00
|
|
|
"opslag.de/schobers/zntg/allg5"
|
2018-09-09 19:07:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type scroll struct {
|
|
|
|
Wrapper
|
|
|
|
Content Control
|
|
|
|
Bar *ContentScrollbar
|
|
|
|
}
|
|
|
|
|
|
|
|
func Scroll(c Control, o Orientation) Control {
|
|
|
|
var dock = NewDockPanel(nil)
|
|
|
|
var bar = &ContentScrollbar{Orientation: o}
|
|
|
|
switch o {
|
|
|
|
case OrientationHorizontal:
|
|
|
|
dock.Append(DockBottom, TopMargin(bar, ScrollbarWidth))
|
|
|
|
dock.Append(DockBottom, c)
|
|
|
|
case OrientationVertical:
|
|
|
|
dock.Append(DockRight, LeftMargin(bar, ScrollbarWidth))
|
|
|
|
dock.Append(DockRight, c)
|
|
|
|
}
|
|
|
|
var s = &scroll{Wrap(dock), c, bar}
|
2018-09-23 07:42:23 +00:00
|
|
|
bar.OnChanged = func(v float32) {
|
2018-09-09 19:07:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2018-09-22 14:23:26 +00:00
|
|
|
func (s *scroll) Handle(ctx Context, ev allg5.Event) {
|
2018-09-09 19:07:53 +00:00
|
|
|
s.Wrapper.Handle(ctx, ev)
|
|
|
|
switch e := ev.(type) {
|
2018-09-22 14:23:26 +00:00
|
|
|
case *allg5.MouseMoveEvent:
|
2018-09-23 07:42:23 +00:00
|
|
|
if 0 != e.DeltaZ && !s.Bar.IsOver && geom.PtF32(float32(e.X), float32(e.Y)).In(s.Bounds) {
|
2018-09-09 19:07:53 +00:00
|
|
|
var d = e.DeltaZ
|
2018-09-22 14:23:26 +00:00
|
|
|
if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
|
2018-09-09 19:07:53 +00:00
|
|
|
d *= 10
|
|
|
|
}
|
|
|
|
s.Bar.increment(d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *scroll) Render(ctx Context) {
|
|
|
|
var bounds = s.Content.Rect()
|
|
|
|
var w, h = bounds.Dx(), bounds.Dy()
|
2018-09-22 14:23:26 +00:00
|
|
|
var bmp, err = allg5.NewVideoBitmap(int(w), int(h))
|
2018-09-09 19:07:53 +00:00
|
|
|
if nil != err {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer bmp.Destroy()
|
|
|
|
bmp.SetAsTarget()
|
|
|
|
switch s.Bar.Orientation {
|
|
|
|
case OrientationHorizontal:
|
2018-09-23 07:42:23 +00:00
|
|
|
Arrange(ctx, s.Content, geom.RectF32(-s.Bar.Value, 0, w, h))
|
2018-09-09 19:07:53 +00:00
|
|
|
case OrientationVertical:
|
2018-09-23 07:42:23 +00:00
|
|
|
Arrange(ctx, s.Content, geom.RectF32(0, -s.Bar.Value, w, h))
|
2018-09-09 19:07:53 +00:00
|
|
|
}
|
|
|
|
s.Content.Render(ctx)
|
|
|
|
ctx.Display().SetAsTarget()
|
2018-09-23 07:42:23 +00:00
|
|
|
var min = s.Bounds.Min
|
2018-09-09 19:07:53 +00:00
|
|
|
bmp.Draw(min.X, min.Y)
|
|
|
|
s.Bar.Render(ctx)
|
|
|
|
}
|
|
|
|
|
2018-09-23 07:42:23 +00:00
|
|
|
func (s *scroll) Arrange(ctx Context, rect geom.RectangleF32) {
|
2018-09-09 19:07:53 +00:00
|
|
|
var sz = s.Content.DesiredSize(ctx)
|
|
|
|
switch s.Bar.Orientation {
|
|
|
|
case OrientationHorizontal:
|
|
|
|
s.Bar.Length = sz.X
|
|
|
|
case OrientationVertical:
|
|
|
|
s.Bar.Length = sz.Y
|
|
|
|
}
|
|
|
|
s.Wrapper.Arrange(ctx, rect)
|
|
|
|
}
|