use crate::Sender;
use crate::factory::{FactorySender, FactoryView, Position};
use std::fmt::Debug;
pub trait FactoryComponent:
Position<<Self::ParentWidget as FactoryView>::Position, Self::Index> + Sized + 'static
{
type ParentWidget: FactoryView + 'static;
type CommandOutput: Debug + Send + 'static;
type Input: Debug + 'static;
type Output: Debug + 'static;
type Init;
type Root: AsRef<<Self::ParentWidget as FactoryView>::Children> + Debug + Clone;
type Widgets: 'static;
type Index;
fn init_model(init: Self::Init, index: &Self::Index, sender: FactorySender<Self>) -> Self;
fn init_root(&self) -> Self::Root;
fn init_widgets(
&mut self,
index: &Self::Index,
root: Self::Root,
returned_widget: &<Self::ParentWidget as FactoryView>::ReturnedWidget,
sender: FactorySender<Self>,
) -> Self::Widgets;
#[allow(unused)]
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {}
#[allow(unused)]
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {}
fn update_cmd_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::CommandOutput,
sender: FactorySender<Self>,
) {
self.update_cmd(message, sender.clone());
self.update_view(widgets, sender);
}
#[allow(unused)]
fn update_view(&self, widgets: &mut Self::Widgets, sender: FactorySender<Self>) {}
fn update_with_view(
&mut self,
widgets: &mut Self::Widgets,
message: Self::Input,
sender: FactorySender<Self>,
) {
self.update(message, sender.clone());
self.update_view(widgets, sender);
}
#[allow(unused)]
fn shutdown(&mut self, widgets: &mut Self::Widgets, output: Sender<Self::Output>) {}
fn id(&self) -> String {
format!("{:p}", &self)
}
}
pub trait CloneableFactoryComponent: FactoryComponent {
fn get_init(&self) -> Self::Init;
}