Redid the entity system a bit to make it more reliable

Now it supports things like parenting elements before they are
added to a window and elements no longer have to constantly check
for a nil entity
This commit is contained in:
2023-04-15 01:14:36 -04:00
parent 5cf0b162c0
commit 437aef0c27
12 changed files with 129 additions and 96 deletions

View File

@@ -16,15 +16,15 @@ type Image struct {
// NewImage creates a new image element.
func NewImage (image image.Image) (element *Image) {
element = &Image { buffer: canvas.FromImage(image) }
element.entity = tomo.NewEntity(element)
bounds := element.buffer.Bounds()
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
return
}
// Bind binds this element to an entity.
func (element *Image) Bind (entity tomo.Entity) {
if entity == nil { element.entity = nil; return }
element.entity = entity
bounds := element.buffer.Bounds()
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
// Entity returns this element's entity.
func (element *Image) Entity () tomo.Entity {
return element.entity
}
// Draw causes the element to draw to the specified destination canvas.