Skip to content

Commit

Permalink
Merge pull request #52 from juh9870/custom-node-style
Browse files Browse the repository at this point in the history
Allow viewer co customize egui style for the individual node UI
  • Loading branch information
zakarumych authored Feb 6, 2025
2 parents b17ce75 + 1d86aae commit 4bbe1fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,10 @@ impl<T> Snarl<T> {
let mut new_pins_size = Vec2::ZERO;

let r = node_frame.show(node_ui, |ui| {
if viewer.has_node_style(node, &inputs, &outputs, self) {
viewer.apply_node_style(ui.style_mut(), node, &inputs, &outputs, self);
}

let min_pin_y = node_state.header_height().mul_add(0.5, node_rect.min.y);

// Input pins' center side by X axis.
Expand Down
24 changes: 24 additions & 0 deletions src/ui/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ pub trait SnarlViewer<T> {
let _ = (node, inputs, outputs, snarl);
default
}
/// Checks if node has a custom egui style.
#[inline]
fn has_node_style(
&mut self,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
snarl: &Snarl<T>,
) -> bool {
let _ = (node, inputs, outputs, snarl);
false
}

/// Modifies the node's egui style
fn apply_node_style(
&mut self,
style: &mut Style,
node: NodeId,
inputs: &[InPin],
outputs: &[OutPin],
snarl: &Snarl<T>,
) {
let _ = (style, node, inputs, outputs, snarl);
}

/// Returns layout override for the node.
///
Expand Down

0 comments on commit 4bbe1fb

Please sign in to comment.