Skip to content

Commit d9af73a

Browse files
refactor(spectrum): reuse cutout pass to mask lines
Signed-off-by: Maika Namuo <httpworldview@gmail.com>
1 parent ce31954 commit d9af73a

1 file changed

Lines changed: 12 additions & 31 deletions

File tree

‎src/visuals/spectrum/state.rs‎

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,14 @@ crate::visuals::visualization_widget!(Spectrum, SpectrumState, |this, r, th, b|
417417
return;
418418
};
419419
r.draw_primitive(b, params);
420-
if let Some(cutouts) = state.cutout_params(b, th) {
421-
r.draw_primitive(b, cutouts);
422-
}
423420
if let Some(range) = grid_range {
424-
r.with_layer(b, |r| draw_grid_lines(r, th, b, range, &state));
425-
r.with_layer(b, |r| draw_grid_labels(r, th, &state));
421+
r.with_layer(b, |r| {
422+
draw_grid_lines(r, th, b, range, &state);
423+
if let Some(cutouts) = state.cutout_params(b, th) {
424+
r.draw_primitive(b, cutouts);
425+
}
426+
draw_grid_labels(r, th, &state);
427+
});
426428
}
427429
if let Some((peak, layout)) = peak.zip(peak_layout) {
428430
let peak_color = state.palette[PEAK_PALETTE_INDEX];
@@ -671,36 +673,15 @@ fn draw_grid_lines(
671673
let text_color = th.extended_palette().background.base.text;
672674
let major_color = with_alpha(text_color, 0.25);
673675
let minor_color = with_alpha(text_color, 0.10);
674-
let bottom = bounds.y + bounds.height;
675676

676677
for (frequency, major, _) in &state.grid_ticks {
677678
let Some(x) = axis.tick_x(*frequency) else { continue };
678679
let x = (x - 0.5).clamp(bounds.x, (bounds.x + bounds.width - 1.0).max(bounds.x));
679-
let color = if *major { major_color } else { minor_color };
680-
let label_index = state
681-
.grid_labels
682-
.partition_point(|label| label.bounds.x + label.bounds.width <= x);
683-
let blocker = state
684-
.grid_labels
685-
.get(label_index)
686-
.filter(|label| label.bounds.x < x + 1.0);
687-
let mut draw_segment = |top: f32, segment_bottom: f32| {
688-
if segment_bottom > top {
689-
fill_rect(
690-
r,
691-
Rectangle::new(Point::new(x, top), Size::new(1.0, segment_bottom - top)),
692-
color,
693-
);
694-
}
695-
};
696-
if let Some(label) = blocker {
697-
let cutout_top = label.bounds.y.clamp(bounds.y, bottom);
698-
let cutout_bottom = (label.bounds.y + label.bounds.height).clamp(cutout_top, bottom);
699-
draw_segment(bounds.y, cutout_top);
700-
draw_segment(cutout_bottom, bottom);
701-
} else {
702-
draw_segment(bounds.y, bottom);
703-
}
680+
fill_rect(
681+
r,
682+
Rectangle::new(Point::new(x, bounds.y), Size::new(1.0, bounds.height)),
683+
if *major { major_color } else { minor_color },
684+
);
704685
}
705686
}
706687

0 commit comments

Comments
 (0)