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

@@ -67,6 +67,7 @@ func (backend *Backend) newWindow (
window.system.initialize()
window.system.pushFunc = window.pasteAndPush
window.theme.Case = tomo.C("tomo", "window")
window.xWindow, err = xwindow.Generate(backend.connection)
if err != nil { return }
@@ -142,14 +143,18 @@ func (window *window) Window () tomo.Window {
func (window *window) Adopt (child tomo.Element) {
// disown previous child
if window.child != nil {
window.child.unbind()
window.child.unlink()
window.child = nil
}
// adopt new child
if child != nil {
window.child = bind(nil, window, child)
window.resizeChildToFit()
childEntity, ok := child.Entity().(*entity)
if ok && childEntity != nil {
window.child = childEntity
childEntity.setWindow(window)
window.resizeChildToFit()
}
}
}