Skip to content

Commit

Permalink
Fix node size (#20)
Browse files Browse the repository at this point in the history
* ⚰️ remove socket field related code

* 🐛 fix node size
  • Loading branch information
tguichaoua authored Dec 10, 2024
1 parent ac962c9 commit 803f43d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 8 additions & 3 deletions nodui/src/editor/show/render/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::{
NodeLayout, NodeSide, RenderedSocket,
};

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

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

Expand Down Expand Up @@ -42,7 +44,6 @@ pub(crate) fn prepare<S>(
sockets: Vec<PreparedSocket<S>>,
) -> PreparedBody<S> {
let padding = Margin::same(5.0);
let column_gap = 5.0;

let size: Vec2 = match layout {
NodeLayout::Single => {
Expand All @@ -61,7 +62,11 @@ pub(crate) fn prepare<S>(
*size = layout::stack_vertically([*size, s.compute_size()]);
}

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

layout::stack_horizontally([left, column_gap, right])
}
Expand Down
4 changes: 2 additions & 2 deletions nodui/src/editor/show/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const SOCKET_WIDTH: f32 = 10.0;
/// Space between socket's name its socket shape.
const SOCKET_NAME_GAP: f32 = 5.0;

/// Space between socket's name and field.
const SOCKET_NAME_FIELD_GAP: f32 = 5.0;
/// Space between the two columns of a node.
const DOUBLE_COLUMNS_GAP: f32 = 5.0;

/// The height of a socket line.
const ROW_HEIGHT: f32 = 20.0;
6 changes: 2 additions & 4 deletions nodui/src/editor/show/render/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use egui::{vec2, Color32, Vec2};

use crate::{misc::layout, NodeSide, Socket, SocketShape};

use super::{ROW_HEIGHT, SOCKET_NAME_FIELD_GAP, SOCKET_NAME_GAP, SOCKET_WIDTH};
use super::{ROW_HEIGHT, SOCKET_NAME_GAP, SOCKET_WIDTH};

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

Expand All @@ -32,10 +32,8 @@ impl<S> PreparedSocket<S> {
let socket_size = Vec2::splat(SOCKET_WIDTH);
let socket_text_gap = vec2(SOCKET_NAME_GAP, 0.0);
let text_size = self.text.size();
let text_field_gap = vec2(SOCKET_NAME_FIELD_GAP, 0.0);

let mut size =
layout::stack_horizontally([socket_size, socket_text_gap, text_size, text_field_gap]);
let mut size = layout::stack_horizontally([socket_size, socket_text_gap, text_size]);

// FIXME: it work will the computed height is lower than `ROW_HEIGHT`.
size.y = ROW_HEIGHT;
Expand Down

0 comments on commit 803f43d

Please sign in to comment.