Ok this is overstepping the bounds of this branch

This commit is contained in:
Sasha Koshka 2023-01-19 17:35:19 -05:00
parent 7b8cdd9e04
commit 78fb934afe
3 changed files with 97 additions and 9 deletions

View File

@ -59,8 +59,6 @@ func (element *Container) Adopt (child tomo.Element, expand bool) {
child0.OnSelectionRequest (func () (granted bool) {
return element.childSelectionRequestCallback(child0)
})
}
if child0, ok := child.(tomo.Selectable); ok {
child0.OnSelectionMotionRequest (
func (direction tomo.SelectionDirection) (granted bool) {
if element.onSelectionMotionRequest == nil { return }

View File

@ -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)

View File

@ -273,6 +273,10 @@ func (element *TextBox) ScrollAxes () (horizontal, vertical bool) {
return true, false
}
func (element *TextBox) OnScrollBoundsChange (callback func ()) {
element.onScrollBoundsChange = callback
}
func (element *TextBox) updateMinimumSize () {
textBounds := element.placeholderDrawer.LayoutBounds()
element.core.SetMinimumSize (