Scrolling over a ScrollContainer will now scroll it
This commit is contained in:
@@ -81,6 +81,21 @@ func (entity *entity) childAt (point image.Point) *entity {
|
||||
return entity
|
||||
}
|
||||
|
||||
func (entity *entity) scrollTargetChildAt (point image.Point) *entity {
|
||||
for _, child := range entity.children {
|
||||
if point.In(child.bounds) {
|
||||
result := child.scrollTargetChildAt(point)
|
||||
if result != nil { return result }
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := entity.element.(tomo.ScrollTarget); ok {
|
||||
return entity
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ----------- Entity ----------- //
|
||||
|
||||
func (entity *entity) Invalidate () {
|
||||
|
||||
@@ -190,20 +190,22 @@ func (window *window) handleButtonPress (
|
||||
insideWindow := point.In(window.canvas.Bounds())
|
||||
scrolling := buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7
|
||||
|
||||
underneath := window.system.childAt(point)
|
||||
|
||||
if !insideWindow && window.shy && !scrolling {
|
||||
window.Close()
|
||||
} else if scrolling {
|
||||
if child, ok := underneath.element.(tomo.ScrollTarget); ok {
|
||||
sum := scrollSum { }
|
||||
sum.add(buttonEvent.Detail, window, buttonEvent.State)
|
||||
window.compressScrollSum(buttonEvent, &sum)
|
||||
child.HandleScroll (
|
||||
point.X, point.Y,
|
||||
float64(sum.x), float64(sum.y))
|
||||
underneath := window.system.scrollTargetChildAt(point)
|
||||
if underneath != nil {
|
||||
if child, ok := underneath.element.(tomo.ScrollTarget); ok {
|
||||
sum := scrollSum { }
|
||||
sum.add(buttonEvent.Detail, window, buttonEvent.State)
|
||||
window.compressScrollSum(buttonEvent, &sum)
|
||||
child.HandleScroll (
|
||||
point.X, point.Y,
|
||||
float64(sum.x), float64(sum.y))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
underneath := window.system.childAt(point)
|
||||
if child, ok := underneath.element.(tomo.MouseTarget); ok {
|
||||
window.system.drags[buttonEvent.Detail] = child
|
||||
child.HandleMouseDown (
|
||||
|
||||
@@ -123,6 +123,11 @@ func (system *system) childAt (point image.Point) *entity {
|
||||
return system.child.childAt(point)
|
||||
}
|
||||
|
||||
func (system *system) scrollTargetChildAt (point image.Point) *entity {
|
||||
if system.child == nil { return nil }
|
||||
return system.child.scrollTargetChildAt(point)
|
||||
}
|
||||
|
||||
func (system *system) resizeChildToFit () {
|
||||
system.child.bounds = system.canvas.Bounds()
|
||||
system.child.clippedBounds = system.child.bounds
|
||||
|
||||
Reference in New Issue
Block a user