flexible-elements-were-a-mistake #11
@ -8,6 +8,7 @@ import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
|||||||
// widgets. It is meant to be embedded directly into a struct.
|
// widgets. It is meant to be embedded directly into a struct.
|
||||||
type Core struct {
|
type Core struct {
|
||||||
canvas canvas.Canvas
|
canvas canvas.Canvas
|
||||||
|
bounds image.Rectangle
|
||||||
|
|
||||||
metrics struct {
|
metrics struct {
|
||||||
minimumWidth int
|
minimumWidth int
|
||||||
@ -37,7 +38,7 @@ func NewCore (
|
|||||||
// overridden.
|
// overridden.
|
||||||
func (core *Core) Bounds () (bounds image.Rectangle) {
|
func (core *Core) Bounds () (bounds image.Rectangle) {
|
||||||
if core.canvas == nil { return }
|
if core.canvas == nil { return }
|
||||||
return core.canvas.Bounds()
|
return core.bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinimumSize fulfils the tomo.Element interface. This should not need to be
|
// 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
|
// DrawTo fulfills the tomo.Element interface. This should not need to be
|
||||||
// overridden.
|
// overridden.
|
||||||
func (core *Core) DrawTo (canvas canvas.Canvas) {
|
func (core *Core) DrawTo (canvas canvas.Canvas, bounds image.Rectangle) {
|
||||||
core.canvas = canvas
|
core.canvas = canvas
|
||||||
|
core.bounds = bounds
|
||||||
if core.drawSizeChange != nil && core.canvas != nil {
|
if core.drawSizeChange != nil && core.canvas != nil {
|
||||||
core.drawSizeChange()
|
core.drawSizeChange()
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,14 @@ import "git.tebibyte.media/sashakoshka/tomo/config"
|
|||||||
// Element represents a basic on-screen object.
|
// Element represents a basic on-screen object.
|
||||||
type Element interface {
|
type Element interface {
|
||||||
// Bounds reports the element's bounding box. This must reflect the
|
// 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)
|
Bounds () (bounds image.Rectangle)
|
||||||
|
|
||||||
// DrawTo sets this element's canvas. This should only be called by the
|
// DrawTo gives the element a canvas to draw on, along with a bounding
|
||||||
// parent element. This is typically a region of the parent element's
|
// box to be used for laying out the element. This should only be called
|
||||||
// canvas.
|
// by the parent element. This is typically a region of the parent
|
||||||
DrawTo (canvas canvas.Canvas)
|
// element's canvas.
|
||||||
|
DrawTo (canvas canvas.Canvas, bounds image.Rectangle)
|
||||||
|
|
||||||
// OnDamage sets a function to be called when an area of the element is
|
// OnDamage sets a function to be called when an area of the element is
|
||||||
// drawn on and should be pushed to the screen.
|
// drawn on and should be pushed to the screen.
|
||||||
|
Reference in New Issue
Block a user