2024-06-02 11:23:03 -06:00
|
|
|
package system
|
|
|
|
|
|
|
|
import "image"
|
|
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
|
|
import "git.tebibyte.media/tomo/tomo/input"
|
|
|
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
|
|
|
|
|
|
|
// 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
|
2024-08-23 13:57:30 -06:00
|
|
|
// getInnerClippingBounds returns the area of the canvas that children
|
|
|
|
// can draw to.
|
|
|
|
getInnerClippingBounds () image.Rectangle
|
2024-06-02 11:23:03 -06:00
|
|
|
// 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)
|
2024-07-25 11:01:15 -06:00
|
|
|
// catches returns whether or not this parent masks events.
|
|
|
|
masks () bool
|
2024-06-02 11:23:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2024-07-25 11:01:15 -06:00
|
|
|
// doStyle re-applies the box's style non-recursively
|
|
|
|
doDraw ()
|
|
|
|
doLayout ()
|
|
|
|
doStyle ()
|
2024-06-02 11:23:03 -06:00
|
|
|
|
|
|
|
// flushActionQueue performs any queued actions, like invalidating the
|
|
|
|
// minimum size or grabbing input focus.
|
2024-06-11 16:12:47 -06:00
|
|
|
flushActionQueue ()
|
2024-06-02 11:23:03 -06:00
|
|
|
// recursiveRedo recursively recalculates the minimum size, layout, and
|
|
|
|
// re-paints this anyBox and all of its children.
|
2024-06-11 16:12:47 -06:00
|
|
|
recursiveRedo ()
|
2024-06-02 11:23:03 -06:00
|
|
|
// loseCanvas causes this anyBox and its children (if applicable) to
|
|
|
|
// lose their canvases and re-cut them as needed.
|
2024-06-11 16:12:47 -06:00
|
|
|
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 ()
|
2024-07-25 11:01:15 -06:00
|
|
|
|
|
|
|
// minimumSize returns the box's minimum size
|
|
|
|
minimumSize () image.Point
|
2024-06-02 11:23:03 -06:00
|
|
|
// 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.
|
2024-07-25 11:01:15 -06:00
|
|
|
boxUnder (image.Point) anyBox
|
2024-06-02 11:23:03 -06:00
|
|
|
// 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
|
|
|
|
|
2024-07-25 11:01:15 -06:00
|
|
|
// setBounds sets the box's bounds.
|
|
|
|
setBounds (image.Rectangle)
|
|
|
|
// setAttr sets an attribute at the user or style level depending
|
|
|
|
// on the value of user.
|
|
|
|
setAttr (attr tomo.Attr, user bool)
|
2024-08-10 18:24:25 -06:00
|
|
|
// unsetAttr unsets an attribute at the user or style level depending
|
|
|
|
// on the value of user.
|
|
|
|
unsetAttr (kind tomo.AttrKind, user bool)
|
2024-07-25 11:01:15 -06:00
|
|
|
|
2024-06-02 11:23:03 -06:00
|
|
|
// 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
|
|
|
|
|
2024-06-11 16:12:47 -06:00
|
|
|
handleFocusEnter ()
|
|
|
|
handleFocusLeave ()
|
|
|
|
// handleDndEnter ()
|
|
|
|
// handleDndLeave ()
|
|
|
|
// handleDndDrop (data.Data)
|
|
|
|
handleMouseEnter ()
|
|
|
|
handleMouseLeave ()
|
2024-07-25 11:01:15 -06:00
|
|
|
handleMouseMove () bool
|
|
|
|
handleMouseDown (input.Button) bool
|
|
|
|
handleMouseUp (input.Button) bool
|
|
|
|
handleScroll (float64, float64) bool
|
|
|
|
handleKeyDown (input.Key, bool) bool
|
|
|
|
handleKeyUp (input.Key, bool) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type anyContentBox interface {
|
|
|
|
anyBox
|
|
|
|
|
|
|
|
// recommendedWidth returns the recommended width for a given height.
|
|
|
|
recommendedWidth (int) int
|
|
|
|
// recommendedHeight returns the recommended height for a given height.
|
|
|
|
recommendedHeight (int) int
|
2024-06-02 11:23:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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!")
|
|
|
|
}
|
|
|
|
}
|