Skip to content

Commit

Permalink
recompute linetracker when loading measures
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Sep 1, 2024
1 parent 8e7512a commit 83648d9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ui/tablature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ impl Tablature {
}
self.canvas_measures.push(measure);
}
// recompute line tracker with existing width
let existing_width = self.line_tracker.tablature_container_width;
std::mem::swap(
&mut self.line_tracker,
&mut LineTracker::make(&self.canvas_measures, existing_width),
);
}

pub fn update_container_width(&mut self, width: f32) {
Expand Down Expand Up @@ -136,12 +142,14 @@ impl Tablature {
#[derive(Default)]
struct LineTracker {
measure_to_line: Vec<usize>, // measure id to line number
tablature_container_width: f32,
}

impl LineTracker {
pub fn make(measures: &[CanvasMeasure], tablature_container_width: f32) -> Self {
let mut line_tracker = LineTracker {
measure_to_line: vec![0; measures.len()],
tablature_container_width,
};
let mut current_line = 1;
let mut horizontal_cursor = 0.0;
Expand Down

0 comments on commit 83648d9

Please sign in to comment.