Use "in front" and "behind" instead of "below" and "above"

This commit is contained in:
Emil Ernerfeldt 2023-01-26 16:05:52 +01:00
parent cb051425ff
commit ce2d37d5d9
3 changed files with 42 additions and 32 deletions

View file

@ -308,10 +308,11 @@ impl SidePanel {
};
let resize_x = side.opposite().side_x(rect);
let resize_x = ui.painter().round_to_pixel(resize_x);
ui.painter()
.clone()
.with_z(layers::ZOrder::ABOVE_ALL)
.vline(resize_x, rect.y_range(), stroke);
ui.painter().clone().with_z(layers::ZOrder::FRONT).vline(
resize_x,
rect.y_range(),
stroke,
);
}
inner_response
@ -759,10 +760,11 @@ impl TopBottomPanel {
};
let resize_y = side.opposite().side_y(rect);
let resize_y = ui.painter().round_to_pixel(resize_y);
ui.painter()
.clone()
.with_z(layers::ZOrder::ABOVE_ALL)
.hline(rect.x_range(), resize_y, stroke);
ui.painter().clone().with_z(layers::ZOrder::FRONT).hline(
rect.x_range(),
resize_y,
stroke,
);
}
inner_response

View file

@ -127,27 +127,32 @@ impl AreaLayerId {
pub struct ZOrder(pub i32);
impl ZOrder {
/// The default layer 0.
pub const BASE: ZOrder = ZOrder(0);
pub const ABOVE_ALL: ZOrder = ZOrder(i32::MAX);
pub const BELOW_ALL: ZOrder = ZOrder(i32::MIN);
/// In front of everything else.
pub const FRONT: ZOrder = ZOrder(i32::MAX);
/// Behind everything else.
pub const BACK: ZOrder = ZOrder(i32::MIN);
/// Directly above
pub fn above(self) -> Self {
self.above_by(1)
pub fn in_front(self) -> Self {
self.in_front_by(1)
}
/// Directly below
pub fn below(self) -> Self {
self.below_by(1)
/// Directly behind
pub fn behind(self) -> Self {
self.behind_by(1)
}
/// Above by the number of levels given
pub fn above_by(self, levels: i32) -> Self {
/// In front of by the number of levels given
pub fn in_front_by(self, levels: i32) -> Self {
Self(self.0.saturating_add(levels))
}
/// Below by the number of levels given
pub fn below_by(self, levels: i32) -> Self {
/// Behind by the number of levels given
pub fn behind_by(self, levels: i32) -> Self {
Self(self.0.saturating_sub(levels))
}
}
@ -175,6 +180,9 @@ impl std::ops::AddAssign<ZOffset> for ZOrder {
// ----------------------------------------------------------------------------
/// Offset within a [`ZOrder`].
///
/// * Positive: more in front of.
/// * Negative: more behind.
pub type ZOffset = i32;
// ----------------------------------------------------------------------------
@ -222,28 +230,28 @@ impl ZLayer {
Self::from_area_layer_z(self.area_layer, z)
}
/// Get the `ZLayer` directly above this one
/// Get the `ZLayer` directly in front of this one.
#[must_use]
pub fn above(self) -> Self {
self.with_z(self.z.above())
pub fn in_front(self) -> Self {
self.with_z(self.z.in_front())
}
/// Get the `ZLayer` above this one by `levels` levels
/// Get the `ZLayer` in front of this one by `levels` levels.
#[must_use]
pub fn above_by(self, levels: i32) -> Self {
self.with_z(self.z.above_by(levels))
pub fn in_front_by(self, levels: i32) -> Self {
self.with_z(self.z.in_front_by(levels))
}
/// Get the `ZLayer` directly below this one
/// Get the `ZLayer` directly behind this one.
#[must_use]
pub fn below(self) -> Self {
self.with_z(self.z.below())
pub fn behind(self) -> Self {
self.with_z(self.z.behind())
}
/// Get the `ZLayer` below this one by `levels` levels
/// Get the `ZLayer` behind this one by `levels` levels.
#[must_use]
pub fn below_by(self, levels: i32) -> Self {
self.with_z(self.z.below_by(levels))
pub fn behind_by(self, levels: i32) -> Self {
self.with_z(self.z.behind_by(levels))
}
/// `Id` of underlying area layer

View file

@ -72,7 +72,7 @@ impl eframe::App for MyApp {
}
let base = ZOrder::BASE;
let above = base.above();
let above = base.in_front();
draw_squares(ui, Vec2::new(0.0, 0.0), base, above);
draw_squares(ui, Vec2::new(100.0, 0.0), above, base);