1use egui::{pos2, Pos2, Vec2};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Anchor {
6 TopRight,
8 TopLeft,
10 BottomRight,
12 BottomLeft,
14}
15
16impl Anchor {
17 #[inline]
18 pub(crate) const fn anim_side(&self) -> f32 {
19 match self {
20 Self::TopRight | Self::BottomRight => 1.,
21 Self::TopLeft | Self::BottomLeft => -1.,
22 }
23 }
24}
25
26impl Anchor {
27 pub(crate) fn screen_corner(&self, sc: Pos2, margin: Vec2) -> Pos2 {
28 let mut out = match self {
29 Self::TopRight => pos2(sc.x, 0.),
30 Self::TopLeft => pos2(0., 0.),
31 Self::BottomRight => sc,
32 Self::BottomLeft => pos2(0., sc.y),
33 };
34 self.apply_margin(&mut out, margin);
35 out
36 }
37
38 pub(crate) fn apply_margin(&self, pos: &mut Pos2, margin: Vec2) {
39 match self {
40 Self::TopRight => {
41 pos.x -= margin.x;
42 pos.y += margin.y;
43 }
44 Self::TopLeft => {
45 pos.x += margin.x;
46 pos.y += margin.y;
47 }
48 Self::BottomRight => {
49 pos.x -= margin.x;
50 pos.y -= margin.y;
51 }
52 Self::BottomLeft => {
53 pos.x += margin.x;
54 pos.y -= margin.y;
55 }
56 }
57 }
58}