Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a line's fill area's alpha channel #34

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion egui_plot/src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ pub struct Line {
pub(super) highlight: bool,
pub(super) allow_hover: bool,
pub(super) fill: Option<f32>,
pub(super) fill_alpha: f32,
pub(super) style: LineStyle,
id: Option<Id>,
}
Expand All @@ -440,6 +441,7 @@ impl Line {
highlight: false,
allow_hover: true,
fill: None,
fill_alpha: DEFAULT_FILL_ALPHA,
style: LineStyle::Solid,
id: None,
}
Expand Down Expand Up @@ -487,6 +489,13 @@ impl Line {
self
}

/// Set the fill area's alpha channel. Default is `0.05`.
#[inline]
pub fn fill_alpha(mut self, alpha: impl Into<f32>) -> Self {
self.fill_alpha = alpha.into();
self
}

/// Set the line's style. Default is `LineStyle::Solid`.
#[inline]
pub fn style(mut self, style: LineStyle) -> Self {
Expand Down Expand Up @@ -545,7 +554,7 @@ impl PlotItem for Line {
fill = None;
}
if let Some(y_reference) = fill {
let mut fill_alpha = DEFAULT_FILL_ALPHA;
let mut fill_alpha = self.fill_alpha;
if *highlight {
fill_alpha = (2.0 * fill_alpha).at_most(1.0);
}
Expand Down