emilk / egui_plot

2D plotting library in Rust for egui
Apache License 2.0
95 stars 31 forks source link

Implement custom ruler color for Plot #47

Open gweisert opened 2 months ago

gweisert commented 2 months ago

Implement custom ruler color for Plot which is exposed through the new custom_ruler_color method. The entire thing is only a few lines.

bircni commented 1 month ago

This should work, the current implementation doesn't support setting the color BUT it works with light and dark mode - your implementation doesn't work with light and dark mode as it is always the same color https://github.com/emilk/egui_plot/blob/0fe0ea6cbf0fe01f2b27f9247516fc63dbb25b0f/egui_plot/src/items/mod.rs#L1939

gweisert commented 1 month ago

@bircni I'm not quite sure what you are trying to say. If no custom ruler color is specified, the function you mentioned is still used to determine the color:

  // before
  let line_color = rulers_color(ui);
  // now
  let line_color = self.ruler_color.unwrap_or_else(|| rulers_color(ui));
bircni commented 1 month ago

Sure I wanted to say that it might be better to set two colors, one for dark and one for light. Sorry that was kinda weird how I wrote that

gweisert commented 1 month ago

That seems really unnecessary to me. If that is your use case, you can easily choose the color beforehand:

let my_color = if ui.visuals().dark_mode { Color32::RED } else { Color32::GREEN };
egui_plot::Plot::new("my_plot").custom_ruler_color(my_color).show( [...] )