feat: imgage feature
This commit is contained in:
@@ -8,9 +8,10 @@ from uframe.ir import (
|
||||
Gauge, Sparkline, Status, Table,
|
||||
Form, Field, Password, Radio, Checkbox, FormButton,
|
||||
Let, Source, IfBlock, ForLoop, CacheControl, OnSubmit, StateDecl,
|
||||
BigTitle,
|
||||
BigTitle, ImageNode,
|
||||
)
|
||||
from uframe.fonts import FONT_HEIGHTS, get_text_width
|
||||
from uframe.imaging import get_image_height
|
||||
|
||||
|
||||
def _text_height(text: str, width: int) -> int:
|
||||
@@ -245,6 +246,15 @@ def measure(node: IRNode, available_width: int) -> None:
|
||||
node.pref_height = 1
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, ImageNode):
|
||||
h = get_image_height(node.path, node.mode, node.img_width)
|
||||
if node.caption:
|
||||
h += 1 # extra line for caption
|
||||
node.pref_width = available_width
|
||||
node.min_width = node.img_width
|
||||
node.pref_height = h
|
||||
node.min_height = 1
|
||||
|
||||
elif isinstance(node, BigTitle):
|
||||
# Try the requested font, fall back to smaller if too wide
|
||||
tw = get_text_width(node.text, node.font)
|
||||
|
||||
Reference in New Issue
Block a user