-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace existing layout algorithm with just Flex layout (#22)
- Loading branch information
1 parent
c57d4a8
commit d4f09de
Showing
29 changed files
with
1,577 additions
and
1,177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import shutil | ||
from textwrap import dedent | ||
|
||
from structlog import get_logger | ||
|
||
from reprisal.components import Div, Text | ||
from reprisal.layout import build_layout_tree | ||
from reprisal.paint import debug_paint, paint_layout | ||
from reprisal.styles import Border, BorderKind, Span, Style | ||
from reprisal.styles.styles import Flex | ||
|
||
logger = get_logger() | ||
|
||
w, h = shutil.get_terminal_size() | ||
|
||
|
||
def content(justify_children: str, align_children: str, n: int) -> Text: | ||
return Text( | ||
content=dedent( | ||
f"""\ | ||
n={n} | ||
j={justify_children} | ||
a={align_children} | ||
This is long enough text that it should wrap around, | ||
but not necessarily at the comma. | ||
""" | ||
), | ||
style=Style( | ||
# TODO: width=auto doesn't make sense if weight=None, combine? | ||
display=Flex( | ||
weight=None, | ||
), | ||
span=Span( | ||
width=20, | ||
height="auto", | ||
), | ||
border=Border(kind=BorderKind.Light), | ||
), | ||
) | ||
|
||
|
||
children = [ | ||
Div( | ||
children=[content(justify_children, align_children, n=n) for n in range(3)], | ||
style=Style( | ||
display=Flex( | ||
direction="row", | ||
justify_children=justify_children, # type: ignore[arg-type] | ||
align_children=align_children, # type: ignore[arg-type] | ||
), | ||
border=Border(kind=BorderKind.Heavy), | ||
), | ||
) | ||
for justify_children in [ | ||
"start", | ||
"center", | ||
"end", | ||
"space-between", | ||
"space-around", | ||
"space-evenly", | ||
] | ||
for align_children in [ | ||
"start", | ||
"center", | ||
"end", | ||
"stretch", | ||
] | ||
] | ||
|
||
root = Div( | ||
children=children, | ||
style=Style( | ||
display=Flex(direction="column", align_children="stretch"), | ||
span=Span( | ||
width=w, | ||
height=20 * len(children), | ||
), | ||
), | ||
) | ||
print(f"{len(children)=}") | ||
|
||
t = build_layout_tree(root) | ||
t.compute_layout() | ||
# pprint(t.dict(exclude_defaults=True, include={"dims", "children"})) | ||
p = paint_layout(t) | ||
# pprint(t.dims.dict()) | ||
# for child in t.children: | ||
# pprint(child.dims.dict()) | ||
print(t.dims) | ||
for child in t.children: | ||
print(child.dims) | ||
_, _, margin_rect = t.dims.padding_border_margin_rects() | ||
print(debug_paint(p, margin_rect)) |
Oops, something went wrong.