backend/internal/system/internal-iface.go

110 lines
3.9 KiB
Go

package system
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/canvas"
// eventCategory lists kinds of Tomo events.
type eventCategory int; const (
eventCategoryDND eventCategory = iota
eventCategoryMouse
eventCategoryScroll
eventCategoryKeyboard
)
// parent is any hierarchical type which contains other boxes. This can be a
// Hierarchy, containerBox, etc.
type parent interface {
// hierarchy returns the hierarchy the parent is apart of.
getHierarchy () *Hierarchy
// canvas returns the canvas held by the parent.
getCanvas () canvas.Canvas
// notifyMinimumSizeChange informs the parent that the minimum size of
// one of its children has changed.
notifyMinimumSizeChange (anyBox)
// drawBackgroundPart draws a part of the parent's background to the
// given Canvas, filling the Canvas's entire bounds. The origin (0, 0)
// of the given Canvas is assumed to be the same as the parent's canvas.
drawBackgroundPart (canvas.Canvas)
// captures returns whether or not this parent captures the given event
// category.
captures (eventCategory) bool
}
// anyBox is any tomo.Box type that is implemented by this package.
type anyBox interface {
tomo.Box
canvas.Drawer
// setParent sets this anyBox's parent.
// getParent returns this anyBox's parent as set by setParent.
setParent (parent)
getParent () parent
// doDraw re-paints the anyBox onto its currently held Canvas non-recursively
// doLayout re-calculates the layout of the anyBox non-recursively
// doMinimumSize re-calculates the minimum size of the anyBox non-recursively
doDraw ()
doLayout ()
doMinimumSize ()
// flushActionQueue performs any queued actions, like invalidating the
// minimum size or grabbing input focus.
flushActionQueue ()
// recursiveRedo recursively recalculates the minimum size, layout, and
// re-paints this anyBox and all of its children.
recursiveRedo ()
// loseCanvas causes this anyBox and its children (if applicable) to
// lose their canvases and re-cut them as needed.
recursiveLoseCanvas ()
// recursiveReAppply causes this anyBox and its children (if applicable)
// to check whether they have an outdated style or icon set, and if so,
// update it and trigger the appropriate event broadcasters.
recursiveReApply ()
// contentMinimum returns the minimum dimensions of this box's content
contentMinimum () image.Point
// canBeFocused returns whether or not this anyBox is capable of holding
// input focus.
canBeFocused () bool
// boxUnder returns the anyBox under the mouse pointer. It can be this
// anyBox, one of its children (if applicable). It must return nil if
// the mouse pointer is outside of this anyBox's bounds.
boxUnder (image.Point, eventCategory) anyBox
// transparent returns whether or not this anyBox contains transparent
// pixels or not, and thus needs its parent's backround to be painted
// underneath it.
transparent () bool
// propagate recursively calls a function on this anyBox, and all of its
// children (if applicable) The normal propagate behavior calls the
// callback on all children before calling it on this anyBox, and
// propagateAlt calls the callback on this anyBox before calling it on
// its children.
propagate (func (anyBox) bool) bool
propagateAlt (func (anyBox) bool) bool
handleFocusEnter ()
handleFocusLeave ()
// handleDndEnter ()
// handleDndLeave ()
// handleDndDrop (data.Data)
handleMouseEnter ()
handleMouseLeave ()
handleMouseMove ()
handleMouseDown (input.Button)
handleMouseUp (input.Button)
handleScroll (float64, float64)
handleKeyDown (input.Key, bool)
handleKeyUp (input.Key, bool)
}
func assertAnyBox (unknown tomo.Box) anyBox {
if box, ok := unknown.(anyBox); ok {
return box
} else {
panic("system: foregin box implementation, i did not make this!")
}
}