robust-parenting #12
@ -94,6 +94,30 @@ func (window *window) NotifyMinimumSizeChange (child elements.Element) {
|
|||||||
window.childMinimumSizeChangeCallback(child.MinimumSize())
|
window.childMinimumSizeChangeCallback(child.MinimumSize())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (window *window) RequestFocus (
|
||||||
|
child elements.Focusable,
|
||||||
|
) (
|
||||||
|
granted bool,
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (window *window) RequestFocusNext (child elements.Focusable) {
|
||||||
|
if child, ok := window.child.(elements.Focusable); ok {
|
||||||
|
if !child.HandleFocus(input.KeynavDirectionForward) {
|
||||||
|
child.HandleUnfocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (window *window) RequestFocusPrevious (child elements.Focusable) {
|
||||||
|
if child, ok := window.child.(elements.Focusable); ok {
|
||||||
|
if !child.HandleFocus(input.KeynavDirectionBackward) {
|
||||||
|
child.HandleUnfocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (window *window) Adopt (child elements.Element) {
|
func (window *window) Adopt (child elements.Element) {
|
||||||
// disown previous child
|
// disown previous child
|
||||||
if window.child != nil {
|
if window.child != nil {
|
||||||
@ -305,27 +329,6 @@ func (window *window) childMinimumSizeChangeCallback (width, height int) (resize
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (window *window) childSelectionRequestCallback () (granted bool) {
|
|
||||||
if _, ok := window.child.(elements.Focusable); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (window *window) childSelectionMotionRequestCallback (
|
|
||||||
direction input.KeynavDirection,
|
|
||||||
) (
|
|
||||||
granted bool,
|
|
||||||
) {
|
|
||||||
if child, ok := window.child.(elements.Focusable); ok {
|
|
||||||
if !child.HandleFocus(direction) {
|
|
||||||
child.HandleUnfocus()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (window *window) pushRegion (region image.Rectangle) {
|
func (window *window) pushRegion (region image.Rectangle) {
|
||||||
if window.xCanvas == nil { panic("whoopsie!!!!!!!!!!!!!!") }
|
if window.xCanvas == nil { panic("whoopsie!!!!!!!!!!!!!!") }
|
||||||
image, ok := window.xCanvas.SubImage(region).(*xgraphics.Image)
|
image, ok := window.xCanvas.SubImage(region).(*xgraphics.Image)
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package elements
|
package elements
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
|
||||||
|
|
||||||
// Parent represents a type capable of containing child elements.
|
// Parent represents a type capable of containing child elements.
|
||||||
type Parent interface {
|
type Parent interface {
|
||||||
// NotifyMinimumSizeChange notifies the container that a child element's
|
// NotifyMinimumSizeChange notifies the container that a child element's
|
||||||
|
@ -51,8 +51,7 @@ func (propagator *Propagator) Focus () {
|
|||||||
parent := propagator.core.Parent()
|
parent := propagator.core.Parent()
|
||||||
if parent, ok := parent.(elements.FocusableParent); ok && parent != nil {
|
if parent, ok := parent.(elements.FocusableParent); ok && parent != nil {
|
||||||
propagator.focused = parent.RequestFocus (
|
propagator.focused = parent.RequestFocus (
|
||||||
propagator.core.Outer().(elements.Focusable),
|
propagator.core.Outer().(elements.Focusable))
|
||||||
input.KeynavDirectionNeutral)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +130,8 @@ func (propagator *Propagator) RequestFocus (
|
|||||||
) (
|
) (
|
||||||
granted bool,
|
granted bool,
|
||||||
) {
|
) {
|
||||||
// TODO implement this, and also implement it for the x backend window
|
|
||||||
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
||||||
if parent.RequestFocus(propagator) {
|
if parent.RequestFocus(propagator.core.Outer().(elements.Focusable)) {
|
||||||
propagator.focused = true
|
propagator.focused = true
|
||||||
granted = true
|
granted = true
|
||||||
}
|
}
|
||||||
@ -146,7 +144,7 @@ func (propagator *Propagator) RequestFocus (
|
|||||||
func (propagator *Propagator) RequestFocusNext (child elements.Focusable) {
|
func (propagator *Propagator) RequestFocusNext (child elements.Focusable) {
|
||||||
if !propagator.focused { return }
|
if !propagator.focused { return }
|
||||||
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
||||||
parent.RequestFocusNext(propagator)
|
parent.RequestFocusNext(propagator.core.Outer().(elements.Focusable))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +153,7 @@ func (propagator *Propagator) RequestFocusNext (child elements.Focusable) {
|
|||||||
func (propagator *Propagator) RequestFocusPrevious (child elements.Focusable) {
|
func (propagator *Propagator) RequestFocusPrevious (child elements.Focusable) {
|
||||||
if !propagator.focused { return }
|
if !propagator.focused { return }
|
||||||
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
||||||
parent.RequestFocusPrevious(propagator)
|
parent.RequestFocusPrevious(propagator.core.Outer().(elements.Focusable))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user