From 4d05127c6d9ec021c920f3c97dd9551940a3bfd0 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 6 Jul 2019 07:42:11 +0200 Subject: [PATCH] Removed Context and Control from event handlers. --- ui/checkbox.go | 4 ++-- ui/controlbase.go | 20 ++++++++++---------- ui/scrollbar.go | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/checkbox.go b/ui/checkbox.go index 94b099b..82ee165 100644 --- a/ui/checkbox.go +++ b/ui/checkbox.go @@ -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) } } } diff --git a/ui/controlbase.go b/ui/controlbase.go index 5f858e3..f430c78 100644 --- a/ui/controlbase.go +++ b/ui/controlbase.go @@ -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 diff --git a/ui/scrollbar.go b/ui/scrollbar.go index 27fe8bb..1c9b3fc 100644 --- a/ui/scrollbar.go +++ b/ui/scrollbar.go @@ -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