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
removes caching in dim function
  • Loading branch information
farwyler committed Jul 2, 2022
commit 764540ff87b8df49e005d7fde0a42e2eb9c19f85
19 changes: 4 additions & 15 deletions helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,29 +595,18 @@ impl Buffer {
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;

let mut cache: HashMap<Color, Color> = HashMap::new();
let mut modify = |col| {
let result = cache.entry(col).or_insert_with(|| {
if let Color::Rgb(r, g, b) = col {
Color::Rgb(shaded(r), shaded(g), shaded(b))
} else {
col
}
});
*result
};
for y in area.top()..area.bottom() {
for x in area.left()..area.right() {
let cell = &mut self[(x, y)];

if shade == 0 {
cell.modifier.insert(Modifier::DIM);
} else {
if let Color::Rgb(..) = cell.fg {
cell.fg = modify(cell.fg);
if let Color::Rgb(r, g, b) = cell.fg {
cell.fg = Color::Rgb(shaded(r), shaded(g), shaded(b))
};
if let Color::Rgb(..) = cell.bg {
cell.bg = modify(cell.bg);
if let Color::Rgb(r, g, b) = cell.bg {
cell.bg = Color::Rgb(shaded(r), shaded(g), shaded(b))
}
}
}
Expand Down