1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-29 16:42:13 +03:00

start building out box model based render of pane

This commit is contained in:
Wez Furlong 2022-08-22 11:02:43 -07:00
parent 8040a8ae81
commit 5f64adb7f0
3 changed files with 129 additions and 1 deletions

View File

@ -546,6 +546,9 @@ pub struct Config {
#[dynamic(default)] #[dynamic(default)]
pub launch_menu: Vec<SpawnCommand>, pub launch_menu: Vec<SpawnCommand>,
#[dynamic(default)]
pub use_box_model_render: bool,
/// When true, watch the config file and reload it automatically /// When true, watch the config file and reload it automatically
/// when it is detected as changing. /// when it is detected as changing.
#[dynamic(default = "default_true")] #[dynamic(default = "default_true")]

View File

@ -52,7 +52,7 @@ impl Default for Float {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct PixelDimension { pub struct PixelDimension {
pub left: f32, pub left: f32,
pub top: f32, pub top: f32,

View File

@ -1138,11 +1138,136 @@ impl super::TermWindow {
}) })
} }
pub fn build_pane(
&mut self,
pos: &PositionedPane,
num_panes: usize,
) -> anyhow::Result<ComputedElement> {
// First compute the bounds for the pane background
let cell_width = self.render_metrics.cell_size.width as f32;
let cell_height = self.render_metrics.cell_size.height as f32;
let (padding_left, padding_top) = self.padding_left_top();
let tab_bar_height = if self.show_tab_bar {
self.tab_bar_pixel_height()?
} else {
0.
};
let (top_bar_height, bottom_bar_height) = if self.config.tab_bar_at_bottom {
(0.0, tab_bar_height)
} else {
(tab_bar_height, 0.0)
};
let border = self.get_os_border();
let top_pixel_y = top_bar_height + padding_top + border.top.get() as f32;
// We want to fill out to the edges of the splits
let (x, width_delta) = if pos.left == 0 {
(
0.,
padding_left + border.left.get() as f32 + (cell_width / 2.0),
)
} else {
(
padding_left + border.left.get() as f32 - (cell_width / 2.0)
+ (pos.left as f32 * cell_width),
cell_width,
)
};
let (y, height_delta) = if pos.top == 0 {
(
(top_pixel_y - padding_top),
padding_top + (cell_height / 2.0),
)
} else {
(
top_pixel_y + (pos.top as f32 * cell_height) - (cell_height / 2.0),
cell_height,
)
};
let background_rect = euclid::rect(
x,
y,
// Go all the way to the right edge if we're right-most
if pos.left + pos.width >= self.terminal_size.cols as usize {
self.dimensions.pixel_width as f32 - x
} else {
(pos.width as f32 * cell_width) + width_delta
},
// Go all the way to the bottom if we're bottom-most
if pos.top + pos.height >= self.terminal_size.rows as usize {
self.dimensions.pixel_height as f32 - y
} else {
(pos.height as f32 * cell_height) + height_delta as f32
},
);
// Bounds for the terminal cells
let content_rect = euclid::rect(
padding_left + border.left.get() as f32 - (cell_width / 2.0)
+ (pos.left as f32 * cell_width),
top_pixel_y + (pos.top as f32 * cell_height) - (cell_height / 2.0),
pos.width as f32 * cell_width,
pos.height as f32 * cell_height,
);
let palette = pos.pane.palette();
// TODO: visual bell background layer
// TODO: scrollbar
Ok(ComputedElement {
item_type: None,
zindex: 0,
bounds: background_rect,
border: PixelDimension::default(),
border_rect: background_rect,
border_corners: None,
colors: ElementColors {
border: BorderColor::default(),
bg: if num_panes > 1 && self.window_background.is_empty() {
palette
.background
.to_linear()
.mul_alpha(self.config.window_background_opacity)
.into()
} else {
InheritableColor::Inherited
},
text: InheritableColor::Inherited,
},
hover_colors: None,
padding: background_rect,
content_rect,
baseline: 1.0,
content: ComputedElementContent::Children(vec![]),
})
}
fn paint_pane_opengl_new(
&mut self,
pos: &PositionedPane,
num_panes: usize,
) -> anyhow::Result<()> {
let computed = self.build_pane(pos, num_panes)?;
let mut ui_items = computed.ui_items();
self.ui_items.append(&mut ui_items);
let gl_state = self.render_state.as_ref().unwrap();
self.render_element(&computed, gl_state, None)
}
pub fn paint_pane_opengl( pub fn paint_pane_opengl(
&mut self, &mut self,
pos: &PositionedPane, pos: &PositionedPane,
num_panes: usize, num_panes: usize,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if self.config.use_box_model_render {
return self.paint_pane_opengl_new(pos, num_panes);
}
self.check_for_dirty_lines_and_invalidate_selection(&pos.pane); self.check_for_dirty_lines_and_invalidate_selection(&pos.pane);
/* /*
let zone = { let zone = {