Skip to content

Commit

Permalink
Merge pull request #705 from Jowan-Spooner/fix-for-node-labels
Browse files Browse the repository at this point in the history
Fix node label alignment
  • Loading branch information
RodZill4 authored Dec 3, 2024
2 parents e13b650 + c2a7bd6 commit 3448c50
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions material_maker/nodes/generic/generic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func update_node() -> void:
# Inputs
var inputs = generator.get_input_defs()
var index = -1
var input_labels := []
for i in range(inputs.size()):
var input = inputs[i]
var enable_left = false
Expand Down Expand Up @@ -475,21 +476,20 @@ func update_node() -> void:
if label != "":
var label_widget : Label = Label.new()
label_widget.text = label
label_widget.theme_type_variation = "MM_NodePropertyLabel"
hsizer.add_child(label_widget)
input_labels.append(label_widget)
set_slot(index, enable_left, type_left, color_left, false, 0, Color())

var input_names_width : int = 0
input_names_width = get_children().reduce(
func(accum, child): return max(child.get_child(0).size.x, accum) if child.get_child_count() else accum
, 0)


# Parameters
if !generator.minimized:
controls = {}
index = -1
var previous_focus = null
var first_focus = null
var labels := []
var property_labels := []
for p in generator.get_parameter_defs():
if !p.has("name") or !p.has("type"):
continue
Expand All @@ -512,19 +512,21 @@ func update_node() -> void:
while index >= get_child_count():
hsizer = HBoxContainer.new()
hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
if input_names_width > 0:
if not input_labels.is_empty():
var empty_control : Control = Control.new()
empty_control.custom_minimum_size.x = input_names_width
empty_control.mouse_filter = Control.MOUSE_FILTER_IGNORE
input_labels.append(empty_control)
hsizer.add_child(empty_control)
add_child(hsizer)
hsizer = get_child(index)
hsizer.custom_minimum_size.y = minimum_line_height
if label != "":
var label_widget = Label.new()
label_widget.text = label
labels.append(label_widget)
property_labels.append(label_widget)
label_widget.theme_type_variation = "MM_NodePropertyLabel"
hsizer.add_child(label_widget)

control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
if hsizer != null:
hsizer.add_child(control)
Expand All @@ -535,16 +537,30 @@ func update_node() -> void:
first_focus = control
previous_focus = control

var label_max_width = labels.reduce(func(accum, label): return max(accum, label.size.x), 0)
var label_max_width = property_labels.reduce(func(accum, label): return max(accum, label.size.x), 0)
label_max_width = min(100, label_max_width)
for label in labels:
for label in property_labels:
label.custom_minimum_size.x = label_max_width
label.size.x = label_max_width
label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS

var input_label_width : int = 0
input_label_width = get_children().reduce(
func(accum, child): return max(child.get_child(0).size.x, accum) if child.get_child_count() else accum
, 0)

if not property_labels.is_empty():
input_label_width += 10

for i in input_labels:
i.custom_minimum_size.x = input_label_width

if first_focus != null:
previous_focus.focus_next = first_focus.get_path()
first_focus.focus_previous = previous_focus.get_path()
initialize_properties()


# Outputs
var outputs = generator.get_output_defs()
output_count = outputs.size()
Expand Down

0 comments on commit 3448c50

Please sign in to comment.