1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

background: implement offsets and alignment

This commit is contained in:
Wez Furlong 2022-05-31 19:39:28 -07:00
parent 40afbf1ec9
commit 590bcf2f75
2 changed files with 44 additions and 3 deletions

View File

@ -74,9 +74,13 @@ pub struct BackgroundLayer {
#[dynamic(default)]
pub vertical_align: BackgroundVerticalAlignment,
#[dynamic(try_from = "crate::units::OptPixelUnit", default)]
pub vertical_offset: Option<Dimension>,
#[dynamic(default)]
pub horizontal_align: BackgroundHorizontalAlignment,
#[dynamic(try_from = "crate::units::OptPixelUnit", default)]
pub horizontal_offset: Option<Dimension>,
/// Additional alpha modifier
#[dynamic(default = "default_one_point_oh")]
@ -119,6 +123,8 @@ impl BackgroundLayer {
repeat_y_size: None,
vertical_align: Default::default(),
horizontal_align: Default::default(),
vertical_offset: None,
horizontal_offset: None,
width: BackgroundSize::Dimension(Dimension::Percent(1.)),
height: BackgroundSize::Dimension(Dimension::Percent(1.)),
})

View File

@ -4,8 +4,9 @@ use crate::utilsprites::RenderMetrics;
use crate::Dimensions;
use anyhow::Context;
use config::{
BackgroundLayer, BackgroundRepeat, BackgroundSize, BackgroundSource, ConfigHandle,
DimensionContext, GradientOrientation,
BackgroundHorizontalAlignment, BackgroundLayer, BackgroundRepeat, BackgroundSize,
BackgroundSource, BackgroundVerticalAlignment, ConfigHandle, DimensionContext,
GradientOrientation,
};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
@ -414,10 +415,44 @@ impl crate::TermWindow {
BackgroundSize::Cover => min_aspect_height as f32,
BackgroundSize::Dimension(n) => n.evaluate_as_pixels(v_context),
};
let origin_x = pixel_width / -2.;
let mut origin_x = pixel_width / -2.;
let top_pixel = pixel_height / -2.;
let mut origin_y = top_pixel;
match layer.def.vertical_align {
BackgroundVerticalAlignment::Top => {}
BackgroundVerticalAlignment::Bottom => {
origin_y += pixel_height - height;
}
BackgroundVerticalAlignment::Middle => {
origin_y += (pixel_height - height) / 2.;
}
}
match layer.def.horizontal_align {
BackgroundHorizontalAlignment::Left => {}
BackgroundHorizontalAlignment::Right => {
origin_x += pixel_width - width;
}
BackgroundHorizontalAlignment::Center => {
origin_x += (pixel_width - width) / 2.;
}
}
let vertical_offset = layer
.def
.vertical_offset
.map(|d| d.evaluate_as_pixels(v_context))
.unwrap_or(0.);
origin_y += vertical_offset;
let horizontal_offset = layer
.def
.horizontal_offset
.map(|d| d.evaluate_as_pixels(h_context))
.unwrap_or(0.);
origin_x += horizontal_offset;
let repeat_x = layer
.def
.repeat_x_size