terminal_menu/utils.py

32 lines
1018 B
Python
Raw Normal View History

2023-05-27 06:40:09 -04:00
def render(pos: int, min: int, max: int, render_distance: int, elements: list):
start = pos - render_distance;
if (start < min):
start = min;
stop = pos + render_distance + 1;
if (stop > max):
stop = max;
i = 0;
y = pos - start;
if (y < min):
y = pos;
if (stop - start != render_distance * 2 + 1):
if (pos - start != render_distance):
stop = stop + render_distance - start - pos
# elif (stop + render_distance > max):
# start = start - (stop + render_distance - max)
y = pos - start;
if (y < min):
y = pos;
2023-05-27 06:40:09 -04:00
return (start, stop, y);
def get_sizes(size1: int, size2: int, total_size: int, aim_ratio: float):
if (size1 + size2 < total_size):
return (size1, size2);
if (size1 > total_size * aim_ratio):
size1 = total_size * aim_ratio;
if (size2 > total_size - size1):
size2 = total_size - size1;
size1 = int(size1);
size2 = int(size2)
return (size1, size2);