refactor(statusline): rename `buffer` into `parts`

pull/2434/head
etienne-k 3 years ago
parent 1e9543953d
commit f3513a6526

@ -18,7 +18,7 @@ pub struct RenderContext<'a> {
pub theme: &'a Theme, pub theme: &'a Theme,
pub focused: bool, pub focused: bool,
pub spinners: &'a ProgressSpinners, pub spinners: &'a ProgressSpinners,
pub buffer: RenderBuffer<'a>, pub parts: RenderBuffer<'a>,
} }
impl<'a> RenderContext<'a> { impl<'a> RenderContext<'a> {
@ -35,7 +35,7 @@ impl<'a> RenderContext<'a> {
theme, theme,
focused, focused,
spinners, spinners,
buffer: RenderBuffer::default(), parts: RenderBuffer::default(),
} }
} }
} }
@ -65,13 +65,13 @@ impl StatusLine {
surface.set_style(viewport.with_height(1), base_style); surface.set_style(viewport.with_height(1), base_style);
let write_left = |context: &mut RenderContext, text, style| { let write_left = |context: &mut RenderContext, text, style| {
Self::append(&mut context.buffer.left, text, &base_style, style) Self::append(&mut context.parts.left, text, &base_style, style)
}; };
let write_center = |context: &mut RenderContext, text, style| { let write_center = |context: &mut RenderContext, text, style| {
Self::append(&mut context.buffer.center, text, &base_style, style) Self::append(&mut context.parts.center, text, &base_style, style)
}; };
let write_right = |context: &mut RenderContext, text, style| { let write_right = |context: &mut RenderContext, text, style| {
Self::append(&mut context.buffer.right, text, &base_style, style) Self::append(&mut context.parts.right, text, &base_style, style)
}; };
// Left side of the status line. // Left side of the status line.
@ -85,8 +85,8 @@ impl StatusLine {
surface.set_spans( surface.set_spans(
viewport.x, viewport.x,
viewport.y, viewport.y,
&context.buffer.left, &context.parts.left,
context.buffer.left.width() as u16, context.parts.left.width() as u16,
); );
// Right side of the status line. // Right side of the status line.
@ -101,10 +101,10 @@ impl StatusLine {
viewport.x viewport.x
+ viewport + viewport
.width .width
.saturating_sub(context.buffer.right.width() as u16), .saturating_sub(context.parts.right.width() as u16),
viewport.y, viewport.y,
&context.buffer.right, &context.parts.right,
context.buffer.right.width() as u16, context.parts.right.width() as u16,
); );
// Center of the status line. // Center of the status line.
@ -118,18 +118,14 @@ impl StatusLine {
// Width of the empty space between the left and center area and between the center and right area. // Width of the empty space between the left and center area and between the center and right area.
let spacing = 1u16; let spacing = 1u16;
let edge_width = context let edge_width = context.parts.left.width().max(context.parts.right.width()) as u16;
.buffer
.left
.width()
.max(context.buffer.right.width()) as u16;
let center_max_width = viewport.width - (2 * edge_width + 2 * spacing); let center_max_width = viewport.width - (2 * edge_width + 2 * spacing);
let center_width = center_max_width.min(context.buffer.center.width() as u16); let center_width = center_max_width.min(context.parts.center.width() as u16);
surface.set_spans( surface.set_spans(
viewport.x + viewport.width / 2 - center_width / 2, viewport.x + viewport.width / 2 - center_width / 2,
viewport.y, viewport.y,
&context.buffer.center, &context.parts.center,
center_width, center_width,
); );
} }

Loading…
Cancel
Save