feat: dynamic mode
This commit is contained in:
@@ -18,6 +18,7 @@ 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,
|
||||
HeadingLevel, DividerStyle, ListStyle, Align, BorderWeight,
|
||||
)
|
||||
|
||||
@@ -213,6 +214,60 @@ def paint(node: IRNode, grid: CharGrid) -> None:
|
||||
elif isinstance(node, Table):
|
||||
_paint_table(node, grid, x, y, w)
|
||||
|
||||
elif isinstance(node, Form):
|
||||
for child in node.children:
|
||||
paint(child, grid)
|
||||
|
||||
elif isinstance(node, Field):
|
||||
label_style = CellStyle(fg="888")
|
||||
field_style = CellStyle(fg="0cf")
|
||||
label_text = f"{node.field_name}: "
|
||||
grid.put_text(x, y, label_text, style=label_style)
|
||||
# Draw [ placeholder_______ ]
|
||||
fx = x + len(label_text)
|
||||
fw = min(node.field_width, w - len(label_text) - 2)
|
||||
grid.put(fx, y, "[", style=field_style)
|
||||
placeholder = node.placeholder or node.field_name
|
||||
inner = f" {placeholder}".ljust(fw - 1)[:fw - 1]
|
||||
grid.put_text(fx + 1, y, inner, style=CellStyle(fg="555"))
|
||||
grid.put(fx + fw, y, "]", style=field_style)
|
||||
|
||||
elif isinstance(node, Password):
|
||||
label_style = CellStyle(fg="888")
|
||||
field_style = CellStyle(fg="0cf")
|
||||
label_text = f"{node.field_name}: "
|
||||
grid.put_text(x, y, label_text, style=label_style)
|
||||
fx = x + len(label_text)
|
||||
fw = min(node.field_width, w - len(label_text) - 2)
|
||||
grid.put(fx, y, "[", style=field_style)
|
||||
inner = " " + "•" * (fw - 2)
|
||||
grid.put_text(fx + 1, y, inner[:fw - 1], style=CellStyle(fg="555"))
|
||||
grid.put(fx + fw, y, "]", style=field_style)
|
||||
|
||||
elif isinstance(node, Radio):
|
||||
label_style = CellStyle(fg="888")
|
||||
label_text = f"{node.group}: "
|
||||
grid.put_text(x, y, label_text, style=label_style)
|
||||
rx = x + len(label_text)
|
||||
for i, opt in enumerate(node.options):
|
||||
dot = "(•)" if i == 0 else "( )"
|
||||
opt_style = CellStyle(fg="0cf" if i == 0 else "888")
|
||||
grid.put_text(rx, y, dot, style=opt_style)
|
||||
rx += 4
|
||||
grid.put_text(rx, y, opt, style=CellStyle())
|
||||
rx += len(opt) + 2
|
||||
|
||||
elif isinstance(node, Checkbox):
|
||||
check_style = CellStyle(fg="0cf")
|
||||
box_char = "[✓]" if node.checked else "[ ]"
|
||||
grid.put_text(x, y, box_char, style=check_style)
|
||||
grid.put_text(x + 4, y, node.checkbox_label)
|
||||
|
||||
elif isinstance(node, FormButton):
|
||||
btn_style = CellStyle(bold=True, fg="0f0")
|
||||
btn_text = f"[ {node.button_label} ]"
|
||||
grid.put_text(x, y, btn_text, style=btn_style, link=node.dest)
|
||||
|
||||
else:
|
||||
# Generic: paint children
|
||||
for child in node.children:
|
||||
|
||||
Reference in New Issue
Block a user