Removed Context and Control from event handlers.

This commit is contained in:
Sander Schobers 2019-07-06 07:42:11 +02:00
parent 36d620108c
commit 4d05127c6d
3 changed files with 14 additions and 14 deletions

View File

@ -4,7 +4,7 @@ import (
"opslag.de/schobers/geom"
)
type SelectedChangedFn func(ctx Context, c Control, selected bool)
type SelectedChangedFn func(selected bool)
type Checkbox struct {
ControlBase
@ -100,7 +100,7 @@ func (c *Checkbox) Handle(ctx Context, e Event) {
c.Selected = !c.Selected
onSelectedChanged := c.onSelectedChanged
if onSelectedChanged != nil {
onSelectedChanged(ctx, c, c.Selected)
onSelectedChanged(c.Selected)
}
}
}

View File

@ -6,12 +6,12 @@ import (
"opslag.de/schobers/geom"
)
type ClickFn func(ctx Context, c Control, pos geom.PointF32, btn MouseButton)
type DragEndFn func(ctx Context, c Control, start, end geom.PointF32)
type DragMoveFn func(ctx Context, c Control, start, move geom.PointF32)
type DragStartFn func(ctx Context, c Control, start geom.PointF32)
type MouseEnterFn func(ctx Context, c Control)
type MouseLeaveFn func(ctx Context, c Control)
type ClickFn func(pos geom.PointF32, btn MouseButton)
type DragEndFn func(start, end geom.PointF32)
type DragMoveFn func(start, move geom.PointF32)
type DragStartFn func(start geom.PointF32)
type MouseEnterFn func()
type MouseLeaveFn func()
var _ Control = &ControlBase{}
@ -66,13 +66,13 @@ func (c *ControlBase) Handle(ctx Context, e Event) {
var start = c.ToControlPosition(e.Pos())
c.dragStart = &start
if c.onDragStart != nil {
c.onDragStart(ctx, c, start)
c.onDragStart(start)
}
} else {
var start = *c.dragStart
var move = c.ToControlPosition(e.Pos())
if c.onDragMove != nil {
c.onDragMove(ctx, c, start, move)
c.onDragMove(start, move)
}
}
}
@ -90,12 +90,12 @@ func (c *ControlBase) Handle(ctx Context, e Event) {
var end = c.ToControlPosition(e.Pos())
c.dragStart = nil
if c.onDragEnd != nil {
c.onDragEnd(ctx, c, start, end)
c.onDragEnd(start, end)
}
}
if c.pressed {
if c.onClick != nil {
c.onClick(ctx, c, c.ToControlPosition(e.Pos()), e.Button)
c.onClick(c.ToControlPosition(e.Pos()), e.Button)
}
}
c.pressed = false

View File

@ -18,10 +18,10 @@ type Scrollbar struct {
func BuildScrollbar(o Orientation, fn func(s *Scrollbar)) *Scrollbar {
var s = &Scrollbar{Orientation: o, ContentLength: 0, ContentOffset: 0}
s.handle.OnDragStart(func(_ Context, _ Control, _ geom.PointF32) {
s.handle.OnDragStart(func(_ geom.PointF32) {
s.startDragOffset = s.ContentOffset
})
s.handle.OnDragMove(func(_ Context, _ Control, start, move geom.PointF32) {
s.handle.OnDragMove(func(start, move geom.PointF32) {
var length = s.Orientation.SizeParallel(s.bounds)
var handleMaxOffset = length - s.Orientation.SizeParallel(s.handle.bounds)
var hidden = s.ContentLength - length