Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/commit_details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ impl DrawableComponent for DetailsComponent {
f,
chunks[1],
&self.theme,
self.get_number_of_lines(width as usize)
.saturating_sub(height as usize),
self.get_number_of_lines(width as usize),
self.scroll_top.get(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl DrawableComponent for DiffComponent {
r,
&self.theme,
self.lines_count(),
self.selection.get_end(),
self.scroll_top.get(),
);
}

Expand Down
23 changes: 13 additions & 10 deletions src/ui/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ use tui::{

///
struct Scrollbar {
max: u16,
lines: u16,
pos: u16,
style_bar: Style,
style_pos: Style,
}

impl Scrollbar {
fn new(max: usize, pos: usize) -> Self {
fn new(lines: usize, pos: usize) -> Self {
Self {
max: u16::try_from(max).unwrap_or_default(),
lines: u16::try_from(lines).unwrap_or_default(),
pos: u16::try_from(pos).unwrap_or_default(),
style_pos: Style::default(),
style_bar: Style::default(),
Expand All @@ -41,24 +41,27 @@ impl Widget for Scrollbar {
vertical: 1,
});

if area.height < 4 {
if area.height == 0 {
return;
}

if area.height > self.max {
if area.height >= self.lines {
return;
}

for y in area.top()..area.bottom() {
buf.set_string(right, y, THICK_VERTICAL, self.style_bar);
}

let progress = f32::from(self.pos) / f32::from(self.max);
let pos = f32::from(area.height.saturating_sub(1)) * progress;
let max_pos = self.lines.saturating_sub(area.height);
let progress = f32::from(self.pos) / f32::from(max_pos);
let progress = if progress > 1.0 { 1.0 } else { progress };
let pos = f32::from(area.height) * progress;

//TODO: any better way for this?
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_truncation)]
let pos = pos as u16;
let pos = (pos as u16).saturating_sub(1);

buf.set_string(right, area.top() + pos, FULL, self.style_pos);
}
Expand All @@ -68,10 +71,10 @@ pub fn draw_scrollbar<B: Backend>(
f: &mut Frame<B>,
r: Rect,
theme: &SharedTheme,
max: usize,
lines: usize,
pos: usize,
) {
let mut widget = Scrollbar::new(max, pos);
let mut widget = Scrollbar::new(lines, pos);
widget.style_pos = theme.scroll_bar_pos();
f.render_widget(widget, r)
}