From 5becc11bf9181de89490721ed07a97b8d649f1bb Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 14 Jan 2024 16:23:31 +0100 Subject: [PATCH] ViewPort: implement attach_to() --- src/view/port.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/view/port.rs b/src/view/port.rs index 932be30..fe978ba 100644 --- a/src/view/port.rs +++ b/src/view/port.rs @@ -97,6 +97,22 @@ where } } +impl ViewPort +where V::Msg: Clone +{ + // make the view of `other_port` accessible from `self` + pub fn attach_to(&self, other_port: OuterViewPort) { + self.attach_to_port(other_port.0); + } + pub fn attach_to_port(&self, other_port: ViewPort) { + self.set_view( other_port.view.read().unwrap().clone() ); + other_port.add_observer( self.cast.clone() ); + + self.update_hooks.write().unwrap().clear(); + self.add_update_hook( Arc::new(other_port) ); + } +} + impl UpdateTask for ViewPort where V::Msg: Clone + Send + Sync,