Skip to content

Commit

Permalink
Fix: Scrollbar not fading when swapping windows in animation
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-freezing-lava committed Oct 7, 2023
1 parent 15be6d5 commit 4fec552
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
30 changes: 17 additions & 13 deletions alacritty/src/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,23 +1114,27 @@ impl Display {
self.window.request_redraw();
opacity
},
scrollbar::ScrollbarState::Invisible => 0.,
scrollbar::ScrollbarState::Invisible { has_damage } => {
if !has_damage {
return;
}
0.
},
};
if opacity == 0. {
return;
}

let bg_rect = self.scrollbar.bg_rect(self.size_info);
let scrollbar_rect = self.scrollbar.rect_from_bg_rect(bg_rect, self.size_info);
let y = self.size_info.height - (scrollbar_rect.y + scrollbar_rect.height) as f32;
rects.push(RenderRect::new(
scrollbar_rect.x as f32,
y,
scrollbar_rect.width as f32,
scrollbar_rect.height as f32,
config.color,
opacity,
));
if opacity != 0. {
rects.push(RenderRect::new(
scrollbar_rect.x as f32,
y,
scrollbar_rect.width as f32,
scrollbar_rect.height as f32,
config.color,
opacity,
));
}

if did_position_change {
self.damage_rects.push(bg_rect);
} else if config.mode == ScrollbarMode::Fading && opacity < config.opacity.as_f32() {
Expand Down
54 changes: 32 additions & 22 deletions alacritty/src/display/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ impl From<&ScrollbarConfig> for Scrollbar {

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ScrollbarState {
Show { opacity: f32 },
WaitForFading { opacity: f32, remaining_duration: Duration },
Fading { opacity: f32 },
Invisible,
}

impl ScrollbarState {
pub fn opacity(&self) -> f32 {
match self {
ScrollbarState::Show { opacity } => *opacity,
ScrollbarState::WaitForFading { opacity, .. } => *opacity,
ScrollbarState::Fading { opacity } => *opacity,
ScrollbarState::Invisible => 0.0,
}
}
Show {
opacity: f32,
},
WaitForFading {
opacity: f32,
remaining_duration: Duration,
},
Fading {
opacity: f32,
},
/// `has_damage` - If the scrollbar was previously viisible, we need to draw a damage rect.
Invisible {
has_damage: bool,
},
}

impl Scrollbar {
Expand Down Expand Up @@ -79,12 +78,24 @@ impl Scrollbar {
self.last_change = None;
}

pub fn is_visible(&self, display_size: SizeInfo) -> bool {
match self.config.mode {
ScrollbarMode::Never => false,
ScrollbarMode::Fading => {
self.is_dragging()
|| self.total_lines > display_size.screen_lines
&& self.last_change_time().is_some()
},
ScrollbarMode::Always => true,
}
}

pub fn intensity(&mut self, display_size: SizeInfo) -> ScrollbarState {
match self.config.mode {
ScrollbarMode::Never => ScrollbarState::Invisible,
ScrollbarMode::Never => ScrollbarState::Invisible { has_damage: false },
ScrollbarMode::Fading => {
if self.total_lines <= display_size.screen_lines {
return ScrollbarState::Invisible;
return ScrollbarState::Invisible { has_damage: false };
}
if self.is_dragging() {
self.last_change = Some(Instant::now());
Expand All @@ -106,11 +117,11 @@ impl Scrollbar {
ScrollbarState::Fading { opacity }
} else {
self.clear_change_time();
ScrollbarState::Invisible
ScrollbarState::Invisible { has_damage: true }
}
}
} else {
ScrollbarState::Invisible
ScrollbarState::Invisible { has_damage: false }
}
},
ScrollbarMode::Always => ScrollbarState::Show { opacity: self.config.opacity.as_f32() },
Expand Down Expand Up @@ -160,8 +171,7 @@ impl Scrollbar {
mouse_x: usize,
mouse_y: usize,
) -> bool {
let intensity = self.intensity(display_size).opacity();
if intensity == 0. {
if !self.is_visible(display_size) {
return false;
}

Expand Down Expand Up @@ -208,7 +218,7 @@ impl Scrollbar {
true
}

pub fn is_dragging(&mut self) -> bool {
pub fn is_dragging(&self) -> bool {
self.drag_state.is_some()
}

Expand Down

0 comments on commit 4fec552

Please sign in to comment.