Fixed inconsistent indentation on treeview
This commit is contained in:
parent
b65474ed2a
commit
7af12f7035
@ -23,7 +23,11 @@ class TreeNode(ABC):
|
|||||||
def add_child(self, child: 'TreeNode') -> None:
|
def add_child(self, child: 'TreeNode') -> None:
|
||||||
"""Add a child node to this node."""
|
"""Add a child node to this node."""
|
||||||
child.parent = self
|
child.parent = self
|
||||||
|
old_depth = child.depth
|
||||||
child.depth = self.depth + 1
|
child.depth = self.depth + 1
|
||||||
|
# Debug: check if depth changed incorrectly
|
||||||
|
if hasattr(child, 'entity') and isinstance(child, EntityNode) and old_depth != child.depth:
|
||||||
|
print(f"EntityNode depth changed from {old_depth} to {child.depth} when added to {self.label}")
|
||||||
self.children.append(child)
|
self.children.append(child)
|
||||||
|
|
||||||
def remove_child(self, child: 'TreeNode') -> None:
|
def remove_child(self, child: 'TreeNode') -> None:
|
||||||
@ -77,7 +81,12 @@ class TreeNode(ABC):
|
|||||||
|
|
||||||
def get_indent(self) -> int:
|
def get_indent(self) -> int:
|
||||||
"""Get the indentation width for this node."""
|
"""Get the indentation width for this node."""
|
||||||
return self.depth * 20
|
indent = self.depth * 20
|
||||||
|
# Debug: print inconsistent depths (only for EntityNodes)
|
||||||
|
if hasattr(self, 'entity') and isinstance(self, EntityNode):
|
||||||
|
if self.depth != 2: # EntityNodes should always be depth 2 (Simulation -> EntityType -> Entity)
|
||||||
|
print(f"Entity {self.entity_id} has inconsistent depth: {self.depth}, indent: {indent}")
|
||||||
|
return indent
|
||||||
|
|
||||||
|
|
||||||
class SimulationNode(TreeNode):
|
class SimulationNode(TreeNode):
|
||||||
@ -122,7 +131,9 @@ class SimulationNode(TreeNode):
|
|||||||
else:
|
else:
|
||||||
# Create new type node
|
# Create new type node
|
||||||
type_node = EntityTypeNode(type_name, entities)
|
type_node = EntityTypeNode(type_name, entities)
|
||||||
|
print(f"SimulationNode: adding {type_name} with current depth {type_node.depth}, my depth is {self.depth}")
|
||||||
self.add_child(type_node)
|
self.add_child(type_node)
|
||||||
|
print(f"SimulationNode: after adding, {type_name} has depth {type_node.depth}")
|
||||||
|
|
||||||
|
|
||||||
class EntityTypeNode(TreeNode):
|
class EntityTypeNode(TreeNode):
|
||||||
@ -131,7 +142,9 @@ class EntityTypeNode(TreeNode):
|
|||||||
def __init__(self, entity_type: str, entities: List[Any]):
|
def __init__(self, entity_type: str, entities: List[Any]):
|
||||||
super().__init__(entity_type)
|
super().__init__(entity_type)
|
||||||
self.entities = entities
|
self.entities = entities
|
||||||
self._update_children()
|
# Debug: check depth
|
||||||
|
print(f"EntityTypeNode {entity_type} created with depth {self.depth}")
|
||||||
|
# Don't call _update_children() here - parent will call after adding this node
|
||||||
|
|
||||||
def _update_children(self) -> None:
|
def _update_children(self) -> None:
|
||||||
"""Update child entity nodes to match current entities."""
|
"""Update child entity nodes to match current entities."""
|
||||||
@ -149,6 +162,9 @@ class EntityTypeNode(TreeNode):
|
|||||||
# Update existing node
|
# Update existing node
|
||||||
entity_node = existing_ids[entity_id]
|
entity_node = existing_ids[entity_id]
|
||||||
entity_node.entity = entity
|
entity_node.entity = entity
|
||||||
|
# Debug: verify depth is correct for updated nodes
|
||||||
|
if entity_node.depth != self.depth + 1:
|
||||||
|
print(f"Updated EntityNode {entity_id} has wrong depth: {entity_node.depth}, should be {self.depth + 1}")
|
||||||
else:
|
else:
|
||||||
# Create new entity node
|
# Create new entity node
|
||||||
entity_node = EntityNode(entity)
|
entity_node = EntityNode(entity)
|
||||||
|
|||||||
@ -133,6 +133,7 @@ class TreeWidget(UIElement):
|
|||||||
elif node == self.hovered_node:
|
elif node == self.hovered_node:
|
||||||
pygame.draw.rect(surface, self.hover_color, node.rect)
|
pygame.draw.rect(surface, self.hover_color, node.rect)
|
||||||
|
|
||||||
|
|
||||||
# Expand/collapse icon
|
# Expand/collapse icon
|
||||||
if node.can_expand():
|
if node.can_expand():
|
||||||
icon_rect = self._get_expand_collapse_rect(node)
|
icon_rect = self._get_expand_collapse_rect(node)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user