layer_shika_domain/value_objects/
anchor_strategy.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
3pub enum AnchorStrategy {
4 #[default]
6 CenterBottom,
7 CenterTop,
9 LeftBottom,
11 RightBottom,
13 LeftTop,
15 RightTop,
17 Cursor,
19}
20
21impl AnchorStrategy {
22 #[must_use]
23 pub const fn calculate_position(
24 self,
25 anchor_x: f64,
26 anchor_y: f64,
27 anchor_w: f64,
28 anchor_h: f64,
29 popup_w: f64,
30 popup_h: f64,
31 ) -> (f64, f64) {
32 match self {
33 Self::CenterBottom => {
34 let center_x = anchor_x + (anchor_w / 2.0);
35 let x = center_x - (popup_w / 2.0);
36 let y = anchor_y + anchor_h;
37 (x, y)
38 }
39 Self::CenterTop => {
40 let center_x = anchor_x + (anchor_w / 2.0);
41 let x = center_x - (popup_w / 2.0);
42 let y = anchor_y - popup_h;
43 (x, y)
44 }
45 Self::LeftBottom => (anchor_x, anchor_y + anchor_h),
46 Self::RightBottom => (anchor_x + anchor_w - popup_w, anchor_y + anchor_h),
47 Self::LeftTop => (anchor_x, anchor_y - popup_h),
48 Self::RightTop => (anchor_x + anchor_w - popup_w, anchor_y - popup_h),
49 Self::Cursor => (anchor_x, anchor_y),
50 }
51 }
52}