gui: factor out background rect calc

avoid some copypasta
This commit is contained in:
Wez Furlong committed 2022-08-23 17:16:04 -07:00
1 parent 9029b3bca6
commit 03246fba23
1 file changed
+25 -71
+25 -71
View File
@@ -1395,11 +1395,9 @@ impl super::TermWindow {
config.text_background_opacity
});
if num_panes > 1 && self.window_background.is_empty() {
// Per-pane, palette-specified background
let cell_width = self.render_metrics.cell_size.width as f32;
let cell_height = self.render_metrics.cell_size.height as f32;
let cell_width = self.render_metrics.cell_size.width as f32;
let cell_height = self.render_metrics.cell_size.height as f32;
let background_rect = {
// We want to fill out to the edges of the splits
let (x, width_delta) = if pos.left == 0 {
(
@@ -1425,26 +1423,31 @@ impl super::TermWindow {
cell_height,
)
};
euclid::rect(
x,
y,
// Go all the way to the right edge if we're right-most
if pos.left + pos.width >= self.terminal_size.cols as usize {
self.dimensions.pixel_width as f32 - x
} else {
(pos.width as f32 * cell_width) + width_delta
},
// Go all the way to the bottom if we're bottom-most
if pos.top + pos.height >= self.terminal_size.rows as usize {
self.dimensions.pixel_height as f32 - y
} else {
(pos.height as f32 * cell_height) + height_delta as f32
},
)
};
if num_panes > 1 && self.window_background.is_empty() {
// Per-pane, palette-specified background
let mut quad = self.filled_rectangle(
layers,
0,
euclid::rect(
x,
y,
// Go all the way to the right edge if we're right-most
if pos.left + pos.width >= self.terminal_size.cols as usize {
self.dimensions.pixel_width as f32 - x
} else {
(pos.width as f32 * cell_width) + width_delta
},
// Go all the way to the bottom if we're bottom-most
if pos.top + pos.height >= self.terminal_size.rows as usize {
self.dimensions.pixel_height as f32 - y
} else {
(pos.height as f32 * cell_height) + height_delta as f32
},
),
background_rect,
palette
.background
.to_linear()
@@ -1494,56 +1497,7 @@ impl super::TermWindow {
};
log::trace!("bell color is {:?}", background);
let cell_width = self.render_metrics.cell_size.width as f32;
let cell_height = self.render_metrics.cell_size.height as f32;
// We want to fill out to the edges of the splits
let (x, width_delta) = if pos.left == 0 {
(
0.,
padding_left + border.left.get() as f32 + (cell_width / 2.0),
)
} else {
(
padding_left + border.left.get() as f32 - (cell_width / 2.0)
+ (pos.left as f32 * cell_width),
cell_width,
)
};
let (y, height_delta) = if pos.top == 0 {
(
(top_pixel_y - padding_top),
padding_top + (cell_height / 2.0),
)
} else {
(
top_pixel_y + (pos.top as f32 * cell_height) - (cell_height / 2.0),
cell_height,
)
};
let mut quad = self.filled_rectangle(
layers,
0,
euclid::rect(
x,
y,
// Go all the way to the right edge if we're right-most
if pos.left + pos.width >= self.terminal_size.cols as usize {
self.dimensions.pixel_width as f32 - x
} else {
(pos.width as f32 * cell_width) + width_delta
},
// Go all the way to the bottom if we're bottom-most
if pos.top + pos.height >= self.terminal_size.rows as usize {
self.dimensions.pixel_height as f32 - y
} else {
(pos.height as f32 * cell_height) + height_delta as f32
},
),
background,
)?;
let mut quad = self.filled_rectangle(layers, 0, background_rect, background)?;
quad.set_hsv(if pos.is_active {
None