Removed Context and Control from event handlers.
This commit is contained in:
parent
36d620108c
commit
4d05127c6d
@ -4,7 +4,7 @@ import (
|
|||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SelectedChangedFn func(ctx Context, c Control, selected bool)
|
type SelectedChangedFn func(selected bool)
|
||||||
|
|
||||||
type Checkbox struct {
|
type Checkbox struct {
|
||||||
ControlBase
|
ControlBase
|
||||||
@ -100,7 +100,7 @@ func (c *Checkbox) Handle(ctx Context, e Event) {
|
|||||||
c.Selected = !c.Selected
|
c.Selected = !c.Selected
|
||||||
onSelectedChanged := c.onSelectedChanged
|
onSelectedChanged := c.onSelectedChanged
|
||||||
if onSelectedChanged != nil {
|
if onSelectedChanged != nil {
|
||||||
onSelectedChanged(ctx, c, c.Selected)
|
onSelectedChanged(c.Selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClickFn func(ctx Context, c Control, pos geom.PointF32, btn MouseButton)
|
type ClickFn func(pos geom.PointF32, btn MouseButton)
|
||||||
type DragEndFn func(ctx Context, c Control, start, end geom.PointF32)
|
type DragEndFn func(start, end geom.PointF32)
|
||||||
type DragMoveFn func(ctx Context, c Control, start, move geom.PointF32)
|
type DragMoveFn func(start, move geom.PointF32)
|
||||||
type DragStartFn func(ctx Context, c Control, start geom.PointF32)
|
type DragStartFn func(start geom.PointF32)
|
||||||
type MouseEnterFn func(ctx Context, c Control)
|
type MouseEnterFn func()
|
||||||
type MouseLeaveFn func(ctx Context, c Control)
|
type MouseLeaveFn func()
|
||||||
|
|
||||||
var _ Control = &ControlBase{}
|
var _ Control = &ControlBase{}
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ func (c *ControlBase) Handle(ctx Context, e Event) {
|
|||||||
var start = c.ToControlPosition(e.Pos())
|
var start = c.ToControlPosition(e.Pos())
|
||||||
c.dragStart = &start
|
c.dragStart = &start
|
||||||
if c.onDragStart != nil {
|
if c.onDragStart != nil {
|
||||||
c.onDragStart(ctx, c, start)
|
c.onDragStart(start)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var start = *c.dragStart
|
var start = *c.dragStart
|
||||||
var move = c.ToControlPosition(e.Pos())
|
var move = c.ToControlPosition(e.Pos())
|
||||||
if c.onDragMove != nil {
|
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())
|
var end = c.ToControlPosition(e.Pos())
|
||||||
c.dragStart = nil
|
c.dragStart = nil
|
||||||
if c.onDragEnd != nil {
|
if c.onDragEnd != nil {
|
||||||
c.onDragEnd(ctx, c, start, end)
|
c.onDragEnd(start, end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.pressed {
|
if c.pressed {
|
||||||
if c.onClick != nil {
|
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
|
c.pressed = false
|
||||||
|
@ -18,10 +18,10 @@ type Scrollbar struct {
|
|||||||
|
|
||||||
func BuildScrollbar(o Orientation, fn func(s *Scrollbar)) *Scrollbar {
|
func BuildScrollbar(o Orientation, fn func(s *Scrollbar)) *Scrollbar {
|
||||||
var s = &Scrollbar{Orientation: o, ContentLength: 0, ContentOffset: 0}
|
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.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 length = s.Orientation.SizeParallel(s.bounds)
|
||||||
var handleMaxOffset = length - s.Orientation.SizeParallel(s.handle.bounds)
|
var handleMaxOffset = length - s.Orientation.SizeParallel(s.handle.bounds)
|
||||||
var hidden = s.ContentLength - length
|
var hidden = s.ContentLength - length
|
||||||
|
Loading…
Reference in New Issue
Block a user