cranpose_ui_layout/
layout_direction.rs1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
5pub enum LayoutDirection {
6 #[default]
8 Ltr,
9 Rtl,
11}
12
13impl LayoutDirection {
14 pub fn place_x(self, start: f32, width: f32, item_width: f32) -> f32 {
16 if self.is_rtl() {
17 width - start - item_width
18 } else {
19 start
20 }
21 }
22 pub fn is_rtl(self) -> bool {
24 matches!(self, Self::Rtl)
25 }
26
27 pub fn reversed(self) -> Self {
29 match self {
30 Self::Ltr => Self::Rtl,
31 Self::Rtl => Self::Ltr,
32 }
33 }
34
35 pub fn resolve(self, start: f32, end: f32) -> (f32, f32) {
37 match self {
38 Self::Ltr => (start, end),
39 Self::Rtl => (end, start),
40 }
41 }
42}