From 06107afdd4f0586099988c8eb7679f12b3bf3ada Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 29 Jun 2022 18:50:08 -0700 Subject: [PATCH] Added background colors and matched the cursor color --- crates/terminal/src/terminal_element.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/terminal/src/terminal_element.rs b/crates/terminal/src/terminal_element.rs index 64cf93c21a8447010da8f943e195ff991299b752..d81292d0c2e6bd18d8c3cf3c79be7dd432cada3f 100644 --- a/crates/terminal/src/terminal_element.rs +++ b/crates/terminal/src/terminal_element.rs @@ -42,8 +42,9 @@ pub struct LayoutState { lines: Vec, line_height: f32, em_width: f32, - cursor: Option, + cursor: Option<(RectF, Color)>, cur_size: SizeInfo, + background_color: Color, } impl Element for TerminalEl { @@ -114,9 +115,12 @@ impl Element for TerminalEl { .and_then(|cursor_line: usize| shaped_lines.get(cursor_line)) { let cursor_x = layout_line.x_for_index(content.cursor.point.column.0); - cursor = Some(RectF::new( - vec2f(cursor_x, cursor_line as f32 * line_height), - vec2f(cell_width, line_height), + cursor = Some(( + RectF::new( + vec2f(cursor_x, cursor_line as f32 * line_height), + vec2f(cell_width, line_height), + ), + terminal_theme.cursor, )); } @@ -128,6 +132,7 @@ impl Element for TerminalEl { em_width: cell_width, cursor, cur_size: new_size, + background_color: terminal_theme.background, }, ) } @@ -155,6 +160,14 @@ impl Element for TerminalEl { right_mouse_down_out: None, }); + //Background + cx.scene.push_quad(Quad { + bounds: visible_bounds, + background: Some(layout.background_color), + border: Default::default(), + corner_radius: 0., + }); + let origin = bounds.origin() + vec2f(layout.em_width, 0.); //Padding let mut line_origin = origin; @@ -168,12 +181,12 @@ impl Element for TerminalEl { line_origin.set_y(boundaries.max_y()); } - if let Some(c) = layout.cursor { + if let Some((c, color)) = layout.cursor { let new_origin = origin + c.origin(); let new_cursor = RectF::new(new_origin, c.size()); cx.scene.push_quad(Quad { bounds: new_cursor, - background: Some(Color::white()), + background: Some(color), border: Default::default(), corner_radius: 0., });