Make per cell bias calculation overridable more easily

This commit is contained in:
Kovid Goyal 2022-04-08 14:52:53 +05:30
parent dd331ca12e
commit ab8a4c6b9f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 3 deletions

View File

@ -80,7 +80,7 @@ def set_layout_options(opts: Options) -> None:
def calculate_cells_map(bias: Optional[Sequence[float]], number_of_windows: int, number_of_cells: int) -> List[int]: def calculate_cells_map(bias: Optional[Sequence[float]], number_of_windows: int, number_of_cells: int) -> List[int]:
cells_per_window = number_of_cells // number_of_windows cells_per_window = number_of_cells // number_of_windows
if bias is not None and 1 < number_of_windows == len(bias) and cells_per_window > 5: if bias is not None and number_of_windows > 1 and number_of_windows == len(bias) and cells_per_window > 5:
cells_map = [int(b * number_of_cells) for b in bias] cells_map = [int(b * number_of_cells) for b in bias]
while min(cells_map) < 5: while min(cells_map) < 5:
maxi, mini = map(cells_map.index, (max(cells_map), min(cells_map))) maxi, mini = map(cells_map.index, (max(cells_map), min(cells_map)))
@ -221,8 +221,11 @@ class Layout:
self.full_name = f'{self.name}:{layout_opts}' if layout_opts else self.name self.full_name = f'{self.name}:{layout_opts}' if layout_opts else self.name
self.remove_all_biases() self.remove_all_biases()
def bias_increment_for_cell(self, is_horizontal: bool) -> float: def bias_increment_for_cell(self, all_windows: WindowList, window_id: int, is_horizontal: bool) -> float:
self._set_dimensions() self._set_dimensions()
return self.calculate_bias_increment_for_a_single_cell(all_windows, window_id, is_horizontal)
def calculate_bias_increment_for_a_single_cell(self, all_windows: WindowList, window_id: int, is_horizontal: bool) -> float:
if is_horizontal: if is_horizontal:
return (lgd.cell_width + 1) / lgd.central.width return (lgd.cell_width + 1) / lgd.central.width
return (lgd.cell_height + 1) / lgd.central.height return (lgd.cell_height + 1) / lgd.central.height

View File

@ -306,7 +306,7 @@ class Tab: # {{{
self.goto_layout(layout_name) self.goto_layout(layout_name)
def resize_window_by(self, window_id: int, increment: float, is_horizontal: bool) -> Optional[str]: def resize_window_by(self, window_id: int, increment: float, is_horizontal: bool) -> Optional[str]:
increment_as_percent = self.current_layout.bias_increment_for_cell(is_horizontal) * increment increment_as_percent = self.current_layout.bias_increment_for_cell(self.windows, window_id, is_horizontal) * increment
if self.current_layout.modify_size_of_window(self.windows, window_id, increment_as_percent, is_horizontal): if self.current_layout.modify_size_of_window(self.windows, window_id, increment_as_percent, is_horizontal):
self.relayout() self.relayout()
return None return None