Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic dimming functionality #2751

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
expand alpha range for new shade function
  • Loading branch information
farwyler committed Jul 2, 2022
commit e6ac344e2158e2505da1d97136614561ddcef3df
2 changes: 1 addition & 1 deletion helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ impl Buffer {
/// shade < 0 -> darken rgb color
/// shade > 0 -> lighten rgb color
pub fn dim(&mut self, area: Rect, shade: i8) {
let alpha = i32::from(shade).unsigned_abs();
let alpha = i32::from(shade).unsigned_abs() << 1;
let (src_factor, dst_factor) = (alpha, 256 - alpha);
let src = if shade > 0 { 255u32 } else { 0u32 } * src_factor;
let shaded = |dst_color: u8| ((u32::from(dst_color) * dst_factor + src) >> 8) as u8;
Expand Down