mirror of
https://github.com/wez/wezterm.git
synced 2024-11-27 02:25:28 +03:00
term: introduce right&bottom padding to ImageCell
This helps us correctly set the size of the image cell for the case where we have a partial cell at the right/bottom edge of an image being mapped across cells. refs: #1270
This commit is contained in:
parent
4c04de551f
commit
294579fd31
@ -30,8 +30,8 @@ pub struct ImageAttachParams {
|
||||
|
||||
/// When rendering in the cell, use this offset from the top left
|
||||
/// of the cell
|
||||
pub display_offset_x: u32,
|
||||
pub display_offset_y: u32,
|
||||
pub padding_left: u16,
|
||||
pub padding_top: u16,
|
||||
|
||||
/// Plane on which to display the image
|
||||
pub z_index: i32,
|
||||
@ -110,6 +110,7 @@ impl TerminalState {
|
||||
|
||||
let mut remain_y = source_height as usize;
|
||||
for y in 0..height_in_cells {
|
||||
let padding_bottom = cell_pixel_height.saturating_sub(remain_y) as u16;
|
||||
let y_delta = (remain_y.min(cell_pixel_height) as f32) / (source_height as f32);
|
||||
remain_y = remain_y.saturating_sub(cell_pixel_height);
|
||||
|
||||
@ -127,8 +128,15 @@ impl TerminalState {
|
||||
);
|
||||
let mut remain_x = source_width as usize;
|
||||
for x in 0..width_in_cells {
|
||||
let padding_right = cell_pixel_width.saturating_sub(remain_x) as u16;
|
||||
let x_delta = (remain_x.min(cell_pixel_width) as f32) / (source_width as f32);
|
||||
log::debug!("x_delta {}, y_delta {}", x_delta, y_delta);
|
||||
log::debug!(
|
||||
"x_delta {}, y_delta {}, padding_right={}, padding_bottom={}",
|
||||
x_delta,
|
||||
y_delta,
|
||||
padding_right,
|
||||
padding_bottom
|
||||
);
|
||||
remain_x = remain_x.saturating_sub(cell_pixel_width);
|
||||
let mut cell = self
|
||||
.screen()
|
||||
@ -140,8 +148,10 @@ impl TerminalState {
|
||||
TextureCoordinate::new(xpos + x_delta, ypos + y_delta),
|
||||
params.data.clone(),
|
||||
params.z_index,
|
||||
params.display_offset_x,
|
||||
params.display_offset_y,
|
||||
params.padding_left,
|
||||
params.padding_top,
|
||||
padding_right,
|
||||
padding_bottom,
|
||||
params.image_id,
|
||||
params.placement_id,
|
||||
));
|
||||
|
@ -146,8 +146,8 @@ impl TerminalState {
|
||||
source_height: height as u32,
|
||||
source_origin_x: 0,
|
||||
source_origin_y: 0,
|
||||
display_offset_x: 0,
|
||||
display_offset_y: 0,
|
||||
padding_left: 0,
|
||||
padding_top: 0,
|
||||
z_index: 0,
|
||||
columns: None,
|
||||
rows: None,
|
||||
|
@ -117,8 +117,8 @@ impl TerminalState {
|
||||
source_height: placement.h.unwrap_or(image_height),
|
||||
source_origin_x: placement.x.unwrap_or(0),
|
||||
source_origin_y: placement.y.unwrap_or(0),
|
||||
display_offset_x: placement.x_offset.unwrap_or(0),
|
||||
display_offset_y: placement.y_offset.unwrap_or(0),
|
||||
padding_left: placement.x_offset.unwrap_or(0) as u16,
|
||||
padding_top: placement.y_offset.unwrap_or(0) as u16,
|
||||
data: img,
|
||||
style: ImageAttachStyle::Kitty,
|
||||
z_index: placement.z_index.unwrap_or(0),
|
||||
|
@ -116,8 +116,8 @@ impl TerminalState {
|
||||
columns: None,
|
||||
source_origin_x: 0,
|
||||
source_origin_y: 0,
|
||||
display_offset_x: 0,
|
||||
display_offset_y: 0,
|
||||
padding_left: 0,
|
||||
padding_top: 0,
|
||||
data: image_data,
|
||||
style: ImageAttachStyle::Sixel,
|
||||
z_index: 0,
|
||||
|
@ -87,8 +87,10 @@ pub struct ImageCell {
|
||||
z_index: i32,
|
||||
/// When rendering in the cell, use this offset from the top left
|
||||
/// of the cell
|
||||
display_offset_x: u32,
|
||||
display_offset_y: u32,
|
||||
padding_left: u16,
|
||||
padding_top: u16,
|
||||
padding_right: u16,
|
||||
padding_bottom: u16,
|
||||
|
||||
image_id: Option<u32>,
|
||||
placement_id: Option<u32>,
|
||||
@ -100,7 +102,7 @@ impl ImageCell {
|
||||
bottom_right: TextureCoordinate,
|
||||
data: Arc<ImageData>,
|
||||
) -> Self {
|
||||
Self::with_z_index(top_left, bottom_right, data, 0, 0, 0, None, None)
|
||||
Self::with_z_index(top_left, bottom_right, data, 0, 0, 0, 0, 0, None, None)
|
||||
}
|
||||
|
||||
pub fn with_z_index(
|
||||
@ -108,8 +110,10 @@ impl ImageCell {
|
||||
bottom_right: TextureCoordinate,
|
||||
data: Arc<ImageData>,
|
||||
z_index: i32,
|
||||
display_offset_x: u32,
|
||||
display_offset_y: u32,
|
||||
padding_left: u16,
|
||||
padding_top: u16,
|
||||
padding_right: u16,
|
||||
padding_bottom: u16,
|
||||
image_id: Option<u32>,
|
||||
placement_id: Option<u32>,
|
||||
) -> Self {
|
||||
@ -118,8 +122,10 @@ impl ImageCell {
|
||||
bottom_right,
|
||||
data,
|
||||
z_index,
|
||||
display_offset_x,
|
||||
display_offset_y,
|
||||
padding_left,
|
||||
padding_top,
|
||||
padding_right,
|
||||
padding_bottom,
|
||||
image_id,
|
||||
placement_id,
|
||||
}
|
||||
@ -153,8 +159,14 @@ impl ImageCell {
|
||||
self.z_index
|
||||
}
|
||||
|
||||
pub fn display_offset(&self) -> (u32, u32) {
|
||||
(self.display_offset_x, self.display_offset_y)
|
||||
/// Returns padding (left, top, right, bottom)
|
||||
pub fn padding(&self) -> (u16, u16, u16, u16) {
|
||||
(
|
||||
self.padding_left,
|
||||
self.padding_top,
|
||||
self.padding_right,
|
||||
self.padding_bottom,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2420,14 +2420,14 @@ impl super::TermWindow {
|
||||
+ params.left_pixel_x
|
||||
+ (cell_idx as f32 * cell_width);
|
||||
|
||||
let (offset_x, offset_y) = image.display_offset();
|
||||
let (padding_left, padding_top, padding_right, padding_bottom) = image.padding();
|
||||
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_texture_adjust(
|
||||
offset_x as f32,
|
||||
offset_y as f32,
|
||||
offset_x as f32,
|
||||
offset_y as f32,
|
||||
padding_left as f32,
|
||||
padding_top as f32,
|
||||
padding_left as f32 - padding_right as f32,
|
||||
padding_top as f32 - padding_bottom as f32,
|
||||
);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_fg_color(glyph_color);
|
||||
|
Loading…
Reference in New Issue
Block a user