|
|
|
@ -24,7 +24,8 @@ type ScrollContainer struct {
|
|
|
|
|
bounds image.Rectangle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO event handlers
|
|
|
|
|
onSelectionRequest func () (granted bool)
|
|
|
|
|
onSelectionMotionRequest func (tomo.SelectionDirection) (granted bool)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewScrollContainer creates a new scroll container with the specified scroll
|
|
|
|
@ -60,12 +61,14 @@ func (element *ScrollContainer) Adopt (child tomo.Scrollable) {
|
|
|
|
|
// adopt new child
|
|
|
|
|
element.child = child
|
|
|
|
|
if child != nil {
|
|
|
|
|
// child.SetParentHooks (tomo.ParentHooks {
|
|
|
|
|
// Draw: window.childDrawCallback,
|
|
|
|
|
// MinimumSizeChange: window.childMinimumSizeChangeCallback,
|
|
|
|
|
// FlexibleHeightChange: window.resizeChildToFit,
|
|
|
|
|
// SelectionRequest: window.childSelectionRequestCallback,
|
|
|
|
|
// })
|
|
|
|
|
child.OnDamage(element.childDamageCallback)
|
|
|
|
|
child.OnMinimumSizeChange(element.updateMinimumSize)
|
|
|
|
|
if newChild, ok := child.(tomo.Selectable); ok {
|
|
|
|
|
newChild.OnSelectionRequest (
|
|
|
|
|
element.childSelectionRequestCallback)
|
|
|
|
|
newChild.OnSelectionMotionRequest (
|
|
|
|
|
element.childSelectionMotionRequestCallback)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: somehow inform the core that we do not in fact want to
|
|
|
|
|
// redraw the element.
|
|
|
|
@ -81,6 +84,89 @@ func (element *ScrollContainer) Adopt (child tomo.Scrollable) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) HandleKeyDown (
|
|
|
|
|
key tomo.Key,
|
|
|
|
|
modifiers tomo.Modifiers,
|
|
|
|
|
repeated bool,
|
|
|
|
|
) {
|
|
|
|
|
if child, ok := element.child.(tomo.KeyboardTarget); ok {
|
|
|
|
|
child.HandleKeyDown(key, modifiers, repeated)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) HandleKeyUp (key tomo.Key, modifiers tomo.Modifiers) {
|
|
|
|
|
if child, ok := element.child.(tomo.KeyboardTarget); ok {
|
|
|
|
|
child.HandleKeyUp(key, modifiers)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) Selected () (selected bool) {
|
|
|
|
|
return element.selected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) Select () {
|
|
|
|
|
if element.onSelectionRequest != nil {
|
|
|
|
|
element.onSelectionRequest()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) HandleSelection (
|
|
|
|
|
direction tomo.SelectionDirection,
|
|
|
|
|
) (
|
|
|
|
|
accepted bool,
|
|
|
|
|
) {
|
|
|
|
|
if child, ok := element.child.(tomo.Selectable); ok {
|
|
|
|
|
element.selected = true
|
|
|
|
|
return child.HandleSelection(direction)
|
|
|
|
|
} else {
|
|
|
|
|
element.selected = false
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) HandleDeselection () {
|
|
|
|
|
if child, ok := element.child.(tomo.Selectable); ok {
|
|
|
|
|
child.HandleDeselection()
|
|
|
|
|
}
|
|
|
|
|
element.selected = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) OnSelectionRequest (callback func () (granted bool)) {
|
|
|
|
|
element.onSelectionRequest = callback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) OnSelectionMotionRequest (
|
|
|
|
|
callback func (direction tomo.SelectionDirection) (granted bool),
|
|
|
|
|
) {
|
|
|
|
|
element.onSelectionMotionRequest = callback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) childDamageCallback (region tomo.Canvas) {
|
|
|
|
|
element.core.DamageRegion(artist.Paste(element, region, image.Point { }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) childSelectionRequestCallback () (granted bool) {
|
|
|
|
|
child, ok := element.child.(tomo.Selectable)
|
|
|
|
|
if !ok { return false }
|
|
|
|
|
if element.onSelectionRequest != nil && element.onSelectionRequest() {
|
|
|
|
|
child.HandleSelection(tomo.SelectionDirectionNeutral)
|
|
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) childSelectionMotionRequestCallback (
|
|
|
|
|
direction tomo.SelectionDirection,
|
|
|
|
|
) (
|
|
|
|
|
granted bool,
|
|
|
|
|
) {
|
|
|
|
|
if element.onSelectionMotionRequest == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return element.onSelectionMotionRequest(direction)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (element *ScrollContainer) clearChildEventHandlers (child tomo.Element) {
|
|
|
|
|
child.OnDamage(nil)
|
|
|
|
|
child.OnMinimumSizeChange(nil)
|
|
|
|
|