Scrolling over a ScrollContainer will now scroll it
This commit is contained in:
		
							parent
							
								
									b9c8350677
								
							
						
					
					
						commit
						7d4ddaf387
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -148,6 +148,16 @@ func (element *Scroll) HandleChildScrollBoundsChange (tomo.Scrollable) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (element *Scroll) HandleScroll (
 | 
			
		||||
	x, y int,
 | 
			
		||||
	deltaX, deltaY float64,
 | 
			
		||||
) {
 | 
			
		||||
	horizontal, vertical := element.child.ScrollAxes()
 | 
			
		||||
	if !horizontal { deltaX = 0 }
 | 
			
		||||
	if !vertical   { deltaY = 0 }
 | 
			
		||||
	element.scrollChildBy(int(deltaX), int(deltaY))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (element *Scroll) SetTheme (theme tomo.Theme) {
 | 
			
		||||
	if theme == element.theme.Theme { return }
 | 
			
		||||
	element.theme.Theme = theme
 | 
			
		||||
@ -195,3 +205,11 @@ func (element *Scroll) updateEnabled () {
 | 
			
		||||
		element.vertical.SetEnabled(vertical)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (element *Scroll) scrollChildBy (x, y int) {
 | 
			
		||||
	if element.child == nil { return }
 | 
			
		||||
	scrollPoint :=
 | 
			
		||||
		element.child.ScrollViewportBounds().Min.
 | 
			
		||||
		Add(image.Pt(x, y))
 | 
			
		||||
	element.child.ScrollTo(scrollPoint)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user