From 92385f6db7c49165b3d0e7c8b16f6264115ceb41 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 20 Jul 2024 12:44:46 +0530 Subject: [PATCH] Make function re-useable and simplify bias docs a bit --- kitty/launch.py | 10 +++++----- kitty/layout/grid.py | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/kitty/launch.py b/kitty/launch.py index ce6097200..2d7c95dee 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -199,11 +199,11 @@ the remainder of the space. * Vertical/horizontal layout: The bias is interpreted as adding/subtracting from the normal size of the window. It should be a number between -90 and 90. This number is -the percentage of cells in the full OS window that should be added to the window size. -So for example, if a window would normally have been 50 cells in the layout inside an -OS Window that is 80 cells high and --bias -10 is used it will become *approximately* -42 cells high. Note that cell counts are approximations, you cannot use this method to -create windows of fixed cell sizes. +the percentage of the OS Window size that should be added to the window size. +So for example, if a window would normally have been size 50 in the layout inside an +OS Window that is size 80 high and --bias -10 is used it will become *approximately* +size 42 high. Note that sizes are approximations, you cannot use this method to +create windows of fixed sizes. * Tall layout: If the window being created is the *first* window in a column, then the bias is interpreted as a percentage, as for the splits layout, splitting the OS diff --git a/kitty/layout/grid.py b/kitty/layout/grid.py index 5d4aa8dbd..4376e90c5 100644 --- a/kitty/layout/grid.py +++ b/kitty/layout/grid.py @@ -58,26 +58,26 @@ class Grid(Layout): def variable_layout(self, layout_func: Callable[..., LayoutDimension], num_windows: int, biased_map: Dict[int, float]) -> LayoutDimension: return layout_func(num_windows, bias=biased_map if num_windows > 1 else None) + def position_for_window_idx(self, idx: int, num_windows: int, ncols:int , nrows: int, special_rows: int, special_col: int) -> Tuple[int, int]: + row_num = col_num = 0 + + def on_col_done(col_windows: List[int]) -> None: + nonlocal col_num, row_num + row_num = 0 + col_num += 1 + + for window_idx, xl, yl in self.layout_windows( + num_windows, nrows, ncols, special_rows, special_col, on_col_done): + if idx == window_idx: + return row_num, col_num + row_num += 1 + return 0, 0 + def apply_bias(self, idx: int, increment: float, all_windows: WindowList, is_horizontal: bool = True) -> bool: num_windows = all_windows.num_groups ncols, nrows, special_rows, special_col = calc_grid_size(num_windows) - def position_for_window_idx(idx: int) -> Tuple[int, int]: - row_num = col_num = 0 - - def on_col_done(col_windows: List[int]) -> None: - nonlocal col_num, row_num - row_num = 0 - col_num += 1 - - for window_idx, xl, yl in self.layout_windows( - num_windows, nrows, ncols, special_rows, special_col, on_col_done): - if idx == window_idx: - return row_num, col_num - row_num += 1 - return 0, 0 - - row_num, col_num = position_for_window_idx(idx) + row_num, col_num = self.position_for_window_idx(idx, num_windows, ncols, nrows, special_rows, special_col) if is_horizontal: b = self.biased_cols