Skip to content

Commit

Permalink
Use Spacing::item_spacing to set the space between sockets (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
tguichaoua authored Dec 15, 2024
1 parent 67b2311 commit f29407b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion nodui/src/editor/show/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<S> NodeUi<S> {
.into_iter()
.map(|s| render::socket::prepare(ui, s))
.collect();
let body = render::body::prepare(background_color, layout, sockets);
let body = render::body::prepare(ui.spacing(), background_color, layout, sockets);

PreparedNode {
header,
Expand Down
18 changes: 9 additions & 9 deletions nodui/src/editor/show/render/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use crate::{
NodeLayout, NodeSide, RenderedSocket,
};

use super::{
socket::PreparedSocket, DOUBLE_COLUMNS_GAP, SOCKET_NAME_GAP, SOCKET_VERTICAL_GAP, SOCKET_WIDTH,
};
use super::{socket::PreparedSocket, SOCKET_NAME_GAP, SOCKET_WIDTH};

/* -------------------------------------------------------------------------- */

Expand Down Expand Up @@ -39,38 +37,40 @@ impl<S> PreparedBody<S> {

/// Prepare the node body for its rendering.
pub(crate) fn prepare<S>(
spacing: &egui::Spacing,
background_color: Color32,
layout: NodeLayout,
sockets: Vec<PreparedSocket<S>>,
) -> PreparedBody<S> {
let padding = Margin::same(5.0);
let socket_vertical_gap = spacing.item_spacing.y;

let size: Vec2 = match layout {
NodeLayout::Single => layout::stack_vertically_with_gap(
sockets.iter().map(PreparedSocket::compute_size),
SOCKET_VERTICAL_GAP,
socket_vertical_gap,
),
NodeLayout::Double => {
let left = layout::stack_vertically_with_gap(
sockets
.iter()
.filter(|s| s.side == NodeSide::Left)
.map(PreparedSocket::compute_size),
SOCKET_VERTICAL_GAP,
socket_vertical_gap,
);

let right = layout::stack_vertically_with_gap(
sockets
.iter()
.filter(|s| s.side == NodeSide::Right)
.map(PreparedSocket::compute_size),
SOCKET_VERTICAL_GAP,
socket_vertical_gap,
);

let column_gap = if left == Vec2::ZERO || right == Vec2::ZERO {
Vec2::ZERO
} else {
vec2(DOUBLE_COLUMNS_GAP, 0.0)
vec2(spacing.item_spacing.x, 0.0)
};

layout::stack_horizontally([left, column_gap, right])
Expand Down Expand Up @@ -161,7 +161,7 @@ fn show_single_column_body<S>(

show_socket(ui, rendered_sockets, socket_center, text_pos, socket);

pos.y += size.y + SOCKET_VERTICAL_GAP;
pos.y += size.y + ui.spacing().item_spacing.y;
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ fn show_double_column_body<S>(

show_socket(ui, rendered_sockets, socket_center, text_pos, socket);

pos.y += size.y + SOCKET_VERTICAL_GAP;
pos.y += size.y + ui.spacing().item_spacing.y;
}
}

Expand Down
9 changes: 1 addition & 8 deletions nodui/src/editor/show/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,5 @@ pub(super) mod socket;
/// The width of the socket's handle.
const SOCKET_WIDTH: f32 = 10.0;

/// Space between socket's name its socket shape.
/// Space between socket's name and its shape.
const SOCKET_NAME_GAP: f32 = 5.0;

/// Space between the two columns of a node.
const DOUBLE_COLUMNS_GAP: f32 = 5.0;

// TODO: use ui.spacing instead
/// The vertical space between each socket.
const SOCKET_VERTICAL_GAP: f32 = 5.0;

0 comments on commit f29407b

Please sign in to comment.