Ok this is overstepping the bounds of this branch
This commit is contained in:
parent
7b8cdd9e04
commit
78fb934afe
@ -59,8 +59,6 @@ func (element *Container) Adopt (child tomo.Element, expand bool) {
|
|||||||
child0.OnSelectionRequest (func () (granted bool) {
|
child0.OnSelectionRequest (func () (granted bool) {
|
||||||
return element.childSelectionRequestCallback(child0)
|
return element.childSelectionRequestCallback(child0)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
if child0, ok := child.(tomo.Selectable); ok {
|
|
||||||
child0.OnSelectionMotionRequest (
|
child0.OnSelectionMotionRequest (
|
||||||
func (direction tomo.SelectionDirection) (granted bool) {
|
func (direction tomo.SelectionDirection) (granted bool) {
|
||||||
if element.onSelectionMotionRequest == nil { return }
|
if element.onSelectionMotionRequest == nil { return }
|
||||||
|
@ -24,7 +24,8 @@ type ScrollContainer struct {
|
|||||||
bounds image.Rectangle
|
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
|
// NewScrollContainer creates a new scroll container with the specified scroll
|
||||||
@ -60,12 +61,14 @@ func (element *ScrollContainer) Adopt (child tomo.Scrollable) {
|
|||||||
// adopt new child
|
// adopt new child
|
||||||
element.child = child
|
element.child = child
|
||||||
if child != nil {
|
if child != nil {
|
||||||
// child.SetParentHooks (tomo.ParentHooks {
|
child.OnDamage(element.childDamageCallback)
|
||||||
// Draw: window.childDrawCallback,
|
child.OnMinimumSizeChange(element.updateMinimumSize)
|
||||||
// MinimumSizeChange: window.childMinimumSizeChangeCallback,
|
if newChild, ok := child.(tomo.Selectable); ok {
|
||||||
// FlexibleHeightChange: window.resizeChildToFit,
|
newChild.OnSelectionRequest (
|
||||||
// SelectionRequest: window.childSelectionRequestCallback,
|
element.childSelectionRequestCallback)
|
||||||
// })
|
newChild.OnSelectionMotionRequest (
|
||||||
|
element.childSelectionMotionRequestCallback)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: somehow inform the core that we do not in fact want to
|
// TODO: somehow inform the core that we do not in fact want to
|
||||||
// redraw the element.
|
// 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) {
|
func (element *ScrollContainer) clearChildEventHandlers (child tomo.Element) {
|
||||||
child.OnDamage(nil)
|
child.OnDamage(nil)
|
||||||
child.OnMinimumSizeChange(nil)
|
child.OnMinimumSizeChange(nil)
|
||||||
|
@ -273,6 +273,10 @@ func (element *TextBox) ScrollAxes () (horizontal, vertical bool) {
|
|||||||
return true, false
|
return true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *TextBox) OnScrollBoundsChange (callback func ()) {
|
||||||
|
element.onScrollBoundsChange = callback
|
||||||
|
}
|
||||||
|
|
||||||
func (element *TextBox) updateMinimumSize () {
|
func (element *TextBox) updateMinimumSize () {
|
||||||
textBounds := element.placeholderDrawer.LayoutBounds()
|
textBounds := element.placeholderDrawer.LayoutBounds()
|
||||||
element.core.SetMinimumSize (
|
element.core.SetMinimumSize (
|
||||||
|
Reference in New Issue
Block a user