1
1
mirror of https://github.com/wez/wezterm.git synced 2024-08-17 02:00:25 +03:00

config: show/hide close-tab button

This commit is contained in:
Aleksey Kuznetsov 2024-07-13 11:32:54 -07:00 committed by Wez Furlong
parent 3607204d80
commit a46bad17d2
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 84 additions and 57 deletions

View File

@ -469,6 +469,9 @@ pub struct Config {
#[dynamic(default = "default_true")]
pub show_new_tab_button_in_tab_bar: bool,
#[dynamic(default = "default_true")]
pub show_close_tab_button_in_tabs: bool,
/// If true, show_tab_index_in_tab_bar uses a zero-based index.
/// The default is false and the tab shows a one-based index.
#[dynamic(default)]

View File

@ -0,0 +1,16 @@
---
tags:
- appearance
- tab_bar
---
# `show_close_tab_button_in_tabs = true`
{{since('nightly')}}
When set to `false`, the close-tab button will not be drawn in tabs when the
fancy tab bar is in use. Default is `true`.
```lua
config.show_close_tab_button_in_tabs = false
```

View File

@ -7,6 +7,8 @@ use crate::termwindow::render::window_buttons::window_button_element;
use crate::termwindow::{UIItem, UIItemType};
use crate::utilsprites::RenderMetrics;
use config::{Dimension, DimensionContext, TabBarColors};
use std::rc::Rc;
use wezterm_font::LoadedFont;
use wezterm_term::color::{ColorAttribute, ColorPalette};
use window::{IntegratedTitleButtonAlignment, IntegratedTitleButtonStyle};
@ -343,63 +345,9 @@ impl crate::TermWindow {
ElementContent::Text(_) => unreachable!(),
ElementContent::Poly { .. } => unreachable!(),
ElementContent::Children(mut kids) => {
let x_button = Element::new(
&font,
ElementContent::Poly {
line_width: metrics.underline_height.max(2),
poly: SizedPoly {
poly: X_BUTTON,
width: Dimension::Pixels(
metrics.cell_size.height as f32 / 2.,
),
height: Dimension::Pixels(
metrics.cell_size.height as f32 / 2.,
),
},
},
)
// Ensure that we draw our background over the
// top of the rest of the tab contents
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.float(Float::Right)
.item_type(UIItemType::CloseTab(tab_idx))
.hover_colors({
let inactive_tab_hover = colors.inactive_tab_hover();
let active_tab = colors.active_tab();
Some(ElementColors {
border: BorderColor::default(),
bg: (if active {
inactive_tab_hover.bg_color
} else {
active_tab.bg_color
})
.to_linear()
.into(),
text: (if active {
inactive_tab_hover.fg_color
} else {
active_tab.fg_color
})
.to_linear()
.into(),
})
})
.padding(BoxDimension {
left: Dimension::Cells(0.25),
right: Dimension::Cells(0.25),
top: Dimension::Cells(0.25),
bottom: Dimension::Cells(0.25),
})
.margin(BoxDimension {
left: Dimension::Cells(0.5),
right: Dimension::Cells(0.),
top: Dimension::Cells(0.),
bottom: Dimension::Cells(0.),
});
kids.push(x_button);
if self.config.show_close_tab_button_in_tabs {
kids.push(make_x_button(&font, &metrics, &colors, tab_idx, active));
}
ElementContent::Children(kids)
}
};
@ -522,3 +470,63 @@ impl crate::TermWindow {
Ok(ui_items)
}
}
fn make_x_button(
font: &Rc<LoadedFont>,
metrics: &RenderMetrics,
colors: &TabBarColors,
tab_idx: usize,
active: bool,
) -> Element {
Element::new(
&font,
ElementContent::Poly {
line_width: metrics.underline_height.max(2),
poly: SizedPoly {
poly: X_BUTTON,
width: Dimension::Pixels(metrics.cell_size.height as f32 / 2.),
height: Dimension::Pixels(metrics.cell_size.height as f32 / 2.),
},
},
)
// Ensure that we draw our background over the
// top of the rest of the tab contents
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.float(Float::Right)
.item_type(UIItemType::CloseTab(tab_idx))
.hover_colors({
let inactive_tab_hover = colors.inactive_tab_hover();
let active_tab = colors.active_tab();
Some(ElementColors {
border: BorderColor::default(),
bg: (if active {
inactive_tab_hover.bg_color
} else {
active_tab.bg_color
})
.to_linear()
.into(),
text: (if active {
inactive_tab_hover.fg_color
} else {
active_tab.fg_color
})
.to_linear()
.into(),
})
})
.padding(BoxDimension {
left: Dimension::Cells(0.25),
right: Dimension::Cells(0.25),
top: Dimension::Cells(0.25),
bottom: Dimension::Cells(0.25),
})
.margin(BoxDimension {
left: Dimension::Cells(0.5),
right: Dimension::Cells(0.),
top: Dimension::Cells(0.),
bottom: Dimension::Cells(0.),
})
}