Support drawing individual border widths
This commit is contained in:
parent
472a3bc69f
commit
5af6d88ffb
@ -9,6 +9,8 @@ from .fast_data_types import (
|
||||
BORDERS_PROGRAM, add_borders_rect, compile_program, init_borders_program
|
||||
)
|
||||
from .utils import load_shaders
|
||||
from .window import Widths
|
||||
|
||||
try:
|
||||
from enum import IntFlag
|
||||
except Exception:
|
||||
@ -32,11 +34,19 @@ def edge(func, os_window_id, tab_id, color, sz, a, b):
|
||||
return partial(func, os_window_id, tab_id, color, sz, a, b)
|
||||
|
||||
|
||||
def border(os_window_id, tab_id, color, sz, left, top, right, bottom):
|
||||
horz = edge(horizontal_edge, os_window_id, tab_id, color, sz, left, right)
|
||||
horz(top), horz(bottom - sz) # top, bottom edges
|
||||
vert = edge(vertical_edge, os_window_id, tab_id, color, sz, top, bottom)
|
||||
vert(left), vert(right - sz) # left, right edges
|
||||
def border(os_window_id, tab_id, color, widths, geometry, base_width=0):
|
||||
left = geometry.left - (widths.left + base_width)
|
||||
top = geometry.top - (widths.top + base_width)
|
||||
right = geometry.right + (widths.right + base_width)
|
||||
bottom = geometry.bottom + (widths.bottom + base_width)
|
||||
if widths.top > 0:
|
||||
edge(horizontal_edge, os_window_id, tab_id, color, widths.top, left, right)(top)
|
||||
if widths.bottom > 0:
|
||||
edge(horizontal_edge, os_window_id, tab_id, color, widths.bottom, left, right)(geometry.bottom + base_width)
|
||||
if widths.left > 0:
|
||||
edge(vertical_edge, os_window_id, tab_id, color, widths.left, top, bottom)(left)
|
||||
if widths.right > 0:
|
||||
edge(vertical_edge, os_window_id, tab_id, color, widths.right, top, bottom)(geometry.right + base_width)
|
||||
|
||||
|
||||
def load_borders_program():
|
||||
@ -65,24 +75,18 @@ class Borders:
|
||||
for br in chain(current_layout.blank_rects, extra_blank_rects):
|
||||
add_borders_rect(self.os_window_id, self.tab_id, *br, BorderColor.default_bg)
|
||||
bw, pw = self.border_width, self.padding_width
|
||||
fw = bw + pw
|
||||
|
||||
if fw > 0:
|
||||
if bw + pw <= 0:
|
||||
return
|
||||
for w in windows:
|
||||
g = w.geometry
|
||||
if bw > 0 and draw_window_borders:
|
||||
# Draw the border rectangles
|
||||
color = BorderColor.active if w is active_window else (BorderColor.bell if w.needs_attention else BorderColor.inactive)
|
||||
border(
|
||||
self.os_window_id, self.tab_id,
|
||||
color, bw, g.left - fw, g.top - fw, g.right + fw,
|
||||
g.bottom + fw
|
||||
)
|
||||
border(self.os_window_id, self.tab_id, color, w.border_widths, g, base_width=pw)
|
||||
if pw > 0:
|
||||
widths = Widths(pw)
|
||||
# Draw the background rectangles over the padding region
|
||||
color = w.screen.color_profile.default_bg
|
||||
border(
|
||||
self.os_window_id, self.tab_id,
|
||||
(color << 8) | BorderColor.window_bg, pw, g.left - pw, g.top - pw, g.right + pw,
|
||||
g.bottom + pw
|
||||
)
|
||||
self.os_window_id, self.tab_id, (color << 8) | BorderColor.window_bg, widths, g)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user