use std::cell::RefCell;
use egui::{Color32, Pos2, Response, Ui};
use super::{
effect::{Effects, Forbidden},
pin::{InPin, OutPin, PinInfo},
};
pub trait SnarlViewer<T> {
#[inline]
fn add_node(
&mut self,
idx: usize,
node: &T,
effects: &mut Effects<T>,
) -> Result<(), Forbidden> {
let _ = (idx, node, effects);
Ok(())
}
#[inline]
fn connect(
&mut self,
from: &OutPin<T>,
to: &InPin<T>,
effects: &mut Effects<T>,
) -> Result<(), Forbidden> {
effects.connect(from.id, to.id);
Ok(())
}
#[inline]
fn disconnect(
&mut self,
from: &OutPin<T>,
to: &InPin<T>,
effects: &mut Effects<T>,
) -> Result<(), Forbidden> {
effects.disconnect(from.id, to.id);
Ok(())
}
#[inline]
fn drop_outputs(&mut self, pin: &OutPin<T>, effects: &mut Effects<T>) -> Result<(), Forbidden> {
effects.drop_outputs(pin.id);
Ok(())
}
#[inline]
fn drop_inputs(&mut self, pin: &InPin<T>, effects: &mut Effects<T>) -> Result<(), Forbidden> {
effects.drop_inputs(pin.id);
Ok(())
}
#[inline]
fn remove_node(
&mut self,
idx: usize,
node: &RefCell<T>,
inputs: &[InPin<T>],
outputs: &[OutPin<T>],
effects: &mut Effects<T>,
) -> Result<(), Forbidden> {
let _ = (idx, node, inputs, outputs);
effects.remove_node(idx);
Ok(())
}
fn title<'a>(&'a mut self, node: &'a T) -> &'a str;
fn show_header(
&mut self,
idx: usize,
node: &RefCell<T>,
inputs: &[InPin<T>],
outputs: &[OutPin<T>],
ui: &mut Ui,
scale: f32,
effects: &mut Effects<T>,
) -> Response {
let _ = (idx, node, inputs, outputs, scale, effects);
ui.label(self.title(&*node.borrow()))
}
fn outputs(&mut self, node: &T) -> usize;
fn inputs(&mut self, node: &T) -> usize;
fn show_input(
&mut self,
pin: &InPin<T>,
ui: &mut Ui,
scale: f32,
effects: &mut Effects<T>,
) -> egui::InnerResponse<PinInfo>;
fn show_output(
&mut self,
pin: &OutPin<T>,
ui: &mut Ui,
scale: f32,
effects: &mut Effects<T>,
) -> egui::InnerResponse<PinInfo>;
fn input_color(&mut self, pin: &InPin<T>) -> Color32;
fn output_color(&mut self, pin: &OutPin<T>) -> Color32;
fn graph_menu(&mut self, pos: Pos2, ui: &mut Ui, scale: f32, effects: &mut Effects<T>) {
let _ = (pos, ui, scale, effects);
}
fn node_menu(
&mut self,
idx: usize,
node: &RefCell<T>,
inputs: &[InPin<T>],
outputs: &[OutPin<T>],
ui: &mut Ui,
scale: f32,
effects: &mut Effects<T>,
) {
let _ = (idx, node, inputs, outputs, ui, scale, effects);
}
}