Gallery covers the pixel image; ^U view never shrinks it for its string
Three gallery cases with a real 30x30 image: the transcript, the picked message (^U image, the Image chip), and the ^U view, on all four sizes. They showed the Cardputer's view shrinking the image to 12x12 to fit the im3: string. The string may now only stop the image from growing; when it would make the image smaller than it is alone, it goes a page down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5dc602e11
commit
c5b2e87ca4
2 files changed
+49
-3
No files matched your search
@@ -175,8 +175,10 @@ class ImageScreen(ScrollScreen):
|
||||
|
||||
The text of the message has no spaces, so it breaks at the width of the image area,
|
||||
into a block of lines that is centred as one. The text never makes the image smaller
|
||||
than its own size. When the frame cannot hold both at that size, the image gets the
|
||||
rows, and the text is under it, a page down, as the URL of a large QR code is.
|
||||
than the size that it has alone on the frame (or its own size, when the frame is
|
||||
larger than that): the text can only stop it from growing. When the frame cannot hold
|
||||
both, the image gets the rows, and the text is under it, a page down, as the URL of a
|
||||
large QR code is. On the 14 rows of the Cardputer, this is the case for most images.
|
||||
"""
|
||||
|
||||
bare = True
|
||||
@@ -205,7 +207,10 @@ class ImageScreen(ScrollScreen):
|
||||
alone = max(1, rows - _MARGIN_ROWS - 2)
|
||||
art_rows = max(1, alone - (1 + len(raw_lines) if raw_lines else 0))
|
||||
size = (picture.width, picture.height)
|
||||
if fit(*size, art_cols, art_rows, grow=True) < size <= fit(*size, art_cols, alone):
|
||||
# The width that the image has without the text, but never more than its own: the
|
||||
# text can stop it from growing, never make it smaller than that.
|
||||
target = fit(*size, art_cols, alone)[0]
|
||||
if fit(*size, art_cols, art_rows, grow=True)[0] < target:
|
||||
art_rows = alone # the text goes a page down
|
||||
cols, _ = fit(picture.width, picture.height, art_cols, art_rows, grow=True)
|
||||
indent = max(0, (width - cols) // 2)
|
||||
|
||||
@@ -804,6 +804,35 @@ def _chat_long_url(cols: int, rows: int) -> Screen:
|
||||
return screen
|
||||
|
||||
|
||||
#: A real MCOimg image: a woodpecker, 30 x 30, in 74 bytes (refer to tests/test_mcoimg.py).
|
||||
_WOODPECKER = (
|
||||
'im3:J!jBVY"9UPkugAX54#9BX:e"FM|cL0G|IS.@$q^=N:4D*B9d1d$450M>W/tOqmq`wqd..bJp|}'
|
||||
"d/4v2vpi5BAZ9wD/B"
|
||||
)
|
||||
|
||||
|
||||
def _chat_image(cols: int, rows: int, *, picked: bool = False) -> Screen:
|
||||
"""A channel message that is a pixel image: its caption, and the image in half blocks.
|
||||
|
||||
The image is 30 pixels wide, so it fits after the indent of the body on each platform
|
||||
(44 cells on the PicoCalc), and it is 15 rows tall. With ``picked``, the image message
|
||||
is selected, so the hint names ``^U image`` and the lane lights ``Image``.
|
||||
"""
|
||||
conv = Conversation(label="Lakeside art", is_channel=True, channel_idx=3)
|
||||
messages = [
|
||||
ChatMessage(text="Alice: drew this on the trail today", is_channel=True),
|
||||
ChatMessage(text=f"Alice: {_WOODPECKER}", is_channel=True),
|
||||
]
|
||||
screen = ChatScreen(conv, messages, send=None, names={}, session=_GallerySession(cols, rows))
|
||||
if picked:
|
||||
screen.handle("up")
|
||||
return screen
|
||||
|
||||
|
||||
def _chat_image_picked(cols: int, rows: int) -> Screen:
|
||||
return _chat_image(cols, rows, picked=True)
|
||||
|
||||
|
||||
class _PickerChat:
|
||||
"""The unread counter that the rows of the picker read live."""
|
||||
|
||||
@@ -1927,6 +1956,15 @@ def _links_qr(cols: int, rows: int) -> Screen:
|
||||
)
|
||||
|
||||
|
||||
def _image_screen(cols: int, rows: int) -> Screen:
|
||||
"""The ^U view of a pixel image: the image on a bare frame, its caption, and its text."""
|
||||
from meshterm.core.mcoimg import recognize
|
||||
from meshterm.ui.pixelart import ImageScreen, decoded
|
||||
from meshterm.ui.widgets import pixel_image_text
|
||||
|
||||
return ImageScreen(decoded(_WOODPECKER), pixel_image_text(recognize(_WOODPECKER)), _WOODPECKER)
|
||||
|
||||
|
||||
def _clock_drift(cols: int, rows: int) -> Screen:
|
||||
"""The Clock drift page in its fullest form: a managed node, nodes out of sync, a name.
|
||||
|
||||
@@ -2000,6 +2038,8 @@ _ENTRIES: list[_Entry] = [
|
||||
_Entry("chat_channel_scoped", _chat_channel_scoped),
|
||||
_Entry("chat_urls", _chat_urls),
|
||||
_Entry("chat_long_url", _chat_long_url),
|
||||
_Entry("chat_image", _chat_image),
|
||||
_Entry("chat_image_picked", _chat_image_picked),
|
||||
_Entry("chat_picker", _chat_picker),
|
||||
_Entry("room", _room),
|
||||
_Entry("room_read_only", _room_read_only),
|
||||
@@ -2054,6 +2094,7 @@ _ENTRIES: list[_Entry] = [
|
||||
_Entry("support_project", _support_project),
|
||||
_Entry("share_qr", _share_qr),
|
||||
_Entry("links_qr", _links_qr),
|
||||
_Entry("image_screen", _image_screen),
|
||||
_Entry("diagnostics", _diagnostics),
|
||||
_Entry("diagnostics-anonymized", _diagnostics_anonymized),
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user