Skip to content

Commit

Permalink
use Cell instead of RefCell for storing wave colour
Browse files Browse the repository at this point in the history
  • Loading branch information
B0ney committed Mar 11, 2024
1 parent dae9f48 commit ac0f72b
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/widget/waveform_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iced::mouse::Button;
use iced::widget::canvas::{self, Renderer as _};
use iced::{keyboard, Border, Renderer};
use iced::{Color, Element, Length, Point, Rectangle, Size, Vector};
use std::cell::RefCell;
use std::cell::Cell;

pub use marker::Marker;
pub use style::{Appearance, StyleSheet};
Expand Down Expand Up @@ -204,7 +204,7 @@ struct State {
wave_id: u64,
canvas_cache: canvas::Cache,
waveform: WaveGeometry,
wave_color: RefCell<Color>,
wave_color: Cell<Color>,
}

impl State {
Expand Down Expand Up @@ -261,16 +261,11 @@ impl State {

// Clear canvas cache if wave colors differ
fn update_wave_color(&self, appearance: &Appearance) {
use std::ops::DerefMut;

let new_color = appearance.wave_color;

match self.wave_color.borrow_mut().deref_mut() {
old_color if new_color.ne(old_color) => {
*old_color = new_color;
self.canvas_cache.clear();
}
_ => {}

if new_color != self.wave_color.get() {
self.wave_color.set(new_color);
self.canvas_cache.clear();
}
}
}
Expand Down

0 comments on commit ac0f72b

Please sign in to comment.