2020-12-09 17:31:08 +01:00
|
|
|
use {
|
2023-02-13 18:39:45 +01:00
|
|
|
r3vi::{
|
|
|
|
view::{
|
|
|
|
InnerViewPort, Observer, ObserverBroadcast, OuterViewPort, View,
|
|
|
|
index::*,
|
|
|
|
},
|
|
|
|
projection::projection_helper::*,
|
2021-11-19 12:19:52 +01:00
|
|
|
},
|
2023-02-13 18:39:45 +01:00
|
|
|
crate::{terminal::{TerminalAtom, TerminalView}},
|
2021-11-19 12:19:52 +01:00
|
|
|
cgmath::Point2,
|
|
|
|
std::sync::Arc,
|
|
|
|
std::sync::RwLock,
|
2020-12-09 17:31:08 +01:00
|
|
|
};
|
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
2020-12-09 17:31:08 +01:00
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
pub struct TerminalCompositor {
|
|
|
|
layers: Vec<Arc<dyn TerminalView>>,
|
|
|
|
cast: Arc<RwLock<ObserverBroadcast<dyn TerminalView>>>,
|
2021-11-19 12:19:52 +01:00
|
|
|
proj_helper: ProjectionHelper<usize, Self>,
|
2021-02-17 18:18:39 +01:00
|
|
|
}
|
2021-01-06 21:35:46 +01:00
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
2021-01-06 21:35:46 +01:00
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
impl TerminalCompositor {
|
2021-11-19 12:19:52 +01:00
|
|
|
pub fn new(port: InnerViewPort<dyn TerminalView>) -> Arc<RwLock<Self>> {
|
|
|
|
let comp = Arc::new(RwLock::new(TerminalCompositor {
|
|
|
|
layers: Vec::new(),
|
|
|
|
cast: port.get_broadcast(),
|
|
|
|
proj_helper: ProjectionHelper::new(port.0.update_hooks.clone()),
|
|
|
|
}));
|
2021-01-06 21:35:46 +01:00
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
comp.write().unwrap().proj_helper.set_proj(&comp);
|
|
|
|
port.set_view(Some(comp.clone()));
|
|
|
|
|
|
|
|
comp
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
pub fn push(&mut self, v: OuterViewPort<dyn TerminalView>) {
|
2021-08-24 23:15:18 +02:00
|
|
|
let idx = self.layers.len();
|
2021-02-17 18:18:39 +01:00
|
|
|
self.layers.push(
|
2021-11-19 12:19:52 +01:00
|
|
|
self.proj_helper
|
|
|
|
.new_index_arg(idx, v, |s: &mut Self, area| {
|
2021-11-07 07:16:33 +01:00
|
|
|
s.cast.notify(area);
|
2021-11-19 12:19:52 +01:00
|
|
|
}),
|
2021-02-17 18:18:39 +01:00
|
|
|
);
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
2020-12-09 17:31:08 +01:00
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
impl View for TerminalCompositor {
|
|
|
|
type Msg = IndexArea<Point2<i16>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IndexView<Point2<i16>> for TerminalCompositor {
|
|
|
|
type Item = TerminalAtom;
|
2021-01-06 21:35:46 +01:00
|
|
|
|
|
|
|
fn get(&self, pos: &Point2<i16>) -> Option<TerminalAtom> {
|
|
|
|
let mut atom = None;
|
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
for layer in self.layers.iter() {
|
|
|
|
match (atom, layer.get(pos)) {
|
|
|
|
(None, next) => atom = next,
|
|
|
|
(Some(last), Some(next)) => atom = Some(next.add_style_back(last.style)),
|
|
|
|
_ => {}
|
2020-12-09 17:31:08 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-06 21:35:46 +01:00
|
|
|
|
|
|
|
atom
|
2020-12-09 17:31:08 +01:00
|
|
|
}
|
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
fn area(&self) -> IndexArea<Point2<i16>> {
|
|
|
|
let mut area = IndexArea::Empty;
|
2021-01-16 18:00:56 +01:00
|
|
|
|
2021-02-17 18:18:39 +01:00
|
|
|
for layer in self.layers.iter() {
|
2021-11-07 07:16:33 +01:00
|
|
|
area = area.union(layer.area());
|
2021-01-16 18:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
area
|
2020-12-09 17:31:08 +01:00
|
|
|
}
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|