mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Added a hollow mode to the cursor rendering code, for terminal lost focus
This commit is contained in:
parent
bba51c3ae6
commit
b9c73127b4
2 changed files with 47 additions and 5 deletions
|
@ -1753,6 +1753,7 @@ pub enum CursorShape {
|
||||||
Bar,
|
Bar,
|
||||||
Block,
|
Block,
|
||||||
Underscore,
|
Underscore,
|
||||||
|
Hollow,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CursorShape {
|
impl Default for CursorShape {
|
||||||
|
@ -1808,8 +1809,19 @@ impl Cursor {
|
||||||
self.origin + origin + Vector2F::new(0.0, self.line_height - 2.0),
|
self.origin + origin + Vector2F::new(0.0, self.line_height - 2.0),
|
||||||
vec2f(self.block_width, 2.0),
|
vec2f(self.block_width, 2.0),
|
||||||
),
|
),
|
||||||
|
CursorShape::Hollow => RectF::new(
|
||||||
|
self.origin + origin + Vector2F::new(0.0, self.line_height - 1.0),
|
||||||
|
vec2f(self.block_width, 1.0),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Draw text under the hollow block if need be
|
||||||
|
if matches!(self.shape, CursorShape::Hollow) {
|
||||||
|
if let Some(block_text) = &self.block_text {
|
||||||
|
block_text.paint(self.origin + origin, bounds, self.line_height, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cx.scene.push_quad(Quad {
|
cx.scene.push_quad(Quad {
|
||||||
bounds,
|
bounds,
|
||||||
background: Some(self.color),
|
background: Some(self.color),
|
||||||
|
@ -1817,8 +1829,38 @@ impl Cursor {
|
||||||
corner_radius: 0.,
|
corner_radius: 0.,
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(block_text) = &self.block_text {
|
if matches!(self.shape, CursorShape::Hollow) {
|
||||||
block_text.paint(self.origin + origin, bounds, self.line_height, cx);
|
//Top
|
||||||
|
cx.scene.push_quad(Quad {
|
||||||
|
bounds: RectF::new(
|
||||||
|
self.origin + origin + Vector2F::new(0.0, -1.0),
|
||||||
|
vec2f(self.block_width + 1., 1.0),
|
||||||
|
),
|
||||||
|
background: Some(self.color),
|
||||||
|
border: Border::new(0., Color::black()),
|
||||||
|
corner_radius: 0.,
|
||||||
|
});
|
||||||
|
//Left
|
||||||
|
cx.scene.push_quad(Quad {
|
||||||
|
bounds: RectF::new(self.origin + origin, vec2f(1.0, self.line_height)),
|
||||||
|
background: Some(self.color),
|
||||||
|
border: Border::new(0., Color::black()),
|
||||||
|
corner_radius: 0.,
|
||||||
|
});
|
||||||
|
//Right
|
||||||
|
cx.scene.push_quad(Quad {
|
||||||
|
bounds: RectF::new(
|
||||||
|
self.origin + origin + vec2f(self.block_width, 0.),
|
||||||
|
vec2f(1.0, self.line_height),
|
||||||
|
),
|
||||||
|
background: Some(self.color),
|
||||||
|
border: Border::new(0., Color::black()),
|
||||||
|
corner_radius: 0.,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if let Some(block_text) = &self.block_text {
|
||||||
|
block_text.paint(self.origin + origin, bounds, self.line_height, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -635,7 +635,7 @@ impl Element for TerminalEl {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.update(cx.app, |terminal, mcx| {
|
.update(cx.app, |terminal, mcx| {
|
||||||
terminal.set_size(dimensions);
|
terminal.set_size(dimensions);
|
||||||
terminal.render_lock(mcx, |content, cursor_text, style| {
|
terminal.render_lock(mcx, |content, cursor_text, blink_mode| {
|
||||||
let mut cells = vec![];
|
let mut cells = vec![];
|
||||||
cells.extend(
|
cells.extend(
|
||||||
content
|
content
|
||||||
|
@ -659,7 +659,7 @@ impl Element for TerminalEl {
|
||||||
content.cursor,
|
content.cursor,
|
||||||
content.display_offset,
|
content.display_offset,
|
||||||
cursor_text,
|
cursor_text,
|
||||||
style,
|
blink_mode,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -713,7 +713,7 @@ impl Element for TerminalEl {
|
||||||
let (shape, color) = if self.focused {
|
let (shape, color) = if self.focused {
|
||||||
(CursorShape::Block, terminal_theme.colors.cursor)
|
(CursorShape::Block, terminal_theme.colors.cursor)
|
||||||
} else {
|
} else {
|
||||||
(CursorShape::Underscore, terminal_theme.colors.foreground)
|
(CursorShape::Hollow, terminal_theme.colors.foreground)
|
||||||
};
|
};
|
||||||
|
|
||||||
Cursor::new(
|
Cursor::new(
|
||||||
|
|
Loading…
Reference in a new issue