Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a0275f9

Browse files
committedJan 29, 2025·
facet layout
1 parent 3b888f5 commit a0275f9

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed
 

‎asset/layout-gui.avif

10.7 KB
Binary file not shown.

‎asset/layout-tui.avif

11.4 KB
Binary file not shown.

‎docs/Changelog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## 0.7.5
3+
## 0.7.5 (2025-01-29)
44
* UI [configuration](Configuration.md)
5+
* experimental [Facet._layout](Facet.md#layout)
56

67
## 0.7.4 (2025-01-27)
78
* Python 3.13 compatible

‎docs/Facet.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
11
# Facet
2-
::: mininterface.facet.Facet
2+
::: mininterface.facet.Facet
3+
4+
## Layout
5+
6+
!!! Experimental
7+
Share your thoughs about how the layout method should work!
8+
9+
Should you need represent more information, Facet has a hidden method `_layout` that you may call with a list of `LayoutElements`:
10+
11+
* `str`
12+
* `pathlib.Path`
13+
* `facet.Image`
14+
15+
```python
16+
from dataclasses import dataclass
17+
from pathlib import Path
18+
from mininterface import run
19+
from mininterface.facet import Image
20+
21+
@dataclass
22+
class Env:
23+
my_str: str = "Hello"
24+
25+
m = run(Env)
26+
# Image object has currently single 'src' attribute
27+
m.facet._layout(["My text", Image("dog1.jpg"), Path("dog1.jpg")])
28+
m.form()
29+
```
30+
31+
As you see, the program displays "My text", then the image and than the path info.
32+
![Layout GUI](asset/layout-gui.avif)
33+
34+
Even in the TUI, the images are visible. (And mouse-zoomable.)
35+
![Layout TUI](asset/layout-tui.avif)

‎mininterface/facet.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919

2020
@dataclass
2121
class Image:
22-
""" NOTE. Experimental. Undocumented. """
22+
""" NOTE. Experimental. """
23+
2324
src: str | Path
25+
""" Src to the image. """
2426

2527

2628
LayoutElement = TypeVar("LayoutElement", str, Image, Path, "Self")
29+
""" Either a string, Path or facet.Image. """
2730

2831

2932
class BackendAdaptor(ABC):
@@ -102,7 +105,7 @@ def set_title(self, text):
102105
print("Title", text)
103106

104107
def _layout(self, elements: list[LayoutElement]):
105-
""" Experimental. """
108+
""" Experimental. Input is a list of `LayoutElements`."""
106109
# NOTE remove warn when working in textual
107110
warn("Facet layout not implemented for this interface.")
108111

@@ -120,6 +123,7 @@ def callback(tag: Tag):
120123
"My choice": Tag(choices=["one", "two"], on_change=callback)
121124
})
122125
# continue here immediately after clicking on a radio button
126+
```
123127
124128
"""
125129
self.adaptor.post_submit_action = _post_submit

0 commit comments

Comments
 (0)
Please sign in to comment.