Skip to content

Commit

Permalink
config: show/hide close-tab button
Browse files Browse the repository at this point in the history
  • Loading branch information
zummenix authored and wez committed Jul 13, 2024
1 parent 3607204 commit a46bad1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 57 deletions.
3 changes: 3 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
16 changes: 16 additions & 0 deletions docs/config/lua/config/show_close_tab_button_in_tabs.md
Original file line number Diff line number Diff line change
@@ -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
```
122 changes: 65 additions & 57 deletions wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)
}
};
Expand Down Expand Up @@ -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.),
})
}

0 comments on commit a46bad1

Please sign in to comment.