swoop_ui/position.rs
1use bevy_ui::prelude::*;
2
3use crate::View;
4
5/// A trait that provides convenient absolute positioning methods for views.
6pub trait PositionView: View {
7 /// Sets the top offset of the view in absolute positioning mode.
8 ///
9 /// # Arguments
10 /// * `y` - Vertical distance from the top edge of the parent container.
11 fn top(mut self, y: Val) -> Self {
12 let node = self.node_node();
13 node.position_type = PositionType::Absolute;
14 node.top = y;
15 self
16 }
17
18 /// Sets the left offset of the view in absolute positioning mode.
19 ///
20 /// # Arguments
21 /// * `x` - Horizontal distance from the left edge of the parent container.
22 fn left(mut self, x: Val) -> Self {
23 let node = self.node_node();
24 node.position_type = PositionType::Absolute;
25 node.left = x;
26 self
27 }
28
29 /// Sets the right offset of the view in absolute positioning mode.
30 ///
31 /// # Arguments
32 /// * `x` - Distance from the right edge of the parent container.
33 fn right(mut self, x: Val) -> Self {
34 let node = self.node_node();
35 node.position_type = PositionType::Absolute;
36 node.right = x;
37 self
38 }
39
40 /// Sets the bottom offset of the view in absolute positioning mode.
41 ///
42 /// # Arguments
43 /// * `y` - Distance from the bottom edge of the parent container.
44 fn bottom(mut self, y: Val) -> Self {
45 let node = self.node_node();
46 node.position_type = PositionType::Absolute;
47 node.bottom = y;
48 self
49 }
50
51 /// Sets both the left and top offsets of the view in absolute positioning mode.
52 ///
53 /// # Arguments
54 /// * `x` - Horizontal distance from the left edge.
55 /// * `y` - Vertical distance from the top edge.
56 fn position(mut self, x: Val, y: Val) -> Self {
57 let node = self.node_node();
58 node.position_type = PositionType::Absolute;
59 node.left = x;
60 node.top = y;
61 self
62 }
63}