| 70 | } |
| 71 | |
| 72 | pub fn generate_layout( |
| 73 | tree: &mut Dwindle, |
| 74 | lastwin: &Rc<RefCell<StrataWindow>>, |
| 75 | lastgeo: Rectangle<i32, Logical>, |
| 76 | split: HorizontalOrVertical, |
| 77 | ratio: f32, |
| 78 | output: Size<i32, Physical>, |
| 79 | gaps: (i32, i32), |
| 80 | ) { |
| 81 | let size = match split { |
| 82 | HorizontalOrVertical::Horizontal => { |
| 83 | Size::from(((lastgeo.size.w as f32 * ratio) as i32, lastgeo.size.h)) |
| 84 | } |
| 85 | HorizontalOrVertical::Vertical => { |
| 86 | Size::from((lastgeo.size.w, (lastgeo.size.h as f32 * ratio) as i32)) |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | let loc: Point<i32, Logical> = match split { |
| 91 | HorizontalOrVertical::Horizontal => Point::from((lastgeo.loc.x, output.h - size.h)), |
| 92 | HorizontalOrVertical::Vertical => Point::from((output.w - size.w, lastgeo.loc.y)), |
| 93 | }; |
| 94 | |
| 95 | let rec_with_gaps = Rectangle { |
| 96 | size: Size::from((size.w - (gaps.1 * 2), (size.h - (gaps.1 * 2)))), |
| 97 | loc: Point::from((loc.x + gaps.1, loc.y + gaps.1)), |
| 98 | }; |
| 99 | |
| 100 | lastwin.borrow_mut().rec = rec_with_gaps; |
| 101 | |
| 102 | let loc = match split { |
| 103 | HorizontalOrVertical::Horizontal => Point::from((output.w - size.w, lastgeo.loc.y)), |
| 104 | HorizontalOrVertical::Vertical => Point::from((lastgeo.loc.x, output.h - size.h)), |
| 105 | }; |
| 106 | |
| 107 | let rec = Rectangle { size, loc }; |
| 108 | let rec_with_gaps = Rectangle { |
| 109 | size: Size::from((size.w - (gaps.1 * 2), (size.h - (gaps.1 * 2)))), |
| 110 | loc: Point::from((loc.x + gaps.1, loc.y + gaps.1)), |
| 111 | }; |
| 112 | match tree { |
| 113 | Dwindle::Empty => {} |
| 114 | Dwindle::Window(w) => w.borrow_mut().rec = rec_with_gaps, |
| 115 | Dwindle::Split { split, ratio, left, right } => { |
| 116 | if let Dwindle::Window(w) = left.as_mut() { |
| 117 | w.borrow_mut().rec = rec; |
| 118 | generate_layout(right.as_mut(), w, rec, *split, *ratio, output, gaps) |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |