MCPcopy Create free account
hub / github.com/emilk/egui_plot / axis_widgets

Function axis_widgets

egui_plot/src/plot.rs:1737–1855  ·  view source on GitHub ↗

Returns the rect left after adding axes.

(
    mem: Option<&PlotMemory>,
    show_axes: impl Into<Vec2b>,
    complete_rect: Rect,
    [x_axes, y_axes]: [&'a [AxisHints<'a>]; 2],
)

Source from the content-addressed store, hash-verified

1735
1736/// Returns the rect left after adding axes.
1737fn axis_widgets<'a>(
1738 mem: Option<&PlotMemory>,
1739 show_axes: impl Into<Vec2b>,
1740 complete_rect: Rect,
1741 [x_axes, y_axes]: [&'a [AxisHints<'a>]; 2],
1742) -> ([Vec<AxisWidget<'a>>; 2], Rect) {
1743 // Next we want to create this layout.
1744 // Indices are only examples.
1745 //
1746 // left right
1747 // +---+---------x----------+ +
1748 // | | X-axis 3 |
1749 // | +--------------------+ top
1750 // | | X-axis 2 |
1751 // +-+-+--------------------+-+-+
1752 // |y|y| |y|y|
1753 // |-|-| |-|-|
1754 // |A|A| |A|A|
1755 // y|x|x| Plot Window |x|x|
1756 // |i|i| |i|i|
1757 // |s|s| |s|s|
1758 // |1|0| |2|3|
1759 // +-+-+--------------------+-+-+
1760 // | X-axis 0 | |
1761 // +--------------------+ | bottom
1762 // | X-axis 1 | |
1763 // + +--------------------+---+
1764 //
1765 let show_axes = show_axes.into();
1766
1767 let mut x_axis_widgets = Vec::<AxisWidget<'_>>::new();
1768 let mut y_axis_widgets = Vec::<AxisWidget<'_>>::new();
1769
1770 // Will shrink as we add more axes.
1771 let mut rect_left = complete_rect;
1772
1773 if show_axes.x {
1774 // We will fix this later, once we know how much space the y axes take up.
1775 let initial_x_range = complete_rect.x_range();
1776
1777 for (i, cfg) in x_axes.iter().enumerate().rev() {
1778 let mut height = cfg.min_thickness;
1779 if let Some(mem) = mem {
1780 // If the labels took up too much space the previous frame, give them more space
1781 // now:
1782 height = height.max(mem.x_axis_thickness.get(&i).copied().unwrap_or_default());
1783 }
1784
1785 let rect = match VPlacement::from(cfg.placement) {
1786 VPlacement::Bottom => {
1787 let bottom = rect_left.bottom();
1788 *rect_left.bottom_mut() -= height;
1789 let top = rect_left.bottom();
1790 Rect::from_x_y_ranges(initial_x_range, top..=bottom)
1791 }
1792 VPlacement::Top => {
1793 let top = rect_left.top();
1794 *rect_left.top_mut() += height;

Callers 1

show_dynMethod · 0.85

Calls 3

maxMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected