From 4f27c79bf7b88e445075f8f6aaac0d9ae6affead Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sat, 24 Jul 2021 14:45:51 +0900 Subject: [PATCH] fix horizontal scroll bar style --- src/components/table.rs | 25 +++++++++++++------------ src/ui/scrollbar.rs | 11 ++++++++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/components/table.rs b/src/components/table.rs index 1e9475f..faf2328 100644 --- a/src/components/table.rs +++ b/src/components/table.rs @@ -302,6 +302,19 @@ impl DrawableComponent for TableComponent { }, ); + let column_width = area.width.saturating_pow(10); + self.horizontal_scroll.update( + if self.headers.is_empty() { + 0 + } else { + column_width + .saturating_mul(self.headers[..self.column_index].len() as u16) + .saturating_add(1) as usize + }, + column_width.saturating_mul(self.headers.len() as u16) as usize, + area.width.saturating_sub(2) as usize, + ); + TableValueComponent::new(self.selected_cell().unwrap_or_default()) .draw(f, layout[0], focused)?; @@ -315,18 +328,6 @@ impl DrawableComponent for TableComponent { Style::default() }) }); - let column_width = area.width.saturating_pow(10); - self.horizontal_scroll.update( - if self.headers.is_empty() { - 0 - } else { - column_width - .saturating_mul(self.headers[..self.column_index].len() as u16) - .saturating_add(1) as usize - }, - column_width.saturating_mul(self.headers.len() as u16) as usize, - area.width.saturating_sub(2) as usize, - ); let header = Row::new(header_cells).height(1).bottom_margin(1); let rows = rows.iter().enumerate().map(|(row_index, item)| { let height = item diff --git a/src/ui/scrollbar.rs b/src/ui/scrollbar.rs index af8ccdd..7820a78 100644 --- a/src/ui/scrollbar.rs +++ b/src/ui/scrollbar.rs @@ -4,7 +4,7 @@ use tui::{ backend::Backend, buffer::Buffer, layout::{Margin, Rect}, - style::Style, + style::{Color, Modifier, Style}, symbols::{ block::FULL, line::{DOUBLE_HORIZONTAL, DOUBLE_VERTICAL}, @@ -97,7 +97,12 @@ impl Widget for Scrollbar { if self.vertical { buf.set_string(right, bar_top + pos, FULL, self.style_pos); } else { - buf.set_string(bar_top + pos, bottom, "▆", self.style_pos); + buf.set_string( + bar_top + pos, + bottom, + "\u{2212}", + self.style_pos.add_modifier(Modifier::BOLD), + ); } } } @@ -110,6 +115,6 @@ pub fn draw_scrollbar( vertical: bool, ) { let mut widget = Scrollbar::new(max, pos, vertical); - widget.style_pos = Style::default(); + widget.style_pos = Style::default().fg(Color::Blue); f.render_widget(widget, r); }