1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Use Margin instead of a,b,c,d

This commit is contained in:
Emil Ernerfeldt
2023-08-14 13:44:07 +02:00
parent 75617d5a15
commit 93c763be5d
2 changed files with 19 additions and 18 deletions

View File

@@ -338,6 +338,13 @@ pub struct Margin {
} }
impl Margin { impl Margin {
pub const ZERO: Self = Self {
left: 0.0,
right: 0.0,
top: 0.0,
bottom: 0.0,
};
#[inline] #[inline]
pub fn same(margin: f32) -> Self { pub fn same(margin: f32) -> Self {
Self { Self {

View File

@@ -748,9 +748,10 @@ impl Plot {
// Next we want to create this layout. // Next we want to create this layout.
// Incides are only examples. // Incides are only examples.
// //
// +-b-+---------x----------+ + // left right
// +---+---------x----------+ +
// | | x-Axis 3 | // | | x-Axis 3 |
// c +--------------------+ // | +--------------------+ top
// | | x-Axis 2 | // | | x-Axis 2 |
// +-+-+--------------------+-+-+ // +-+-+--------------------+-+-+
// |y|y| |y|y| // |y|y| |y|y|
@@ -762,26 +763,22 @@ impl Plot {
// |1|0| |2|3| // |1|0| |2|3|
// +-+-+--------------------+-+-+ // +-+-+--------------------+-+-+
// | x-Axis 0 | | // | x-Axis 0 | |
// +--------------------+ a // +--------------------+ | bottom
// | x-Axis 1 | | // | x-Axis 1 | |
// + +--------------------+-d-+ // + +--------------------+---+
// //
let mut plot_rect: Rect = { let mut plot_rect: Rect = {
// find dimensions of axis labels // Calcuclate the space needed for each axis labels.
// for a, b, c, d meanings see picture let mut margin = Margin::ZERO;
let mut a = 0.0;
let mut b = 0.0;
let mut c = 0.0;
let mut d = 0.0;
if show_axes.x { if show_axes.x {
for cfg in &x_axes { for cfg in &x_axes {
match cfg.placement { match cfg.placement {
axis::Placement::Default => { axis::Placement::Default => {
a += cfg.thickness(); margin.bottom += cfg.thickness();
} }
axis::Placement::Opposite => { axis::Placement::Opposite => {
c += cfg.thickness(); margin.top += cfg.thickness();
} }
} }
} }
@@ -790,20 +787,17 @@ impl Plot {
for cfg in &y_axes { for cfg in &y_axes {
match cfg.placement { match cfg.placement {
axis::Placement::Default => { axis::Placement::Default => {
b += cfg.thickness(); margin.left += cfg.thickness();
} }
axis::Placement::Opposite => { axis::Placement::Opposite => {
d += cfg.thickness(); margin.right += cfg.thickness();
} }
} }
} }
} }
// determine plot rectangle // determine plot rectangle
Rect { margin.shrink_rect(complete_rect)
min: complete_rect.min + Vec2::new(b, c),
max: complete_rect.max - Vec2::new(d, a),
}
}; };
let mut x_axis_widgets = Vec::<XAxisWidget>::new(); let mut x_axis_widgets = Vec::<XAxisWidget>::new();
let mut y_axis_widgets = Vec::<YAxisWidget>::new(); let mut y_axis_widgets = Vec::<YAxisWidget>::new();