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

Fix node label alignment #705

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 28 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,22 @@ 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 = 25

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 +538,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 All @@ -568,6 +585,7 @@ func update_node() -> void:
hsizer = get_child(i)
if hsizer.get_child_count() == 0:
hsizer.custom_minimum_size.y = 25 if !generator.minimized else 12

# Edit buttons
if generator.is_editable():
for theme_stylebox in ["frame", "selected_frame"]:
Expand Down
2 changes: 2 additions & 0 deletions material_maker/widgets/float_edit/float_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ extends Container

var float_value: float = 0.5
@export var value: float = 0.5 :
get:
return float_value
set(new_value):
set_value(new_value)

Expand Down