Skip to content

Commit

Permalink
fix stacking of beat effects
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Dec 7, 2024
1 parent 2c2bb79 commit 4dc3e7f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/ui/canvas_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,12 @@ fn draw_beat(
frame.fill_text(note_effect_text);
};

// Annotate note effect above (same position for all notes)
let mut beat_annotations = Vec::new();

// draw notes for beat
for note in &beat.notes {
beat_annotations.extend(above_note_effect_annotation(&note.effect));
draw_note(
frame,
measure_start_y,
Expand All @@ -391,22 +395,15 @@ fn draw_beat(
beat_color,
);
}
}

fn draw_note(
frame: &mut Frame<Renderer>,
measure_start_y: f32,
beat_position_x: f32,
width_per_beat: f32,
note: &Note,
beat_color: Color,
) {
// Annotate note effect above (same position for all notes)
let annotations = above_note_effect_annotation(&note.effect);
if !annotations.is_empty() {
let merged_annotations = annotations.join("\n");
let y_position = NOTE_EFFECT_ANNOTATION_Y - 4.0 * (annotations.len() - 1) as f32;
// merge and display beat annotations
if !beat_annotations.is_empty() {
beat_annotations.sort_unstable();
beat_annotations.dedup();
let merged_annotations = beat_annotations.join("\n");
let y_position = NOTE_EFFECT_ANNOTATION_Y - 4.0 * (beat_annotations.len() - 1) as f32;
let note_effect_text = Text {
shaping: Advanced, // required for printing unicode
content: merged_annotations,
color: Color::WHITE,
size: 9.0.into(),
Expand All @@ -415,14 +412,24 @@ fn draw_note(
};
frame.fill_text(note_effect_text);
}
}

fn draw_note(
frame: &mut Frame<Renderer>,
measure_start_y: f32,
beat_position_x: f32,
width_per_beat: f32,
note: &Note,
beat_color: Color,
) {
// note label (pushed down on the right string)
let note_label = note_value(note);
let local_beat_position_y = (note.string as f32 - 1.0) * STRING_LINE_HEIGHT;
// center the notes with more than one char
let note_position_x = beat_position_x + 3.0 - note_label.chars().count() as f32 / 2.0;
let note_position_y = measure_start_y + local_beat_position_y - 5.0;
let note_text = Text {
shaping: Advanced, // required for printing unicode
content: note_label,
color: beat_color,
size: 10.0.into(),
Expand Down

0 comments on commit 4dc3e7f

Please sign in to comment.