exa04 / cyma

Visualizers for nih-plug UIs made using VIZIA.
https://exa04.github.io/cyma/book
Mozilla Public License 2.0
35 stars 1 forks source link

New grid system #40

Closed exa04 closed 7 months ago

exa04 commented 7 months ago

Allows custom scaling and orientation of the Grid.

Breaking Change

This PR introduces a breaking change as it changes the parameter list for Grid::new(). The new grid works a bit differently from the old one; Grids are now limited to being either vertically or horizontally aligned. Also, a scaling has to be given

Here's how to adapt a grid to this new system (from the peak meter in the visualizers example)

Grid::new(
    cx,
+   ValueScaling::Linear,
    (-32.0, 8.0),
-   0.0,
    vec![6.0, 0.0, -6.0, -12.0, -18.0, -24.0, -30.0],
+   Orientation::Horizontal,
);

You will also have to layer two Grids to get both vertical and horizontal grid lines.

Example

This new system, although slightly more tedious to work with, grants you more control when it comes to the layout, scaling, and style of your grids. For example, here's the spectrum analyzer's grid from the visualizers example.

ZStack::new(cx, |cx| {
  Grid::new(
    cx,
    ValueScaling::Frequency,
    (10., 21_000.),
    vec![
        20., 40., 30., 50., 60., 70., 80., 90., 100., 200., 300., 400., 500., 600., 700.,
        800., 900., 1_000., 2_000., 3_000., 4_000., 5_000., 6_000., 7_000., 8_000., 9_000.,
        10_000., 20_000.,
    ],
    Orientation::Vertical,
  )
  .color(Color::rgb(60, 60, 60));

  Grid::new(
    cx,
    ValueScaling::Linear,
    (-80., 6.),
    vec![0., -10., -20., -30., -40., -50., -60., -70.],
    Orientation::Horizontal,
  )
  .color(Color::rgb(40, 40, 40));
  SpectrumAnalyzer::new(...);
}

The magnitude grid is also more faint than the frequency grid. They're in a ZStack, above the SpectrumAnalyzer.