flexible-elements-were-a-mistake #11

Merged
sashakoshka merged 17 commits from flexible-elements-were-a-mistake into main 2023-03-13 21:37:58 -06:00
2 changed files with 10 additions and 7 deletions
Showing only changes of commit 3d28ebe4cf - Show all commits

View File

@ -8,6 +8,7 @@ import "git.tebibyte.media/sashakoshka/tomo/canvas"
// widgets. It is meant to be embedded directly into a struct.
type Core struct {
canvas canvas.Canvas
bounds image.Rectangle
metrics struct {
minimumWidth int
@ -37,7 +38,7 @@ func NewCore (
// overridden.
func (core *Core) Bounds () (bounds image.Rectangle) {
if core.canvas == nil { return }
return core.canvas.Bounds()
return core.bounds
}
// MinimumSize fulfils the tomo.Element interface. This should not need to be
@ -48,8 +49,9 @@ func (core *Core) MinimumSize () (width, height int) {
// DrawTo fulfills the tomo.Element interface. This should not need to be
// overridden.
func (core *Core) DrawTo (canvas canvas.Canvas) {
func (core *Core) DrawTo (canvas canvas.Canvas, bounds image.Rectangle) {
core.canvas = canvas
core.bounds = bounds
if core.drawSizeChange != nil && core.canvas != nil {
core.drawSizeChange()
}

View File

@ -9,13 +9,14 @@ import "git.tebibyte.media/sashakoshka/tomo/config"
// Element represents a basic on-screen object.
type Element interface {
// Bounds reports the element's bounding box. This must reflect the
// bounding box of the last canvas given to the element by DrawTo.
// bounding last given to the element by DrawTo.
Bounds () (bounds image.Rectangle)
// DrawTo sets this element's canvas. This should only be called by the
// parent element. This is typically a region of the parent element's
// canvas.
DrawTo (canvas canvas.Canvas)
// DrawTo gives the element a canvas to draw on, along with a bounding
// box to be used for laying out the element. This should only be called
// by the parent element. This is typically a region of the parent
// element's canvas.
DrawTo (canvas canvas.Canvas, bounds image.Rectangle)
// OnDamage sets a function to be called when an area of the element is
// drawn on and should be pushed to the screen.