Scroll container mouse pass through

This commit is contained in:
Sasha Koshka 2023-01-19 18:03:50 -05:00
parent 71d50cab4b
commit 9c37cb8fef
3 changed files with 34 additions and 2 deletions

View File

@ -100,6 +100,31 @@ func (element *ScrollContainer) HandleKeyUp (key tomo.Key, modifiers tomo.Modifi
}
}
func (element *ScrollContainer) HandleMouseDown (x, y int, button tomo.Button) {
if child, ok := element.child.(tomo.MouseTarget); ok {
child.HandleMouseDown(x, y, button)
}
}
func (element *ScrollContainer) HandleMouseUp (x, y int, button tomo.Button) {
if child, ok := element.child.(tomo.MouseTarget); ok {
child.HandleMouseUp(x, y, button)
}
}
func (element *ScrollContainer) HandleMouseMove (x, y int) {
if child, ok := element.child.(tomo.MouseTarget); ok {
child.HandleMouseMove(x, y)
}
}
func (element *ScrollContainer) HandleMouseScroll (
x, y int,
deltaX, deltaY float64,
) {
// TODO: do not pass this down to the child
}
func (element *ScrollContainer) Selected () (selected bool) {
return element.selected
}
@ -213,6 +238,13 @@ func (element *ScrollContainer) draw () {
artist.Paste(element.core, element.child, image.Point { })
element.drawHorizontalBar()
element.drawVerticalBar()
artist.FillRectangle (
element, theme.BackgroundPattern(),
image.Rect (
element.vertical.bounds.Min.X,
element.horizontal.bounds.Min.Y,
element.vertical.bounds.Max.X,
element.horizontal.bounds.Max.Y))
}
func (element *ScrollContainer) drawHorizontalBar () {

View File

@ -58,7 +58,7 @@ func (element *TextBox) HandleMouseDown (x, y int, button tomo.Button) {
func (element *TextBox) HandleMouseUp (x, y int, button tomo.Button) { }
func (element *TextBox) HandleMouseMove (x, y int) { }
func (element *TextBox) HandleScroll (x, y int, deltaX, deltaY float64) { }
func (element *TextBox) HandleMouseScroll (x, y int, deltaX, deltaY float64) { }
func (element *TextBox) HandleKeyDown (
key tomo.Key,

View File

@ -20,7 +20,7 @@ func run () {
textBox := basic.NewTextBox("", "sample text sample text")
scrollContainer := basic.NewScrollContainer(true, true)
scrollContainer.Adopt(textBox)
container.Adopt(scrollContainer, false)
container.Adopt(scrollContainer, true)
window.OnClose(tomo.Stop)
window.Show()