Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow viewer co customize egui style for the individual node UI #52

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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