| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
use egui::Ui; |
| 21 |
use quasi_router::layout::Arrangement; |
| 22 |
use quasi_router::{RegionKind, Screen, Slot}; |
| 23 |
|
| 24 |
use crate::{Pass, node}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
pub(crate) fn screen_regions(pass: &mut Pass<'_>, ui: &mut Ui, screen: &Screen) { |
| 37 |
let (leading, body, trailing) = split(screen); |
| 38 |
|
| 39 |
for slot in &leading { |
| 40 |
node::region(pass, ui, slot); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
if trailing.is_empty() { |
| 52 |
arranged(pass, ui, screen, &body); |
| 53 |
} else { |
| 54 |
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| { |
| 55 |
for slot in trailing.iter().rev() { |
| 56 |
node::region(pass, ui, slot); |
| 57 |
} |
| 58 |
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| { |
| 59 |
arranged(pass, ui, screen, &body); |
| 60 |
}); |
| 61 |
}); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
fn split(screen: &Screen) -> (Vec<&Slot>, Vec<&Slot>, Vec<&Slot>) { |
| 71 |
let first_body = screen |
| 72 |
.slots |
| 73 |
.iter() |
| 74 |
.position(|slot| !matches!(slot.kind, RegionKind::Band)); |
| 75 |
let Some(at) = first_body else { |
| 76 |
return (screen.slots.iter().collect(), Vec::new(), Vec::new()); |
| 77 |
}; |
| 78 |
let is_band = |slot: &&Slot| matches!(slot.kind, RegionKind::Band); |
| 79 |
( |
| 80 |
screen.slots[..at].iter().collect(), |
| 81 |
screen.slots[at..] |
| 82 |
.iter() |
| 83 |
.filter(|slot| !is_band(slot)) |
| 84 |
.collect(), |
| 85 |
screen.slots[at..].iter().filter(is_band).collect(), |
| 86 |
) |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
fn arranged(pass: &mut Pass<'_>, ui: &mut Ui, screen: &Screen, body: &[&Slot]) { |
| 91 |
match screen.arrangement { |
| 92 |
Arrangement::SidebarContent { share } => { |
| 93 |
let sidebar = body |
| 94 |
.iter() |
| 95 |
.position(|slot| matches!(slot.kind, RegionKind::Sidebar)); |
| 96 |
match sidebar { |
| 97 |
Some(at) => { |
| 98 |
let width = ui.available_width() * share_of(share); |
| 99 |
ui.horizontal_top(|ui| { |
| 100 |
ui.allocate_ui(egui::vec2(width, ui.available_height()), |ui| { |
| 101 |
scrolled(ui, body[at], pass); |
| 102 |
}); |
| 103 |
ui.vertical(|ui| { |
| 104 |
for (i, slot) in body.iter().enumerate() { |
| 105 |
if i != at { |
| 106 |
scrolled(ui, slot, pass); |
| 107 |
} |
| 108 |
} |
| 109 |
}); |
| 110 |
}); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
None => { |
| 117 |
for slot in body { |
| 118 |
scrolled(ui, slot, pass); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
Arrangement::ListDetail { share, tabbed } => { |
| 125 |
if tabbed { |
| 126 |
|
| 127 |
|
| 128 |
if let Some(slot) = body.first() { |
| 129 |
scrolled(ui, slot, pass); |
| 130 |
} |
| 131 |
} else { |
| 132 |
let left = ui.available_width() * share_of(share); |
| 133 |
ui.horizontal_top(|ui| { |
| 134 |
if let Some(slot) = body.first() { |
| 135 |
ui.allocate_ui(egui::vec2(left, ui.available_height()), |ui| { |
| 136 |
scrolled(ui, slot, pass); |
| 137 |
}); |
| 138 |
} |
| 139 |
ui.vertical(|ui| { |
| 140 |
for slot in body.iter().skip(1) { |
| 141 |
scrolled(ui, slot, pass); |
| 142 |
} |
| 143 |
}); |
| 144 |
}); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
Arrangement::Single => { |
| 151 |
for slot in body { |
| 152 |
scrolled(ui, slot, pass); |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
fn scrolled(ui: &mut Ui, slot: &Slot, pass: &mut Pass<'_>) { |
| 164 |
egui::ScrollArea::vertical() |
| 165 |
.id_salt(&slot.id) |
| 166 |
.show(ui, |ui| { |
| 167 |
node::region(pass, ui, slot); |
| 168 |
}); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
fn share_of(share: quasi_router::layout::Share) -> f32 { |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
const SCALE: u16 = 1000; |
| 177 |
f32::from(share.of(SCALE)) / f32::from(SCALE) |
| 178 |
} |
| 179 |
|