Changed the API to make it handle keynav better and be simpler
I have yet to actually update the code to reflect these changes. I will do this shortly.
This commit is contained in:
parent
00d75d4488
commit
192a91757f
82
tomo.go
82
tomo.go
@ -4,7 +4,6 @@ import "image"
|
|||||||
import "errors"
|
import "errors"
|
||||||
import "image/draw"
|
import "image/draw"
|
||||||
import "image/color"
|
import "image/color"
|
||||||
// import "git.tebibyte.media/sashakoshka/tomo/iterator"
|
|
||||||
|
|
||||||
// Image represents a simple image buffer that fulfills the image.Image
|
// Image represents a simple image buffer that fulfills the image.Image
|
||||||
// interface while also having methods that do away with the use of the
|
// interface while also having methods that do away with the use of the
|
||||||
@ -15,14 +14,35 @@ type Image interface {
|
|||||||
RGBAAt (x, y int) (c color.RGBA)
|
RGBAAt (x, y int) (c color.RGBA)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canvas is like Image but also requires a SetRGBA method. This interface can
|
// Canvas is like Image but also requires Set and SetRGBA methods. This
|
||||||
// be easily satisfied using an image.RGBA struct.
|
// interface can be easily satisfied using an image.RGBA struct.
|
||||||
type Canvas interface {
|
type Canvas interface {
|
||||||
draw.Image
|
draw.Image
|
||||||
RGBAAt (x, y int) (c color.RGBA)
|
RGBAAt (x, y int) (c color.RGBA)
|
||||||
SetRGBA (x, y int, c color.RGBA)
|
SetRGBA (x, y int, c color.RGBA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParentHooks is a struct that contains callbacks that let child elements send
|
||||||
|
// information to their parent element without the child element knowing
|
||||||
|
// anything about the parent element or containing any reference to it. When a
|
||||||
|
// parent element adopts a child element, it must set these callbacks.
|
||||||
|
type ParentHooks struct {
|
||||||
|
// 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.
|
||||||
|
Draw func (region Image)
|
||||||
|
|
||||||
|
// MinimumSizeChange is called when the child element's minimum width
|
||||||
|
// and/or height changes. When this function is called, the element will
|
||||||
|
// have already been resized and there is no need to send it a resize
|
||||||
|
// event.
|
||||||
|
MinimumSizeChange func (width, height int)
|
||||||
|
|
||||||
|
// SelectionRequest is called when the child element element wants
|
||||||
|
// itself to be selected. If the parent element chooses to grant the
|
||||||
|
// request, it must send the child element a selection event.
|
||||||
|
SelectionRequest func ()
|
||||||
|
}
|
||||||
|
|
||||||
// Element represents a basic on-screen object.
|
// Element represents a basic on-screen object.
|
||||||
type Element interface {
|
type Element interface {
|
||||||
// Element must implement the Image interface. Elements should start out
|
// Element must implement the Image interface. Elements should start out
|
||||||
@ -37,17 +57,21 @@ type Element interface {
|
|||||||
// element contains other selectable elements, it must return true.
|
// element contains other selectable elements, it must return true.
|
||||||
Selectable () (bool)
|
Selectable () (bool)
|
||||||
|
|
||||||
// SetDrawCallback sets a function to be called when a part of the
|
// If this element contains other elements, and one is selected, this
|
||||||
// element's surface is updated. The updated region will be passed to
|
// method will advance the selection in the specified direction. If no
|
||||||
// the callback as a sub-image.
|
// children are selected, or there are no more children to be selected
|
||||||
SetDrawCallback (draw func (region Image))
|
// in the specified direction, the element will unselect all of its
|
||||||
|
// children and return false. If the selection could be advanced, it
|
||||||
// SetMinimumSizeChangeCallback sets a function to be called when the
|
// will return true. If the element contains no child elements, it will
|
||||||
// element's minimum width and/or height changes. When this function is
|
// always return false.
|
||||||
// called, the element will have already been resized and there is no
|
AdvanceSelection (direction int) (ok bool)
|
||||||
// need to send it a resize event.
|
|
||||||
SetMinimumSizeChangeCallback (notify func (width, height int))
|
|
||||||
|
|
||||||
|
// SetParentHooks gives the element callbacks that let it send
|
||||||
|
// information to its parent element without it knowing anything about
|
||||||
|
// the parent element or containing any reference to it. When a parent
|
||||||
|
// element adopts a child element, it must set these callbacks.
|
||||||
|
SetParentHooks (callbacks ParentHooks)
|
||||||
|
|
||||||
// MinimumWidth specifies the minimum amount of pixels this element's
|
// MinimumWidth specifies the minimum amount of pixels this element's
|
||||||
// width may be set to. If the element is resized to an amount smaller
|
// width may be set to. If the element is resized to an amount smaller
|
||||||
// that MinimumWidth, it will instead set its width to MinimumWidth.
|
// that MinimumWidth, it will instead set its width to MinimumWidth.
|
||||||
@ -64,15 +88,35 @@ type Element interface {
|
|||||||
// be explicitly shown with the Show() method. If it contains no element, it
|
// be explicitly shown with the Show() method. If it contains no element, it
|
||||||
// displays a black (or transprent) background.
|
// displays a black (or transprent) background.
|
||||||
type Window interface {
|
type Window interface {
|
||||||
Element
|
// Adopt sets the root element of the window. There can only be one of
|
||||||
|
// these at one time.
|
||||||
Adopt (child Element)
|
Adopt (child Element)
|
||||||
|
|
||||||
|
// Child returns the root element of the window.
|
||||||
Child () (child Element)
|
Child () (child Element)
|
||||||
|
|
||||||
|
// SetTitle sets the title that appears on the window's title bar. This
|
||||||
|
// method might have no effect with some backends.
|
||||||
SetTitle (title string)
|
SetTitle (title string)
|
||||||
SetIcon (sizes []image.Image)
|
|
||||||
Show ()
|
// SetIcon taks in a list different sizes of the same icon and selects
|
||||||
Hide ()
|
// the best one to display on the window title bar, dock, or whatever is
|
||||||
Close ()
|
// applicable for the given backend. This method might have no effect
|
||||||
OnClose (func ())
|
// with some backends.
|
||||||
|
SetIcon (sizes []image.Image)
|
||||||
|
|
||||||
|
// Show shows the window. The window starts off hidden, so this must be
|
||||||
|
// called after initial setup to make sure it is visible.
|
||||||
|
Show ()
|
||||||
|
|
||||||
|
// Hide hides the window.
|
||||||
|
Hide ()
|
||||||
|
|
||||||
|
// Close closes the window.
|
||||||
|
Close ()
|
||||||
|
|
||||||
|
// OnClose specifies a function to be called when the window is closed.
|
||||||
|
OnClose (func ())
|
||||||
}
|
}
|
||||||
|
|
||||||
var backend Backend
|
var backend Backend
|
||||||
|
Reference in New Issue
Block a user