atomize-element-interface #3
@ -261,6 +261,20 @@ func (window *Window) childSelectionRequestCallback () (granted bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (window *Window) childSelectionMotionRequestCallback (
|
||||||
|
direction tomo.SelectionDirection,
|
||||||
|
) (
|
||||||
|
granted bool,
|
||||||
|
) {
|
||||||
|
if child, ok := window.child.(tomo.Selectable); ok {
|
||||||
|
if !child.HandleSelection(direction) {
|
||||||
|
child.HandleDeselection()
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
20
element.go
20
element.go
@ -3,7 +3,8 @@ package tomo
|
|||||||
// ParentHooks is a struct that contains callbacks that let child elements send
|
// ParentHooks is a struct that contains callbacks that let child elements send
|
||||||
// information to their parent element without the child element knowing
|
// information to their parent element without the child element knowing
|
||||||
// anything about the parent element or containing any reference to it. When a
|
// anything about the parent element or containing any reference to it. When a
|
||||||
// parent element adopts a child element, it must set these callbacks.
|
// parent element adopts a child element, it must set these callbacks. They are
|
||||||
|
// allowed to be nil.
|
||||||
type ParentHooks struct {
|
type ParentHooks struct {
|
||||||
// Draw is called when a part of the child element's surface is updated.
|
// Draw is called when a part of the child element's surface is updated.
|
||||||
// The updated region will be passed to the callback as a sub-image.
|
// The updated region will be passed to the callback as a sub-image.
|
||||||
@ -20,6 +21,10 @@ type ParentHooks struct {
|
|||||||
// request, it must send the child element a selection event and return
|
// request, it must send the child element a selection event and return
|
||||||
// true.
|
// true.
|
||||||
SelectionRequest func () (granted bool)
|
SelectionRequest func () (granted bool)
|
||||||
|
|
||||||
|
// SelectionMotionRequest is called when the child element wants the
|
||||||
|
// parent element to select the previous/next element in relation to it.
|
||||||
|
SelectionMotionRequest func (direction SelectionDirection) (granted bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunDraw runs the Draw hook if it is not nil. If it is nil, it does nothing.
|
// RunDraw runs the Draw hook if it is not nil. If it is nil, it does nothing.
|
||||||
@ -46,6 +51,19 @@ func (hooks ParentHooks) RunSelectionRequest () (granted bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunSelectionMotionRequest runs the SelectionMotionRequest hook if it is not
|
||||||
|
// nil. If it is nil, it does nothing.
|
||||||
|
func (hooks ParentHooks) RunSelectionMotionRequest (
|
||||||
|
direction SelectionDirection,
|
||||||
|
) (
|
||||||
|
granted bool,
|
||||||
|
) {
|
||||||
|
if hooks.SelectionMotionRequest != nil {
|
||||||
|
granted = hooks.SelectionMotionRequest(direction)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Element represents a basic on-screen object.
|
// Element represents a basic on-screen object.
|
||||||
type Element interface {
|
type Element interface {
|
||||||
// Element must implement the Canvas interface. Elements should start
|
// Element must implement the Canvas interface. Elements should start
|
||||||
|
@ -103,6 +103,7 @@ func (element *Button) HandleSelection (
|
|||||||
) (
|
) (
|
||||||
accepted bool,
|
accepted bool,
|
||||||
) {
|
) {
|
||||||
|
direction = direction.Canon()
|
||||||
if !element.enabled { return false }
|
if !element.enabled { return false }
|
||||||
if element.selected && direction != tomo.SelectionDirectionNeutral {
|
if element.selected && direction != tomo.SelectionDirectionNeutral {
|
||||||
return false
|
return false
|
||||||
|
@ -43,6 +43,9 @@ func (element *Container) SetLayout (layout tomo.Layout) {
|
|||||||
// whatever way is defined by the current layout.
|
// whatever way is defined by the current layout.
|
||||||
func (element *Container) Adopt (child tomo.Element, expand bool) {
|
func (element *Container) Adopt (child tomo.Element, expand bool) {
|
||||||
child.SetParentHooks (tomo.ParentHooks {
|
child.SetParentHooks (tomo.ParentHooks {
|
||||||
|
Draw: func (region tomo.Canvas) {
|
||||||
|
element.drawChildRegion(child, region)
|
||||||
|
},
|
||||||
MinimumSizeChange: func (int, int) {
|
MinimumSizeChange: func (int, int) {
|
||||||
element.updateMinimumSize()
|
element.updateMinimumSize()
|
||||||
},
|
},
|
||||||
@ -51,8 +54,12 @@ func (element *Container) Adopt (child tomo.Element, expand bool) {
|
|||||||
if !selectable { return }
|
if !selectable { return }
|
||||||
return element.childSelectionRequestCallback(child)
|
return element.childSelectionRequestCallback(child)
|
||||||
},
|
},
|
||||||
Draw: func (region tomo.Canvas) {
|
SelectionMotionRequest: func (
|
||||||
element.drawChildRegion(child, region)
|
direction tomo.SelectionDirection,
|
||||||
|
) (
|
||||||
|
granted bool,
|
||||||
|
) {
|
||||||
|
return element.core.RequestSelectionMotion(direction)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
element.children = append (element.children, tomo.LayoutEntry {
|
element.children = append (element.children, tomo.LayoutEntry {
|
||||||
|
@ -80,6 +80,18 @@ func (control CoreControl) RequestSelection () (granted bool) {
|
|||||||
return control.core.hooks.RunSelectionRequest()
|
return control.core.hooks.RunSelectionRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestSelectionMotion requests that the element's parent deselect this
|
||||||
|
// element and select the one to the left or right of it, depending on the
|
||||||
|
// direction. If the requests was granted, it returns true. If it was denied, it
|
||||||
|
// returns false.
|
||||||
|
func (control CoreControl) RequestSelectionMotion (
|
||||||
|
direction tomo.SelectionDirection,
|
||||||
|
) (
|
||||||
|
granted bool,
|
||||||
|
) {
|
||||||
|
return control.core.hooks.RunSelectionMotionRequest(direction)
|
||||||
|
}
|
||||||
|
|
||||||
// HasImage returns true if the core has an allocated image buffer, and false if
|
// HasImage returns true if the core has an allocated image buffer, and false if
|
||||||
// it doesn't.
|
// it doesn't.
|
||||||
func (control CoreControl) HasImage () (has bool) {
|
func (control CoreControl) HasImage () (has bool) {
|
||||||
|
Reference in New Issue
Block a user