Merge pull request #1465 from zed-industries/render-bug

Fix cell background rendering
This commit is contained in:
Mikayla Maki 2022-08-03 15:06:28 -07:00 committed by GitHub
commit 10c28891dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 17 deletions

View file

@ -1,8 +1,9 @@
Design notes:
This crate is split into two conceptual halves:
- The terminal.rs file and the ./src/mappings/ folder, these contain the code for interacting with Alacritty and maintaining the pty event loop. Some behavior in this file is constrained by terminal protocols and standards. The Zed init function is also placed here.
- The terminal.rs file and the src/mappings/ folder, these contain the code for interacting with Alacritty and maintaining the pty event loop. Some behavior in this file is constrained by terminal protocols and standards. The Zed init function is also placed here.
- Everything else. These other files integrate the `Terminal` struct created in terminal.rs into the rest of GPUI. The main entry point for GPUI is the terminal_view.rs file and the modal.rs file.
Terminals are created externally, and so can fail in unexpected ways However, GPUI currently does not have an API for models than can fail to instantiate. `TerminalBuilder` solves this by using Rust's type system to split `Terminal` instantiation into a 2 step process: first attempt to create the file handles with `TerminalBuilder::new()`, check the result, then call `TerminalBuilder::subscribe(cx)` from within a model context.
The TerminalView struct abstracts over failed and successful terminals, and provides other constructs a standardized way of instantiating an always-successful terminal view.
The TerminalView struct abstracts over failed and successful terminals, and provides a standardized way of instantiating an always-successful view of a terminal.

View file

@ -53,6 +53,7 @@ pub struct LayoutState {
display_offset: usize,
}
#[derive(Debug)]
struct IndexedCell {
point: Point,
cell: Cell,
@ -108,7 +109,14 @@ impl LayoutCell {
visible_bounds: RectF,
cx: &mut PaintContext,
) {
let pos = point_to_absolute(origin, self.point, layout);
let pos = {
let point = self.point;
vec2f(
(origin.x() + point.column as f32 * layout.size.cell_width).floor(),
origin.y() + point.line as f32 * layout.size.line_height,
)
};
self.text
.paint(pos, visible_bounds, layout.size.line_height, cx);
}
@ -139,10 +147,15 @@ impl LayoutRect {
}
fn paint(&self, origin: Vector2F, layout: &LayoutState, cx: &mut PaintContext) {
let position = point_to_absolute(origin, self.point, layout);
let position = {
let point = self.point;
vec2f(
(origin.x() + point.column as f32 * layout.size.cell_width).floor(),
origin.y() + point.line as f32 * layout.size.line_height,
)
};
let size = vec2f(
(layout.size.cell_width.ceil() * self.num_of_cells as f32).ceil(),
(layout.size.cell_width * self.num_of_cells as f32).ceil(),
layout.size.line_height,
);
@ -155,13 +168,6 @@ impl LayoutRect {
}
}
fn point_to_absolute(origin: Vector2F, point: Point<i32, i32>, layout: &LayoutState) -> Vector2F {
vec2f(
(origin.x() + point.column as f32 * layout.size.cell_width).floor(),
origin.y() + point.line as f32 * layout.size.line_height,
)
}
#[derive(Clone, Debug, Default)]
struct RelativeHighlightedRange {
line_index: usize,
@ -325,7 +331,6 @@ impl TerminalEl {
rects.push(cur_rect.take().unwrap());
}
}
(cells, rects, highlight_ranges)
}
@ -343,12 +348,14 @@ impl TerminalEl {
text_fragment.width()
};
//Cursor should always surround as much of the text as possible,
//hence when on pixel boundaries round the origin down and the width up
Some((
vec2f(
cursor_point.col() as f32 * size.cell_width(),
cursor_point.line() as f32 * size.line_height(),
(cursor_point.col() as f32 * size.cell_width()).floor(),
(cursor_point.line() as f32 * size.line_height()).floor(),
),
cursor_width,
cursor_width.ceil(),
))
} else {
None