Skip to content

Commit 97a0318

Browse files
committed
Cleanup + small fix in flow logic
1 parent 67ac9f5 commit 97a0318

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

src/omnipy/data/_display/panel/draft/layout.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ def resize_panels_to_fit_frame( # noqa: C901
3434
dim_aware_layout: Layout[DimensionsAwarePanel[AnyFrame]]
3535
prev_layout_dims: DimensionsWithWidthAndHeight | None = None
3636

37-
no_reflow_panel_keys: set[str] = set()
37+
no_resize_panel_keys: set[str] = set()
3838
for key, draft_panel in content.items():
3939
if draft_panel.frame.fixed_width is True or panel_is_dimensions_aware(draft_panel):
40-
no_reflow_panel_keys.add(key)
40+
no_resize_panel_keys.add(key)
4141

42-
prev_no_reflow_panel_keys = no_reflow_panel_keys.copy()
42+
prev_no_reflow_panel_keys = no_resize_panel_keys.copy()
4343

4444
while True:
4545
dim_aware_layout = Layout(**dim_aware_panels)
4646
layout_dims = cls._calc_table_layout_dims(dim_aware_layout)
4747
if layout_dims == prev_layout_dims \
48-
and no_reflow_panel_keys == prev_no_reflow_panel_keys:
48+
and no_resize_panel_keys == prev_no_reflow_panel_keys:
4949
break
5050

5151
prev_layout_dims = layout_dims
52-
prev_no_reflow_panel_keys = no_reflow_panel_keys.copy()
52+
prev_no_reflow_panel_keys = no_resize_panel_keys.copy()
5353

5454
frame_dims = cast(Frame, values['frame']).dims
5555
delta_width = layout_dims.width - frame_dims.width \
@@ -71,8 +71,8 @@ def _priority(
7171
and panel.frame.fixed_height \
7272
else panel.dims.height
7373

74-
return (float('inf') if key in no_reflow_panel_keys else panel_height,
75-
float('inf') if key in no_reflow_panel_keys else
74+
return (float('inf') if key in no_resize_panel_keys else panel_height,
75+
float('inf') if key in no_resize_panel_keys else
7676
(-panel.frame.dims.width if has_width(panel.frame.dims) else -float('inf')),
7777
-cls._panel_dims_if_cropped(panel).width,
7878
-i)
@@ -140,28 +140,29 @@ def _priority(
140140
constraints=draft_panel.constraints,
141141
config=draft_panel.config,
142142
)
143-
new_dim_aware_panel: DimensionsAwarePanel[
143+
resized_panel: DimensionsAwarePanel[
144144
AnyFrame] = new_draft_panel.render_next_stage()
145145

146146
prev_cropped_dims = cls._panel_dims_if_cropped(dim_aware_panels[key])
147-
new_cropped_dims = cls._panel_dims_if_cropped(new_dim_aware_panel)
147+
new_cropped_dims = cls._panel_dims_if_cropped(resized_panel)
148148

149-
if key not in no_reflow_panel_keys:
149+
if key not in no_resize_panel_keys:
150150
prev_frame_dims = dim_aware_panels[key].frame.dims
151-
if new_dim_aware_panel.dims.width == dim_aware_panels[key].dims.width:
152-
if has_width(new_dim_aware_panel.frame.dims) and \
151+
if delta_width and delta_width > 0 \
152+
and resized_panel.dims.width == dim_aware_panels[key].dims.width:
153+
if has_width(resized_panel.frame.dims) and \
153154
has_width(prev_frame_dims) and \
154-
new_dim_aware_panel.frame.dims.width < prev_frame_dims.width:
155-
no_reflow_panel_keys.add(key)
155+
resized_panel.frame.dims.width < prev_frame_dims.width:
156+
no_resize_panel_keys.add(key)
156157
break
157158
else:
158159
if new_cropped_dims.width > prev_cropped_dims.width:
159-
no_reflow_panel_keys.remove(key)
160+
no_resize_panel_keys.remove(key)
160161

161162
if new_cropped_dims == prev_cropped_dims:
162163
continue
163164

164-
dim_aware_panels[key] = new_dim_aware_panel
165+
dim_aware_panels[key] = resized_panel
165166
break
166167

167168
for key, panel in dim_aware_panels.items():

src/omnipy/data/_display/panel/styling/text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from omnipy.data._display.panel.draft.text import ReflowedTextDraftPanel
1414
from omnipy.data._display.panel.helpers import extract_value_if_enum
1515
from omnipy.data._display.panel.styling.base import StylizedMonospacedPanel, StylizedRichTypes
16-
from omnipy.data._display.panel.styling.output import OutputMode, VerticalTextCroppingOutputVariant
16+
from omnipy.data._display.panel.styling.output import OutputMode, TextCroppingOutputVariant
1717
from omnipy.util import _pydantic as pyd
1818

1919

@@ -89,14 +89,14 @@ def _stylized_content_html_impl(self) -> StylizedRichTypes:
8989
@cached_property
9090
@override
9191
def plain(self) -> OutputVariant:
92-
return VerticalTextCroppingOutputVariant(self, OutputMode.PLAIN)
92+
return TextCroppingOutputVariant(self, OutputMode.PLAIN)
9393

9494
@cached_property
9595
@override
9696
def bw_stylized(self) -> OutputVariant:
97-
return VerticalTextCroppingOutputVariant(self, OutputMode.BW_STYLIZED)
97+
return TextCroppingOutputVariant(self, OutputMode.BW_STYLIZED)
9898

9999
@cached_property
100100
@override
101101
def colorized(self) -> OutputVariant:
102-
return VerticalTextCroppingOutputVariant(self, OutputMode.COLORIZED)
102+
return TextCroppingOutputVariant(self, OutputMode.COLORIZED)

tests/data/display/panel/cases/layout_basics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ def case_layout_single_panel_stage_2_fixed_dims(
441441
'╰──────┴───────────╯\n'),
442442
exp_dims_all_stages=Dimensions(width=20, height=4),
443443
),
444-
# First panel is longer width-resizable, since the text in the first
445-
# panel cannot be soft-wrapped more than what has already been done.
444+
# First panel is no longer width-resizable, since the text in the
445+
# first panel cannot be soft-wrapped more than what has already been
446+
# done.
446447
#
447448
# Width-resizable panels:
448449
# - Second

0 commit comments

Comments
 (0)