feat: dynamic mode
This commit is contained in:
@@ -6,6 +6,8 @@ from uframe.ir import (
|
||||
IRNode, Page, Box, Row, Col, Spacer, Pad,
|
||||
Heading, Text, Label, Divider, Link, ListNode, ListItem,
|
||||
Gauge, Sparkline, Status, Table,
|
||||
Form, Field, Password, Radio, Checkbox, FormButton,
|
||||
Let, Source, IfBlock, ForLoop, CacheControl, OnSubmit, StateDecl,
|
||||
)
|
||||
|
||||
|
||||
@@ -195,13 +197,70 @@ def measure(node: IRNode, available_width: int) -> None:
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, Table):
|
||||
# Height = header border + header row + separator + data rows + bottom border
|
||||
num_rows = len(node.rows)
|
||||
node.pref_width = available_width
|
||||
node.min_width = len(node.columns) * 3 + 1 # minimum 3 chars per col + borders
|
||||
node.pref_height = num_rows + 4 # top border + header + separator + rows + bottom border
|
||||
node.min_width = len(node.columns) * 3 + 1
|
||||
node.pref_height = num_rows + 4
|
||||
node.min_height = 4
|
||||
|
||||
elif isinstance(node, Form):
|
||||
total_h = 0
|
||||
for child in node.children:
|
||||
measure(child, available_width)
|
||||
total_h += child.pref_height
|
||||
node.pref_width = available_width
|
||||
node.min_width = 10
|
||||
node.pref_height = total_h
|
||||
node.min_height = total_h
|
||||
|
||||
elif isinstance(node, Field):
|
||||
node.pref_width = available_width
|
||||
node.min_width = len(node.field_name) + node.field_width + 6
|
||||
node.pref_height = 1
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, Password):
|
||||
node.pref_width = available_width
|
||||
node.min_width = len(node.field_name) + node.field_width + 6
|
||||
node.pref_height = 1
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, Radio):
|
||||
node.pref_width = available_width
|
||||
node.min_width = len(node.group) + sum(len(o) + 6 for o in node.options)
|
||||
node.pref_height = 1
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, Checkbox):
|
||||
node.pref_width = available_width
|
||||
node.min_width = len(node.checkbox_label) + 6
|
||||
node.pref_height = 1
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, FormButton):
|
||||
node.pref_width = available_width
|
||||
node.min_width = len(node.button_label) + 6
|
||||
node.pref_height = 1
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, (Let, Source, CacheControl, StateDecl)):
|
||||
# Zero-height metadata nodes — no visual output
|
||||
node.pref_width = 0
|
||||
node.min_width = 0
|
||||
node.pref_height = 0
|
||||
node.min_height = 0
|
||||
|
||||
elif isinstance(node, (IfBlock, ForLoop, OnSubmit)):
|
||||
# Container nodes — height = sum of children
|
||||
total_h = 0
|
||||
for child in node.children:
|
||||
measure(child, available_width)
|
||||
total_h += child.pref_height
|
||||
node.pref_width = available_width
|
||||
node.min_width = 1
|
||||
node.pref_height = total_h
|
||||
node.min_height = 0
|
||||
|
||||
else:
|
||||
# Generic: just measure children
|
||||
total_h = 0
|
||||
|
||||
Reference in New Issue
Block a user