mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-24 14:11:55 +00:00
Hints title refactor (#608)
This commit is contained in:
parent
b69e823375
commit
8637adf373
|
@ -37,7 +37,7 @@ pub struct FloatingText {
|
|||
max_line_width: usize,
|
||||
v_scroll: usize,
|
||||
h_scroll: usize,
|
||||
mode: FloatingTextMode,
|
||||
mode_title: &'static str,
|
||||
}
|
||||
|
||||
macro_rules! style {
|
||||
|
@ -139,10 +139,9 @@ impl FloatingText {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
let max_line_width = max_width!(src);
|
||||
|
||||
Self {
|
||||
src,
|
||||
mode,
|
||||
mode_title: Self::get_mode_title(mode),
|
||||
max_line_width,
|
||||
v_scroll: 0,
|
||||
h_scroll: 0,
|
||||
|
@ -172,13 +171,20 @@ impl FloatingText {
|
|||
|
||||
Some(Self {
|
||||
src,
|
||||
mode,
|
||||
mode_title: Self::get_mode_title(mode),
|
||||
max_line_width,
|
||||
h_scroll: 0,
|
||||
v_scroll: 0,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_mode_title(mode: FloatingTextMode) -> &'static str {
|
||||
match mode {
|
||||
FloatingTextMode::Preview => "Command Preview",
|
||||
FloatingTextMode::Description => "Command Description",
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll_down(&mut self) {
|
||||
if self.v_scroll + 1 < self.src.len() {
|
||||
self.v_scroll += 1;
|
||||
|
@ -207,14 +213,9 @@ impl FloatingText {
|
|||
impl FloatContent for FloatingText {
|
||||
fn draw(&mut self, frame: &mut Frame, area: Rect) {
|
||||
// Define the Block with a border and background color
|
||||
let block_title = match self.mode {
|
||||
FloatingTextMode::Preview => "Command Preview",
|
||||
FloatingTextMode::Description => "Command Description",
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(block_title)
|
||||
.title(self.mode_title)
|
||||
.title_alignment(ratatui::layout::Alignment::Center)
|
||||
.title_style(Style::default().reversed())
|
||||
.style(Style::default());
|
||||
|
@ -292,7 +293,7 @@ impl FloatContent for FloatingText {
|
|||
|
||||
fn get_shortcut_list(&self) -> ShortcutList {
|
||||
ShortcutList {
|
||||
scope_name: "Floating text",
|
||||
scope_name: self.mode_title,
|
||||
hints: vec![
|
||||
Shortcut::new(vec!["j", "Down"], "Scroll down"),
|
||||
Shortcut::new(vec!["k", "Up"], "Scroll up"),
|
||||
|
|
|
@ -35,7 +35,7 @@ pub fn span_vec_len(span_vec: &[Span]) -> usize {
|
|||
impl ShortcutList {
|
||||
pub fn draw(&self, frame: &mut Frame, area: Rect) {
|
||||
let block = Block::default()
|
||||
.title(self.scope_name)
|
||||
.title(format!(" {} ", self.scope_name))
|
||||
.borders(Borders::all());
|
||||
let inner_area = area.inner(Margin::new(1, 1));
|
||||
let shortcut_spans: Vec<Vec<Span>> = self.hints.iter().map(|h| h.to_spans()).collect();
|
||||
|
@ -145,7 +145,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
|
|||
hints.push(Shortcut::new(vec!["Tab"], "Next tab"));
|
||||
hints.push(Shortcut::new(vec!["Shift-Tab"], "Previous tab"));
|
||||
ShortcutList {
|
||||
scope_name: "Item list",
|
||||
scope_name: "Command list",
|
||||
hints,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user