mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Implement resizing for vertical and horizontal layouts
This commit is contained in:
@@ -97,10 +97,7 @@ class Layout:
|
|||||||
self.blank_rects = ()
|
self.blank_rects = ()
|
||||||
self.layout_opts = self.parse_layout_opts(layout_opts)
|
self.layout_opts = self.parse_layout_opts(layout_opts)
|
||||||
self.full_name = self.name + ((':' + layout_opts) if layout_opts else '')
|
self.full_name = self.name + ((':' + layout_opts) if layout_opts else '')
|
||||||
self.initialize_sub_class()
|
self.remove_all_biases()
|
||||||
|
|
||||||
def initialize_sub_class(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def bias_increment_for_cell(self, is_horizontal):
|
def bias_increment_for_cell(self, is_horizontal):
|
||||||
self._set_dimensions()
|
self._set_dimensions()
|
||||||
@@ -378,9 +375,6 @@ class Tall(Layout):
|
|||||||
vlayout = Layout.ylayout
|
vlayout = Layout.ylayout
|
||||||
main_is_horizontal = True
|
main_is_horizontal = True
|
||||||
|
|
||||||
def initialize_sub_class(self):
|
|
||||||
self.remove_all_biases()
|
|
||||||
|
|
||||||
def remove_all_biases(self):
|
def remove_all_biases(self):
|
||||||
self.main_bias = list(self.layout_opts['bias'])
|
self.main_bias = list(self.layout_opts['bias'])
|
||||||
self.biased_map = {}
|
self.biased_map = {}
|
||||||
@@ -533,6 +527,29 @@ class Grid(Tall):
|
|||||||
class Vertical(Layout):
|
class Vertical(Layout):
|
||||||
|
|
||||||
name = 'vertical'
|
name = 'vertical'
|
||||||
|
main_is_horizontal = False
|
||||||
|
vlayout = Layout.ylayout
|
||||||
|
|
||||||
|
def variable_layout(self, num_windows, biased_map):
|
||||||
|
return self.vlayout(num_windows, bias=variable_bias(num_windows, biased_map) if num_windows else None)
|
||||||
|
|
||||||
|
def remove_all_biases(self):
|
||||||
|
self.biased_map = {}
|
||||||
|
return True
|
||||||
|
|
||||||
|
def apply_bias(self, idx, increment, num_windows, is_horizontal):
|
||||||
|
if self.main_is_horizontal != is_horizontal:
|
||||||
|
return False
|
||||||
|
if num_windows < 2:
|
||||||
|
return False
|
||||||
|
before_layout = list(self.variable_layout(num_windows, self.biased_map))
|
||||||
|
candidate = self.biased_map.copy()
|
||||||
|
before = candidate.get(idx, 0)
|
||||||
|
candidate[idx] = before + increment
|
||||||
|
if before_layout == list(self.variable_layout(num_windows, candidate)):
|
||||||
|
return False
|
||||||
|
self.biased_map = candidate
|
||||||
|
return True
|
||||||
|
|
||||||
def do_layout(self, windows, active_window_idx):
|
def do_layout(self, windows, active_window_idx):
|
||||||
self.blank_rects = []
|
self.blank_rects = []
|
||||||
@@ -545,11 +562,9 @@ class Vertical(Layout):
|
|||||||
|
|
||||||
xlayout = self.xlayout(1)
|
xlayout = self.xlayout(1)
|
||||||
xstart, xnum = next(xlayout)
|
xstart, xnum = next(xlayout)
|
||||||
ylayout = self.ylayout(window_count)
|
ylayout = self.variable_layout(window_count, self.biased_map)
|
||||||
|
for i, (w, (ystart, ynum)) in enumerate(zip(windows, ylayout)):
|
||||||
for i in range(window_count):
|
w.set_geometry(i, window_geometry(xstart, xnum, ystart, ynum))
|
||||||
ystart, ynum = next(ylayout)
|
|
||||||
windows[i].set_geometry(i, window_geometry(xstart, xnum, ystart, ynum))
|
|
||||||
# bottom blank rect
|
# bottom blank rect
|
||||||
self.bottom_blank_rect(windows[i])
|
self.bottom_blank_rect(windows[i])
|
||||||
|
|
||||||
@@ -557,9 +572,11 @@ class Vertical(Layout):
|
|||||||
self.simple_blank_rects(windows[0], windows[-1])
|
self.simple_blank_rects(windows[0], windows[-1])
|
||||||
|
|
||||||
|
|
||||||
class Horizontal(Layout):
|
class Horizontal(Vertical):
|
||||||
|
|
||||||
name = 'horizontal'
|
name = 'horizontal'
|
||||||
|
main_is_horizontal = True
|
||||||
|
vlayout = Layout.xlayout
|
||||||
|
|
||||||
def do_layout(self, windows, active_window_idx):
|
def do_layout(self, windows, active_window_idx):
|
||||||
self.blank_rects = []
|
self.blank_rects = []
|
||||||
@@ -570,13 +587,11 @@ class Horizontal(Layout):
|
|||||||
self.blank_rects = blank_rects_for_window(windows[0])
|
self.blank_rects = blank_rects_for_window(windows[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
xlayout = self.xlayout(window_count)
|
xlayout = self.variable_layout(window_count, self.biased_map)
|
||||||
ylayout = self.ylayout(1)
|
ylayout = self.ylayout(1)
|
||||||
ystart, ynum = next(ylayout)
|
ystart, ynum = next(ylayout)
|
||||||
|
for i, (w, (xstart, xnum)) in enumerate(zip(windows, xlayout)):
|
||||||
for i in range(window_count):
|
w.set_geometry(i, window_geometry(xstart, xnum, ystart, ynum))
|
||||||
xstart, xnum = next(xlayout)
|
|
||||||
windows[i].set_geometry(i, window_geometry(xstart, xnum, ystart, ynum))
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
# between blank rect
|
# between blank rect
|
||||||
self.between_blank_rect(windows[i - 1], windows[i])
|
self.between_blank_rect(windows[i - 1], windows[i])
|
||||||
|
|||||||
Reference in New Issue
Block a user