use crate::{
Env, InspectorRowsResponse, NodeCtx, NodeUi, NodeUiResponse, SocketDoc, SocketKind,
widget::node_inspector,
};
use gantz_core::node;
impl NodeUi for gantz_core::node::graph::Outlet {
fn name(&self, _: &Env<'_>) -> std::borrow::Cow<'_, str> {
"out".into()
}
fn description(&self) -> Option<&'static str> {
Some("A graph output")
}
fn ui(&mut self, ctx: NodeCtx, uictx: egui_graph::NodeCtx) -> NodeUiResponse {
let framed = uictx.framed(|ui, _sockets| {
let name = self.name(ctx.env());
let ix = outlet_ix(ctx.path(), ctx.outlets());
let text = format!("{}[{}]", name, ix);
ui.add(egui::Label::new(text).selectable(false))
});
NodeUiResponse::new(framed)
}
fn inspector_rows(
&mut self,
ctx: &mut NodeCtx,
body: &mut egui_extras::TableBody,
) -> InspectorRowsResponse {
let row_h = node_inspector::table_row_h(body.ui_mut());
body.row(row_h, |mut row| {
row.col(|ui| {
ui.label("index");
});
row.col(|ui| {
let ix = outlet_ix(ctx.path(), ctx.outlets());
ui.label(format!("{ix}"));
});
});
let changed =
node_inspector::socket_doc_rows(body, ctx.path(), &mut self.ty, &mut self.description);
InspectorRowsResponse {
changed,
payloads: Vec::new(),
}
}
fn socket_doc(&self, _: &Env<'_>, kind: SocketKind, _ix: usize) -> Option<SocketDoc> {
match kind {
SocketKind::Input => Some(super::inlet::socket_doc(
&self.ty,
&self.description,
"output",
)),
SocketKind::Output => None,
}
}
}
fn outlet_ix(path: &[node::Id], outlets: &[node::Id]) -> usize {
let id = path.last().expect("outlet must have non-outlet path");
outlets
.iter()
.position(|in_id| id == in_id)
.expect("outlet ID must exist")
}