xref: /StarryEngine/starry_toolkit/src/traits/transform.rs (revision 6f3c183754d5940a0fbae5cb2a8bc423f3ed1beb)
1*6f3c1837SR0ronoa use crate::widgets::{HorizontalPlacement, VerticalPlacement, Widget};
2*6f3c1837SR0ronoa 
3*6f3c1837SR0ronoa pub trait Transform: Sized + Widget {
4*6f3c1837SR0ronoa     fn reposition(&self, x: i32, y: i32) -> &Self {
5*6f3c1837SR0ronoa         let mut position = self.local_position().get();
6*6f3c1837SR0ronoa         let mut rect = self.rect().get();
7*6f3c1837SR0ronoa         position.x = x;
8*6f3c1837SR0ronoa         position.y = y;
9*6f3c1837SR0ronoa         rect.x = x;
10*6f3c1837SR0ronoa         rect.y = y;
11*6f3c1837SR0ronoa         self.local_position().set(position);
12*6f3c1837SR0ronoa         self.rect().set(rect);
13*6f3c1837SR0ronoa         self.arrange();
14*6f3c1837SR0ronoa         self
15*6f3c1837SR0ronoa     }
16*6f3c1837SR0ronoa 
17*6f3c1837SR0ronoa     fn resize(&self, width: u32, height: u32) -> &Self {
18*6f3c1837SR0ronoa         let mut rect = self.rect().get();
19*6f3c1837SR0ronoa         rect.width = width;
20*6f3c1837SR0ronoa         rect.height = height;
21*6f3c1837SR0ronoa         self.rect().set(rect);
22*6f3c1837SR0ronoa         self.arrange();
23*6f3c1837SR0ronoa         self
24*6f3c1837SR0ronoa     }
25*6f3c1837SR0ronoa 
26*6f3c1837SR0ronoa     fn placement(
27*6f3c1837SR0ronoa         &self,
28*6f3c1837SR0ronoa         vertical_placement: VerticalPlacement,
29*6f3c1837SR0ronoa         horizontal_placement: HorizontalPlacement,
30*6f3c1837SR0ronoa     ) -> &Self {
31*6f3c1837SR0ronoa         self.vertical_placement().set(vertical_placement);
32*6f3c1837SR0ronoa         self.horizontal_placement().set(horizontal_placement);
33*6f3c1837SR0ronoa         self.arrange();
34*6f3c1837SR0ronoa         self
35*6f3c1837SR0ronoa     }
36*6f3c1837SR0ronoa }
37