| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use egui::Ui; |
| 25 |
use quasi_router::layout::Arrangement; |
| 26 |
use quasi_router::{RegionKind, Screen, Slot}; |
| 27 |
|
| 28 |
use crate::{Pass, node}; |
| 29 |
|
| 30 |
|
| 31 |
pub(crate) fn screen_regions(pass: &mut Pass<'_>, ui: &mut Ui, screen: &Screen) { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
for slot in screen |
| 36 |
.slots |
| 37 |
.iter() |
| 38 |
.filter(|slot| matches!(slot.kind, RegionKind::Band)) |
| 39 |
{ |
| 40 |
node::region(pass, ui, slot); |
| 41 |
} |
| 42 |
|
| 43 |
let body: Vec<&Slot> = screen |
| 44 |
.slots |
| 45 |
.iter() |
| 46 |
.filter(|slot| !matches!(slot.kind, RegionKind::Band)) |
| 47 |
.collect(); |
| 48 |
|
| 49 |
match screen.arrangement { |
| 50 |
Arrangement::SidebarContent { share } => { |
| 51 |
let sidebar = body |
| 52 |
.iter() |
| 53 |
.position(|slot| matches!(slot.kind, RegionKind::Sidebar)); |
| 54 |
match sidebar { |
| 55 |
Some(at) => { |
| 56 |
let width = ui.available_width() * share_of(share); |
| 57 |
ui.horizontal_top(|ui| { |
| 58 |
ui.allocate_ui(egui::vec2(width, ui.available_height()), |ui| { |
| 59 |
scrolled(ui, body[at], pass); |
| 60 |
}); |
| 61 |
ui.vertical(|ui| { |
| 62 |
for (i, slot) in body.iter().enumerate() { |
| 63 |
if i != at { |
| 64 |
scrolled(ui, slot, pass); |
| 65 |
} |
| 66 |
} |
| 67 |
}); |
| 68 |
}); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
None => { |
| 75 |
for slot in &body { |
| 76 |
scrolled(ui, slot, pass); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
Arrangement::ListDetail { share, tabbed } => { |
| 83 |
if tabbed { |
| 84 |
|
| 85 |
|
| 86 |
if let Some(slot) = body.first() { |
| 87 |
scrolled(ui, slot, pass); |
| 88 |
} |
| 89 |
} else { |
| 90 |
let left = ui.available_width() * share_of(share); |
| 91 |
ui.horizontal_top(|ui| { |
| 92 |
if let Some(slot) = body.first() { |
| 93 |
ui.allocate_ui(egui::vec2(left, ui.available_height()), |ui| { |
| 94 |
scrolled(ui, slot, pass); |
| 95 |
}); |
| 96 |
} |
| 97 |
ui.vertical(|ui| { |
| 98 |
for slot in body.iter().skip(1) { |
| 99 |
scrolled(ui, slot, pass); |
| 100 |
} |
| 101 |
}); |
| 102 |
}); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
fn scrolled(ui: &mut Ui, slot: &Slot, pass: &mut Pass<'_>) { |
| 114 |
egui::ScrollArea::vertical() |
| 115 |
.id_salt(&slot.id) |
| 116 |
.show(ui, |ui| { |
| 117 |
node::region(pass, ui, slot); |
| 118 |
}); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
fn share_of(share: quasi_router::layout::Share) -> f32 { |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
const SCALE: u16 = 1000; |
| 127 |
f32::from(share.of(SCALE)) / f32::from(SCALE) |
| 128 |
} |
| 129 |
|