1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Add #[inline] to all builder-pattern functions (#3557)

Better performance and maybe code size
This commit is contained in:
Emil Ernerfeldt
2023-11-16 13:50:05 +01:00
committed by GitHub
parent 4886c8c8c0
commit a243180600
32 changed files with 398 additions and 35 deletions

View File

@@ -132,6 +132,7 @@ impl AxisHints {
/// Specify axis label.
///
/// The default is 'x' for x-axes and 'y' for y-axes.
#[inline]
pub fn label(mut self, label: impl Into<WidgetText>) -> Self {
self.label = label.into();
self
@@ -140,6 +141,7 @@ impl AxisHints {
/// Specify maximum number of digits for ticks.
///
/// This is considered by the default tick formatter and affects the width of the y-axis
#[inline]
pub fn max_digits(mut self, digits: usize) -> Self {
self.digits = digits;
self
@@ -149,6 +151,7 @@ impl AxisHints {
///
/// For X-axis, use [`VPlacement`].
/// For Y-axis, use [`HPlacement`].
#[inline]
pub fn placement(mut self, placement: impl Into<Placement>) -> Self {
self.placement = placement.into();
self

View File

@@ -55,18 +55,21 @@ impl Bar {
/// Name of this bar chart element.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
/// Add a custom stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Add a custom fill color.
#[inline]
pub fn fill(mut self, color: impl Into<Color32>) -> Self {
self.fill = color.into();
self
@@ -75,24 +78,28 @@ impl Bar {
/// Offset the base of the bar.
/// This offset is on the Y axis for a vertical bar
/// and on the X axis for a horizontal bar.
#[inline]
pub fn base_offset(mut self, offset: f64) -> Self {
self.base_offset = Some(offset);
self
}
/// Set the bar width.
#[inline]
pub fn width(mut self, width: f64) -> Self {
self.bar_width = width;
self
}
/// Set orientation of the element as vertical. Argument axis is X.
#[inline]
pub fn vertical(mut self) -> Self {
self.orientation = Orientation::Vertical;
self
}
/// Set orientation of the element as horizontal. Argument axis is Y.
#[inline]
pub fn horizontal(mut self) -> Self {
self.orientation = Orientation::Horizontal;
self

View File

@@ -94,42 +94,49 @@ impl BoxElem {
/// Name of this box element.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
/// Add a custom stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Add a custom fill color.
#[inline]
pub fn fill(mut self, color: impl Into<Color32>) -> Self {
self.fill = color.into();
self
}
/// Set the box width.
#[inline]
pub fn box_width(mut self, width: f64) -> Self {
self.box_width = width;
self
}
/// Set the whisker width.
#[inline]
pub fn whisker_width(mut self, width: f64) -> Self {
self.whisker_width = width;
self
}
/// Set orientation of the element as vertical. Argument axis is X.
#[inline]
pub fn vertical(mut self) -> Self {
self.orientation = Orientation::Vertical;
self
}
/// Set orientation of the element as horizontal. Argument axis is Y.
#[inline]
pub fn horizontal(mut self) -> Self {
self.orientation = Orientation::Horizontal;
self

View File

@@ -134,30 +134,35 @@ impl HLine {
}
/// Highlight this line in the plot by scaling up the line.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Add a stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
#[inline]
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Set the line's style. Default is `LineStyle::Solid`.
#[inline]
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
self
@@ -170,6 +175,7 @@ impl HLine {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -250,30 +256,35 @@ impl VLine {
}
/// Highlight this line in the plot by scaling up the line.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Add a stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
#[inline]
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Set the line's style. Default is `LineStyle::Solid`.
#[inline]
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
self
@@ -286,6 +297,7 @@ impl VLine {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -367,36 +379,42 @@ impl Line {
}
/// Highlight this line in the plot by scaling up the line.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Add a stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
#[inline]
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Fill the area between this line and a given horizontal reference line.
#[inline]
pub fn fill(mut self, y_reference: impl Into<f32>) -> Self {
self.fill = Some(y_reference.into());
self
}
/// Set the line's style. Default is `LineStyle::Solid`.
#[inline]
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
self
@@ -409,6 +427,7 @@ impl Line {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -535,18 +554,21 @@ impl Polygon {
/// Highlight this polygon in the plot by scaling up the stroke and reducing the fill
/// transparency.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Add a custom stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Set the stroke width.
#[inline]
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
@@ -554,23 +576,27 @@ impl Polygon {
#[deprecated = "Use `fill_color`."]
#[allow(unused, clippy::needless_pass_by_value)]
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self
}
#[deprecated = "Use `fill_color`."]
#[allow(unused, clippy::needless_pass_by_value)]
#[inline]
pub fn fill_alpha(mut self, _alpha: impl Into<f32>) -> Self {
self
}
/// Fill color. Defaults to the stroke color with added transparency.
#[inline]
pub fn fill_color(mut self, color: impl Into<Color32>) -> Self {
self.fill_color = Some(color.into());
self
}
/// Set the outline's style. Default is `LineStyle::Solid`.
#[inline]
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
self
@@ -583,6 +609,7 @@ impl Polygon {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -667,18 +694,21 @@ impl Text {
}
/// Highlight this text in the plot by drawing a rectangle around it.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Text color.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into();
self
}
/// Anchor position of the text. Default is `Align2::CENTER_CENTER`.
#[inline]
pub fn anchor(mut self, anchor: Align2) -> Self {
self.anchor = anchor;
self
@@ -691,6 +721,7 @@ impl Text {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -796,36 +827,42 @@ impl Points {
}
/// Set the shape of the markers.
#[inline]
pub fn shape(mut self, shape: MarkerShape) -> Self {
self.shape = shape;
self
}
/// Highlight these points in the plot by scaling up their markers.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Set the marker's color.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into();
self
}
/// Whether to fill the marker.
#[inline]
pub fn filled(mut self, filled: bool) -> Self {
self.filled = filled;
self
}
/// Whether to add stems between the markers and a horizontal reference line.
#[inline]
pub fn stems(mut self, y_reference: impl Into<f32>) -> Self {
self.stems = Some(y_reference.into());
self
}
/// Set the maximum extent of the marker around its position.
#[inline]
pub fn radius(mut self, radius: impl Into<f32>) -> Self {
self.radius = radius.into();
self
@@ -838,6 +875,7 @@ impl Points {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -1025,18 +1063,21 @@ impl Arrows {
}
/// Highlight these arrows in the plot.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Set the length of the arrow tips
#[inline]
pub fn tip_length(mut self, tip_length: f32) -> Self {
self.tip_length = Some(tip_length);
self
}
/// Set the arrows' color.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into();
self
@@ -1049,6 +1090,7 @@ impl Arrows {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -1165,24 +1207,28 @@ impl PlotImage {
}
/// Highlight this image in the plot.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
}
/// Select UV range. Default is (0,0) in top-left, (1,1) bottom right.
#[inline]
pub fn uv(mut self, uv: impl Into<Rect>) -> Self {
self.uv = uv.into();
self
}
/// A solid color to put behind the image. Useful for transparent images.
#[inline]
pub fn bg_fill(mut self, bg_fill: impl Into<Color32>) -> Self {
self.bg_fill = bg_fill.into();
self
}
/// Multiply image color with this. Default is WHITE (no tint).
#[inline]
pub fn tint(mut self, tint: impl Into<Color32>) -> Self {
self.tint = tint.into();
self
@@ -1195,12 +1241,14 @@ impl PlotImage {
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
/// Rotate the image counter-clockwise around its center by an angle in radians.
#[inline]
pub fn rotate(mut self, angle: f64) -> Self {
self.rotation = angle;
self
@@ -1334,6 +1382,7 @@ impl BarChart {
/// This is the color that shows up in the legend.
/// It can be overridden at the bar level (see [[`Bar`]]).
/// Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
let plot_color = color.into();
self.default_color = plot_color;
@@ -1351,6 +1400,7 @@ impl BarChart {
/// This name will show up in the plot legend, if legends are turned on. Multiple charts may
/// share the same name, in which case they will also share an entry in the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -1358,6 +1408,7 @@ impl BarChart {
/// Set all elements to be in a vertical orientation.
/// Argument axis will be X and bar values will be on the Y axis.
#[inline]
pub fn vertical(mut self) -> Self {
for b in &mut self.bars {
b.orientation = Orientation::Vertical;
@@ -1367,6 +1418,7 @@ impl BarChart {
/// Set all elements to be in a horizontal orientation.
/// Argument axis will be Y and bar values will be on the X axis.
#[inline]
pub fn horizontal(mut self) -> Self {
for b in &mut self.bars {
b.orientation = Orientation::Horizontal;
@@ -1375,6 +1427,7 @@ impl BarChart {
}
/// Set the width (thickness) of all its elements.
#[inline]
pub fn width(mut self, width: f64) -> Self {
for b in &mut self.bars {
b.bar_width = width;
@@ -1383,6 +1436,7 @@ impl BarChart {
}
/// Highlight all plot elements.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self
@@ -1390,6 +1444,7 @@ impl BarChart {
/// Add a custom way to format an element.
/// Can be used to display a set number of decimals or custom labels.
#[inline]
pub fn element_formatter(mut self, formatter: Box<dyn Fn(&Bar, &BarChart) -> String>) -> Self {
self.element_formatter = Some(formatter);
self
@@ -1398,6 +1453,7 @@ impl BarChart {
/// Stacks the bars on top of another chart.
/// Positive values are stacked on top of other positive values.
/// Negative values are stacked below other negative values.
#[inline]
pub fn stack_on(mut self, others: &[&BarChart]) -> Self {
for (index, bar) in self.bars.iter_mut().enumerate() {
let new_base_offset = if bar.value.is_sign_positive() {
@@ -1506,6 +1562,7 @@ impl BoxPlot {
/// This is the color that shows up in the legend.
/// It can be overridden at the element level (see [`BoxElem`]).
/// Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[inline]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
let plot_color = color.into();
self.default_color = plot_color;
@@ -1525,6 +1582,7 @@ impl BoxPlot {
/// This name will show up in the plot legend, if legends are turned on. Multiple series may
/// share the same name, in which case they will also share an entry in the legend.
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
@@ -1532,6 +1590,7 @@ impl BoxPlot {
/// Set all elements to be in a vertical orientation.
/// Argument axis will be X and values will be on the Y axis.
#[inline]
pub fn vertical(mut self) -> Self {
for box_elem in &mut self.boxes {
box_elem.orientation = Orientation::Vertical;
@@ -1541,6 +1600,7 @@ impl BoxPlot {
/// Set all elements to be in a horizontal orientation.
/// Argument axis will be Y and values will be on the X axis.
#[inline]
pub fn horizontal(mut self) -> Self {
for box_elem in &mut self.boxes {
box_elem.orientation = Orientation::Horizontal;
@@ -1549,6 +1609,7 @@ impl BoxPlot {
}
/// Highlight all plot elements.
#[inline]
pub fn highlight(mut self, highlight: bool) -> Self {
self.highlight = highlight;
self

View File

@@ -46,18 +46,21 @@ impl Default for Legend {
impl Legend {
/// Which text style to use for the legend. Default: `TextStyle::Body`.
#[inline]
pub fn text_style(mut self, style: TextStyle) -> Self {
self.text_style = style;
self
}
/// The alpha of the legend background. Default: `0.75`.
#[inline]
pub fn background_alpha(mut self, alpha: f32) -> Self {
self.background_alpha = alpha;
self
}
/// In which corner to place the legend. Default: `Corner::RightTop`.
#[inline]
pub fn position(mut self, corner: Corner) -> Self {
self.position = corner;
self

View File

@@ -260,6 +260,7 @@ impl Plot {
/// For instance, it can be useful to set this to `1.0` for when the two axes show the same
/// unit.
/// By default the plot window's aspect ratio is used.
#[inline]
pub fn data_aspect(mut self, data_aspect: f32) -> Self {
self.data_aspect = Some(data_aspect);
self
@@ -267,6 +268,7 @@ impl Plot {
/// width / height ratio of the plot region.
/// By default no fixed aspect ratio is set (and width/height will fill the ui it is in).
#[inline]
pub fn view_aspect(mut self, view_aspect: f32) -> Self {
self.view_aspect = Some(view_aspect);
self
@@ -274,6 +276,7 @@ impl Plot {
/// Width of plot. By default a plot will fill the ui it is in.
/// If you set [`Self::view_aspect`], the width can be calculated from the height.
#[inline]
pub fn width(mut self, width: f32) -> Self {
self.min_size.x = width;
self.width = Some(width);
@@ -282,6 +285,7 @@ impl Plot {
/// Height of plot. By default a plot will fill the ui it is in.
/// If you set [`Self::view_aspect`], the height can be calculated from the width.
#[inline]
pub fn height(mut self, height: f32) -> Self {
self.min_size.y = height;
self.height = Some(height);
@@ -289,30 +293,35 @@ impl Plot {
}
/// Minimum size of the plot view.
#[inline]
pub fn min_size(mut self, min_size: Vec2) -> Self {
self.min_size = min_size;
self
}
/// Show the x-value (e.g. when hovering). Default: `true`.
#[inline]
pub fn show_x(mut self, show_x: bool) -> Self {
self.show_x = show_x;
self
}
/// Show the y-value (e.g. when hovering). Default: `true`.
#[inline]
pub fn show_y(mut self, show_y: bool) -> Self {
self.show_y = show_y;
self
}
/// Always keep the X-axis centered. Default: `false`.
#[inline]
pub fn center_x_axis(mut self, on: bool) -> Self {
self.center_axis.x = on;
self
}
/// Always keep the Y-axis centered. Default: `false`.
#[inline]
pub fn center_y_axis(mut self, on: bool) -> Self {
self.center_axis.y = on;
self
@@ -321,6 +330,7 @@ impl Plot {
/// Whether to allow zooming in the plot. Default: `true`.
///
/// Note: Allowing zoom in one axis but not the other may lead to unexpected results if used in combination with `data_aspect`.
#[inline]
pub fn allow_zoom<T>(mut self, on: T) -> Self
where
T: Into<Vec2b>,
@@ -330,6 +340,7 @@ impl Plot {
}
/// Whether to allow scrolling in the plot. Default: `true`.
#[inline]
pub fn allow_scroll(mut self, on: bool) -> Self {
self.allow_scroll = on;
self
@@ -337,6 +348,7 @@ impl Plot {
/// Whether to allow double clicking to reset the view.
/// Default: `true`.
#[inline]
pub fn allow_double_click_reset(mut self, on: bool) -> Self {
self.allow_double_click_reset = on;
self
@@ -345,6 +357,7 @@ impl Plot {
/// Set the side margin as a fraction of the plot size. Only used for auto bounds.
///
/// For instance, a value of `0.1` will add 10% space on both sides.
#[inline]
pub fn set_margin_fraction(mut self, margin_fraction: Vec2) -> Self {
self.margin_fraction = margin_fraction;
self
@@ -353,18 +366,21 @@ impl Plot {
/// Whether to allow zooming in the plot by dragging out a box with the secondary mouse button.
///
/// Default: `true`.
#[inline]
pub fn allow_boxed_zoom(mut self, on: bool) -> Self {
self.allow_boxed_zoom = on;
self
}
/// Config the button pointer to use for boxed zooming. Default: [`Secondary`](PointerButton::Secondary)
#[inline]
pub fn boxed_zoom_pointer_button(mut self, boxed_zoom_pointer_button: PointerButton) -> Self {
self.boxed_zoom_pointer_button = boxed_zoom_pointer_button;
self
}
/// Whether to allow dragging in the plot to move the bounds. Default: `true`.
#[inline]
pub fn allow_drag<T>(mut self, on: T) -> Self
where
T: Into<Vec2b>,
@@ -442,6 +458,7 @@ impl Plot {
/// ```
///
/// There are helpers for common cases, see [`log_grid_spacer`] and [`uniform_grid_spacer`].
#[inline]
pub fn x_grid_spacer(mut self, spacer: impl Fn(GridInput) -> Vec<GridMark> + 'static) -> Self {
self.grid_spacers[0] = Box::new(spacer);
self
@@ -450,6 +467,7 @@ impl Plot {
/// Default is a log-10 grid, i.e. every plot unit is divided into 10 other units.
///
/// See [`Self::x_grid_spacer`] for explanation.
#[inline]
pub fn y_grid_spacer(mut self, spacer: impl Fn(GridInput) -> Vec<GridMark> + 'static) -> Self {
self.grid_spacers[1] = Box::new(spacer);
self
@@ -458,6 +476,7 @@ impl Plot {
/// Clamp the grid to only be visible at the range of data where we have values.
///
/// Default: `false`.
#[inline]
pub fn clamp_grid(mut self, clamp_grid: bool) -> Self {
self.clamp_grid = clamp_grid;
self
@@ -465,6 +484,7 @@ impl Plot {
/// Expand bounds to include the given x value.
/// For instance, to always show the y axis, call `plot.include_x(0.0)`.
#[inline]
pub fn include_x(mut self, x: impl Into<f64>) -> Self {
self.min_auto_bounds.extend_with_x(x.into());
self
@@ -472,24 +492,28 @@ impl Plot {
/// Expand bounds to include the given y value.
/// For instance, to always show the x axis, call `plot.include_y(0.0)`.
#[inline]
pub fn include_y(mut self, y: impl Into<f64>) -> Self {
self.min_auto_bounds.extend_with_y(y.into());
self
}
/// Expand bounds to fit all items across the x axis, including values given by `include_x`.
#[inline]
pub fn auto_bounds_x(mut self) -> Self {
self.auto_bounds.x = true;
self
}
/// Expand bounds to fit all items across the y axis, including values given by `include_y`.
#[inline]
pub fn auto_bounds_y(mut self) -> Self {
self.auto_bounds.y = true;
self
}
/// Show a legend including all named items.
#[inline]
pub fn legend(mut self, legend: Legend) -> Self {
self.legend_config = Some(legend);
self
@@ -499,6 +523,7 @@ impl Plot {
///
/// Can be useful to disable if the plot is overlaid over existing content.
/// Default: `true`.
#[inline]
pub fn show_background(mut self, show: bool) -> Self {
self.show_background = show;
self
@@ -507,6 +532,7 @@ impl Plot {
/// Show axis labels and grid tick values on the side of the plot.
///
/// Default: `true`.
#[inline]
pub fn show_axes(mut self, show: impl Into<Vec2b>) -> Self {
self.show_axes = show.into();
self
@@ -515,6 +541,7 @@ impl Plot {
/// Show a grid overlay on the plot.
///
/// Default: `true`.
#[inline]
pub fn show_grid(mut self, show: impl Into<Vec2b>) -> Self {
self.show_grid = show.into();
self
@@ -522,6 +549,7 @@ impl Plot {
/// Add this plot to an axis link group so that this plot will share the bounds with other plots in the
/// same group. A plot cannot belong to more than one axis group.
#[inline]
pub fn link_axis(mut self, group_id: impl Into<Id>, link_x: bool, link_y: bool) -> Self {
self.linked_axes = Some((
group_id.into(),
@@ -535,6 +563,7 @@ impl Plot {
/// Add this plot to a cursor link group so that this plot will share the cursor position with other plots
/// in the same group. A plot cannot belong to more than one cursor group.
#[inline]
pub fn link_cursor(mut self, group_id: impl Into<Id>, link_x: bool, link_y: bool) -> Self {
self.linked_cursors = Some((
group_id.into(),
@@ -548,12 +577,14 @@ impl Plot {
/// Round grid positions to full pixels to avoid aliasing. Improves plot appearance but might have an
/// undesired effect when shifting the plot bounds. Enabled by default.
#[inline]
pub fn sharp_grid_lines(mut self, enabled: bool) -> Self {
self.sharp_grid_lines = enabled;
self
}
/// Resets the plot.
#[inline]
pub fn reset(mut self) -> Self {
self.reset = true;
self
@@ -562,6 +593,7 @@ impl Plot {
/// Set the x axis label of the main X-axis.
///
/// Default: no label.
#[inline]
pub fn x_axis_label(mut self, label: impl Into<WidgetText>) -> Self {
if let Some(main) = self.x_axes.first_mut() {
main.label = label.into();
@@ -572,6 +604,7 @@ impl Plot {
/// Set the y axis label of the main Y-axis.
///
/// Default: no label.
#[inline]
pub fn y_axis_label(mut self, label: impl Into<WidgetText>) -> Self {
if let Some(main) = self.y_axes.first_mut() {
main.label = label.into();
@@ -580,6 +613,7 @@ impl Plot {
}
/// Set the position of the main X-axis.
#[inline]
pub fn x_axis_position(mut self, placement: axis::VPlacement) -> Self {
if let Some(main) = self.x_axes.first_mut() {
main.placement = placement.into();
@@ -588,6 +622,7 @@ impl Plot {
}
/// Set the position of the main Y-axis.
#[inline]
pub fn y_axis_position(mut self, placement: axis::HPlacement) -> Self {
if let Some(main) = self.y_axes.first_mut() {
main.placement = placement.into();
@@ -632,6 +667,7 @@ impl Plot {
/// The default is 5 digits.
///
/// > Todo: This is experimental. Changing the font size might break this.
#[inline]
pub fn y_axis_width(mut self, digits: usize) -> Self {
if let Some(main) = self.y_axes.first_mut() {
main.digits = digits;
@@ -642,6 +678,7 @@ impl Plot {
/// Set custom configuration for X-axis
///
/// More than one axis may be specified. The first specified axis is considered the main axis.
#[inline]
pub fn custom_x_axes(mut self, hints: Vec<AxisHints>) -> Self {
self.x_axes = hints;
self
@@ -650,6 +687,7 @@ impl Plot {
/// Set custom configuration for left Y-axis
///
/// More than one axis may be specified. The first specified axis is considered the main axis.
#[inline]
pub fn custom_y_axes(mut self, hints: Vec<AxisHints>) -> Self {
self.y_axes = hints;
self