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 "image/draw"
 | 
			
		||||
import "image/color"
 | 
			
		||||
// import "git.tebibyte.media/sashakoshka/tomo/iterator"
 | 
			
		||||
 | 
			
		||||
// Image represents a simple image buffer that fulfills the image.Image
 | 
			
		||||
// 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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Canvas is like Image but also requires a SetRGBA method. This interface can
 | 
			
		||||
// be easily satisfied using an image.RGBA struct.
 | 
			
		||||
// Canvas is like Image but also requires Set and SetRGBA methods. This
 | 
			
		||||
// interface can be easily satisfied using an image.RGBA struct.
 | 
			
		||||
type Canvas interface {
 | 
			
		||||
	draw.Image
 | 
			
		||||
	RGBAAt (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.
 | 
			
		||||
type Element interface {
 | 
			
		||||
	// 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.
 | 
			
		||||
	Selectable () (bool)
 | 
			
		||||
 | 
			
		||||
	// SetDrawCallback sets a function to be called when a part of the
 | 
			
		||||
	// element's surface is updated. The updated region will be passed to
 | 
			
		||||
	// the callback as a sub-image.
 | 
			
		||||
	SetDrawCallback (draw func (region Image))
 | 
			
		||||
 | 
			
		||||
	// SetMinimumSizeChangeCallback sets a function to be called when the
 | 
			
		||||
	// 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.
 | 
			
		||||
	SetMinimumSizeChangeCallback (notify func (width, height int))
 | 
			
		||||
	// If this element contains other elements, and one is selected, this
 | 
			
		||||
	// method will advance the selection in the specified direction. If no
 | 
			
		||||
	// children are selected, or there are no more children to be selected
 | 
			
		||||
	// in the specified direction, the element will unselect all of its
 | 
			
		||||
	// children and return false. If the selection could be advanced, it
 | 
			
		||||
	// will return true. If the element contains no child elements, it will
 | 
			
		||||
	// always return false.
 | 
			
		||||
	AdvanceSelection (direction int) (ok bool)
 | 
			
		||||
 | 
			
		||||
	// 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
 | 
			
		||||
	// width may be set to. If the element is resized to an amount smaller
 | 
			
		||||
	// 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
 | 
			
		||||
// displays a black (or transprent) background.
 | 
			
		||||
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)
 | 
			
		||||
 | 
			
		||||
	// Child returns the root element of the window.
 | 
			
		||||
	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)
 | 
			
		||||
	SetIcon  (sizes []image.Image)
 | 
			
		||||
	Show     ()
 | 
			
		||||
	Hide     ()
 | 
			
		||||
	Close    ()
 | 
			
		||||
	OnClose  (func ())
 | 
			
		||||
 | 
			
		||||
	// SetIcon taks in a list different sizes of the same icon and selects
 | 
			
		||||
	// the best one to display on the window title bar, dock, or whatever is
 | 
			
		||||
	// applicable for the given backend. This method might have no effect
 | 
			
		||||
	// 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
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user