feat: input cursor bar

This commit is contained in:
2024-05-22 03:30:25 +02:00
parent 47beb1bbaf
commit 45983de4b4

View File

@@ -1,4 +1,3 @@
use core::panic;
use std::time::Duration; use std::time::Duration;
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
@@ -218,6 +217,9 @@ impl Runner {
} }
} }
let mut cursor_offset_x = PADDING;
let input_position_y: u16 = (PADDING + self.settings.line_spacing.div_ceil(4)).into();
if !self.input.is_empty() || !self.prompt.is_empty() { if !self.input.is_empty() || !self.prompt.is_empty() {
let surface = font let surface = font
.render(&format!("{}{}", &self.prompt, &self.input)) .render(&format!("{}{}", &self.prompt, &self.input))
@@ -226,11 +228,13 @@ impl Runner {
let rect = Rect::new( let rect = Rect::new(
PADDING.into(), PADDING.into(),
(PADDING + self.settings.line_spacing.div_ceil(4)).into(), input_position_y.into(),
surface.width(), surface.width(),
surface.height(), surface.height(),
); );
cursor_offset_x += surface.width() as u16;
let texture = creator let texture = creator
.create_texture_from_surface(surface) .create_texture_from_surface(surface)
.expect("Error creating texture"); .expect("Error creating texture");
@@ -238,6 +242,16 @@ impl Runner {
let _ = self.canvas.copy(&texture, None, Some(rect)); let _ = self.canvas.copy(&texture, None, Some(rect));
} }
let cursor_rect = Rect::new(
cursor_offset_x.into(),
input_position_y.into(),
3,
font.height() as u32,
);
self.canvas.set_draw_color(background_color_active);
let _ = self.canvas.fill_rect(cursor_rect);
// try to keep the selection centered // try to keep the selection centered
let executables_len: u16 = filtered_executables.len() as u16; let executables_len: u16 = filtered_executables.len() as u16;
let start: u16 = selection_index let start: u16 = selection_index