Skip to content

Commit

Permalink
Tweaks to window node lifecycle management
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhogg committed Feb 12, 2025
1 parent 88bf712 commit e09a3a3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/flitter/render/window/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def update(self, engine, node, references, *, default_size=(512, 512), **k
await result

def similar_to(self, node):
return node.tags == self.tags
return node.tags == self.tags and node.get('id', 1, str) == self.node_id

def create(self, engine, node, resized, **kwargs):
pass
Expand All @@ -138,13 +138,17 @@ async def descend(self, engine, node, references, **kwargs):
for i, scene_node in enumerate(existing):
if type(scene_node) is cls and scene_node.similar_to(child):
scene_node = existing.pop(i)
await scene_node.update(engine, child, references, **kwargs)
break
else:
scene_node = cls(self.glctx)
await scene_node.update(engine, child, references, **kwargs)
await scene_node.update(engine, child, references, **kwargs)
logger.trace("New window node: {}", scene_node.name)
updated.append(scene_node)
while existing:
await existing.pop().destroy()
scene_node = existing.pop()
logger.trace("Destroy window node: {}", scene_node.name)
await scene_node.destroy()
self.children = updated

def render(self, node, references, **kwargs):
Expand All @@ -156,6 +160,9 @@ def parent_finished(self):
def handle_node(self, engine, node, **kwargs):
return False

def __repr__(self):
return f"<{self.name}{' id='+self.node_id if self.node_id else ''}>"


class Reference(WindowNode):
def __init__(self, glctx):
Expand All @@ -174,8 +181,8 @@ def array(self):
return self._reference.array if self._reference is not None else None

async def update(self, engine, node, references, **kwargs):
node_id = node.get('id', 1, str)
self._reference = references.get(node_id) if node_id else None
self.node_id = node.get('id', 1, str)
self._reference = references.get(self.node_id) if self.node_id else None


class ProgramNode(WindowNode):
Expand Down

0 comments on commit e09a3a3

Please sign in to comment.