| |
| #[derive(Clone, Debug, Default, PartialEq)] |
| pub enum Damage { |
| #[default] |
| None, |
| Full, |
| Lines(Vec<LineDamage>), |
| Rects(Vec<RectDamage>), |
| } |
|
|
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| pub struct LineDamage { |
| pub row: usize, |
| pub start_col: usize, |
| pub end_col: usize, |
| } |
|
|
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| pub struct RectDamage { |
| pub x: u32, |
| pub y: u32, |
| pub w: u32, |
| pub h: u32, |
| } |
|
|
| impl Damage { |
| pub fn add_line(&mut self, row: usize, start_col: usize, end_col: usize) { |
| match self { |
| Damage::None => { |
| *self = Damage::Lines(vec![LineDamage { row, start_col, end_col }]); |
| } |
| Damage::Lines(lines) => { |
| lines.push(LineDamage { row, start_col, end_col }); |
| } |
| _ => {} |
| } |
| } |
|
|
| pub fn add_rect(&mut self, x: u32, y: u32, w: u32, h: u32) { |
| match self { |
| Damage::None => { |
| *self = Damage::Rects(vec![RectDamage { x, y, w, h }]); |
| } |
| Damage::Rects(rects) => { |
| rects.push(RectDamage { x, y, w, h }); |
| } |
| _ => {} |
| } |
| } |
|
|
| pub fn set_full(&mut self) { |
| *self = Damage::Full; |
| } |
|
|
| pub fn take(&mut self) -> Damage { |
| std::mem::take(self) |
| } |
| } |
|
|