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

improve width constraints in box_model, center command palette

refs: https://github.com/wez/wezterm/issues/1485
This commit is contained in:
Wez Furlong 2022-12-23 09:03:51 -07:00
parent b789ec447a
commit 3a9513e194
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
2 changed files with 19 additions and 4 deletions

View File

@ -489,6 +489,7 @@ pub enum ElementCell {
Glyph(Rc<CachedGlyph>),
}
#[derive(Debug)]
struct Rects {
padding: RectF,
border_rect: RectF,
@ -569,6 +570,7 @@ impl super::TermWindow {
.map(|c| c.to_pixels(context));
let style = element.font.style();
let border = element.border.to_pixels(context);
let padding = element.padding.to_pixels(context);
let baseline = context.height.pixel_cell + context.metrics.descender.get() as f32;
let min_width = match element.min_width {
Some(w) => w.evaluate_as_pixels(context.width),
@ -579,6 +581,8 @@ impl super::TermWindow {
None => 0.0,
};
let border_and_padding_width = border.left + border.right + padding.left + padding.right;
match &element.content {
ElementContent::Text(s) => {
let window = self.window.as_ref().unwrap().clone();
@ -633,7 +637,7 @@ impl super::TermWindow {
None => pixel_width,
}
.max(min_width)
.min(context.width.pixel_max);
.min(context.width.pixel_max - border_and_padding_width);
let content_rect = euclid::rect(
0.,
@ -673,7 +677,7 @@ impl super::TermWindow {
.min(context.bounds.width()),
None => context.bounds.width(),
}
.min(context.width.pixel_max);
.min(context.width.pixel_max - border_and_padding_width);
for child in kids {
if child.display == DisplayType::Block {

View File

@ -324,6 +324,17 @@ impl CommandPalette {
let dimensions = term_window.dimensions;
let size = term_window.terminal_size;
// Avoid covering the entire width
let desired_width = (size.cols / 3).max(80).min(size.cols);
// Center it
let avail_pixel_width =
size.cols as f32 * term_window.render_metrics.cell_size.width as f32;
let desired_pixel_width =
desired_width as f32 * term_window.render_metrics.cell_size.width as f32;
let x_adjust = ((avail_pixel_width - padding_left) - desired_pixel_width) / 2.;
let computed = term_window.compute_element(
&LayoutContext {
height: DimensionContext {
@ -337,9 +348,9 @@ impl CommandPalette {
pixel_cell: metrics.cell_size.width as f32,
},
bounds: euclid::rect(
padding_left,
padding_left + x_adjust,
top_pixel_y,
size.cols as f32 * term_window.render_metrics.cell_size.width as f32,
desired_pixel_width,
size.rows as f32 * term_window.render_metrics.cell_size.height as f32,
),
metrics: &metrics,