use egui::{Color32, Pos2, Style, Ui};
use crate::{InPin, NodeId, OutPin, Snarl};
use super::pin::PinInfo;
pub trait SnarlViewer<T> {
fn title(&mut self, node: &T) -> String;
fn has_body(&mut self, node: &T) -> bool {
let _ = node;
false
}
fn has_footer(&mut self, node: &T) -> bool {
let _ = node;
false
}
fn has_on_hover_popup(&mut self, node: &T) -> bool {
let _ = node;
false
}
fn show_header(
&mut self,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
ui: &mut Ui,
scale: f32,
snarl: &mut Snarl<T>,
) {
let _ = (inputs, outputs, scale);
ui.label(self.title(&snarl[node]));
}
fn outputs(&mut self, node: &T) -> usize;
fn inputs(&mut self, node: &T) -> usize;
fn show_input(&mut self, pin: &InPin, ui: &mut Ui, scale: f32, snarl: &mut Snarl<T>)
-> PinInfo;
fn show_output(
&mut self,
pin: &OutPin,
ui: &mut Ui,
scale: f32,
snarl: &mut Snarl<T>,
) -> PinInfo;
fn show_body(
&mut self,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
ui: &mut Ui,
scale: f32,
snarl: &mut Snarl<T>,
) {
let _ = (node, inputs, outputs, ui, scale, snarl);
}
fn show_footer(
&mut self,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
ui: &mut Ui,
scale: f32,
snarl: &mut Snarl<T>,
) {
let _ = (node, inputs, outputs, ui, scale, snarl);
}
fn show_on_hover_popup(
&mut self,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
ui: &mut Ui,
scale: f32,
snarl: &mut Snarl<T>,
) {
let _ = (node, inputs, outputs, ui, scale, snarl);
}
fn input_color(&mut self, pin: &InPin, style: &Style, snarl: &mut Snarl<T>) -> Color32;
fn output_color(&mut self, pin: &OutPin, style: &Style, snarl: &mut Snarl<T>) -> Color32;
fn graph_menu(&mut self, pos: Pos2, ui: &mut Ui, scale: f32, snarl: &mut Snarl<T>) {
let _ = (pos, ui, scale, snarl);
}
fn node_menu(
&mut self,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
ui: &mut Ui,
scale: f32,
snarl: &mut Snarl<T>,
) {
let _ = (node, inputs, outputs, ui, scale, snarl);
}
#[inline]
fn connect(&mut self, from: &OutPin, to: &InPin, snarl: &mut Snarl<T>) {
snarl.connect(from.id, to.id);
}
#[inline]
fn disconnect(&mut self, from: &OutPin, to: &InPin, snarl: &mut Snarl<T>) {
snarl.disconnect(from.id, to.id);
}
#[inline]
fn drop_outputs(&mut self, pin: &OutPin, snarl: &mut Snarl<T>) {
snarl.drop_outputs(pin.id);
}
#[inline]
fn drop_inputs(&mut self, pin: &InPin, snarl: &mut Snarl<T>) {
snarl.drop_inputs(pin.id);
}
}