Skip to content

Commit bddcdbf

Browse files
committed
popup: core: Use linear scaling for small terminal sizes.
This commit is a step towards solving #1005 especially the first 2 points. This changes the fixed scaling factor of 3/4 to one that is linear in the range 80 - 100 column width: * The scaling fraction increases from 3/4 to 1 (full-width) as the available size increases from 80 to 100. This increases the range of sizes for which the popup is rendered properly. * For width's smaller than 80 it defaults to full width. * For width's greater than 100 it defaults to 3/4. The values 80 and 100 are given by: * MIN_SUPPORTED_POPUP_WIDTH = 80 * MAX_LINEAR_SCALING_WIDTH = 100 The popup height has a fixed scaling factor of 3/4. Tests added
1 parent 306f237 commit bddcdbf

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

tests/core/test_core.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,19 @@ def set_msg_ids(*args, **kwargs):
343343
num_after=0, num_before=30, anchor=10000000000)
344344
create_msg.assert_called_once_with(controller.model, msg_ids)
345345
assert controller.model.index == {'search': msg_ids}
346+
347+
@pytest.mark.parametrize('screen_size, expected_popup_size', [
348+
((150, 90), (3 * 150 // 4, 3 * 90 // 4)),
349+
((90, 75), (7 * 90 // 8, 3 * 75 // 4)),
350+
((70, 60), (70, 3 * 60 // 4)),
351+
], ids=[
352+
'above_linear_range', 'in_linear_range', 'below_linear_range',
353+
])
354+
def test_maximum_popup_dimensions(self, mocker, controller,
355+
screen_size, expected_popup_size):
356+
controller.loop.screen.get_cols_rows = mocker.Mock(
357+
return_value=screen_size)
358+
359+
popup_size = controller.maximum_popup_dimensions()
360+
361+
assert popup_size == expected_popup_size

zulipterminal/core.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,31 @@ def _draw_screen(self, *args: Any, **kwargs: Any) -> Literal[True]:
163163

164164
def maximum_popup_dimensions(self) -> Tuple[int, int]:
165165
"""
166-
Returns 3/4th of the screen estate's columns and rows.
166+
Returns 3/4th of the screen estate's columns if
167+
columns are greater than 100 (MAX_LINEAR_SCALING_WIDTH) else
168+
scales accordingly untill popup width becomes full width at
169+
80 (MIN_SUPPORTED_POPUP_WIDTH) below which popup width remains
170+
full width.
171+
The screen estate's rows are always scaled by 3/4th to get the
172+
popup rows.
167173
"""
168-
max_cols, max_rows = map(lambda num: 3 * num // 4,
169-
self.loop.screen.get_cols_rows())
170-
return max_cols, max_rows
174+
MIN_SUPPORTED_POPUP_WIDTH = 80
175+
MAX_LINEAR_SCALING_WIDTH = 100
176+
177+
def clamp(n: int, minn: int, maxn: int) -> int:
178+
return max(min(maxn, n), minn)
179+
180+
max_cols, max_rows = self.loop.screen.get_cols_rows()
181+
min_width = MIN_SUPPORTED_POPUP_WIDTH
182+
max_width = MAX_LINEAR_SCALING_WIDTH
183+
# Scale Width
184+
width = clamp(max_cols, min_width, max_width)
185+
scaling_factor = 1 - (width - min_width) / (max_width - min_width) / 4
186+
max_popup_cols = int(scaling_factor * max_cols)
187+
# Scale Height
188+
max_popup_rows = 3 * max_rows // 4
189+
190+
return max_popup_cols, max_popup_rows
171191

172192
def show_pop_up(self, to_show: Any, style: str) -> None:
173193
border_lines = dict(tlcorner='▛', tline='▀', trcorner='▜',

0 commit comments

Comments
 (0)