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

Added collapse/expand blocks for "advanced" settings #336

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

joaquin30
Copy link
Contributor

/claim #288
Closes #288. This adds a button for expand/collapse settings in blocks that are after the "|" separator.

@manuq
Copy link
Contributor

manuq commented Dec 16, 2024

@joaquin30 looking good so far!

Grabacion.de.pantalla.desde.2024-12-16.09-28-57.webm

I know this is still draft, but for the 1st review make sure that this pass the linting and formatting check above. You can do that locally if you setup pre-commit as in the README

@joaquin30 joaquin30 marked this pull request as ready for review December 16, 2024 22:39
Copy link
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working nicely! I have left suggestions for improving the code.

Besides the improvement requests, we try to have descriptive commit messages in this project. Could you squash your commits and provide a good description? For example:

  • A first line explaining briefly what's this about.
  • A description of what does this PR do and how it's implemented.
  • As last line, the URL to the issue that this fixes, eg "Fixes https://..."

Comment on lines 94 to 95
# separate the template string by | character
# for normal and advanced parameters (advanced parameters are hidden)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize the comment sentence and add . to the end of the sentence.

Suggested change
# separate the template string by | character
# for normal and advanced parameters (advanced parameters are hidden)
# Separate the template string by | character
# for normal and advanced parameters (advanced parameters are hidden).

Comment on lines 122 to 135
# Parse the advanced part of the template string
for regex_match in _display_template_regex.search_all(template_string_advanced):
if regex_match.names.has("label"):
var label_string := regex_match.get_string("label")
items.append({"label": label_string, "hidden": true})
elif regex_match.names.has("in_parameter"):
var parameter_string := regex_match.get_string("in_parameter")
items.append({"in_parameter": _parse_parameter_format(parameter_string), "hidden": true})
elif regex_match.names.has("out_parameter"):
var parameter_string := regex_match.get_string("out_parameter")
items.append({"out_parameter": _parse_parameter_format(parameter_string), "hidden": true})
elif regex_match.names.has("const_parameter"):
var parameter_string := regex_match.get_string("const_parameter")
items.append({"const_parameter": _parse_parameter_format(parameter_string), "hidden": true})
Copy link
Contributor

@manuq manuq Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the "hidden": true, this for loop is exactly the same as the one above. So please come with a inner function and a boolean parameter.

Comment on lines 11 to 12
$CollapseButton.connect("button_up", collapse)
$ExpandButton.connect("button_up", expand)
Copy link
Contributor

@manuq manuq Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these buttons, please declare the nodes at the top of the script. And also add unique names to them. This way the script doesn't depend on UI changes:

@onready var _collapse_button: Button = %CollapseButton
@onready var _expand_button: Button = %ExpandButton

for item in BlockDefinition.parse_display_template(format_string):
var hidden = item.has("hidden") and item.get("hidden")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item.get("hidden") already returns null if the key is missing, and you can also pass a default. So you can probably do the same without the has() check:

Suggested change
var hidden = item.has("hidden") and item.get("hidden")
var hidden = item.get("hidden", false)

Untested, please confirm!

Comment on lines 98 to 104
_append_label(collapsable if hidden else _container, item.get("label"))
elif item.has("in_parameter"):
_append_input_parameter(item.get("in_parameter"), match_id)
_append_input_parameter(collapsable if hidden else _container, item.get("in_parameter"), match_id)
elif item.has("out_parameter"):
_append_output_parameter(item.get("out_parameter"), match_id)
_append_output_parameter(collapsable if hidden else _container, item.get("out_parameter"), match_id)
elif item.has("const_parameter"):
_append_const_parameter(item.get("const_parameter"), match_id)
_append_const_parameter(collapsable if hidden else _container, item.get("const_parameter"), match_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The collapsable if hidden else _container is repeated 4 times. Is better to move it to a variable before the if/elif/elif/elif block.

This commit modifies the display_template parsing of .tres block definitions, adding a separator using the | character. All labels and parameters after this separator are added to a new CollapsableSettings container that has collapse/expand buttons, with the goal of hiding advanced settings from users.
To do this, a new hidden key with a boolean value is added to the results of the parse_display_template method. Additionally, CollapsableSettings is implemented using an HBoxContainer and changing the visibility of child nodes when changing collapse/expand states.
Fixes endlessm#288.
@joaquin30 joaquin30 force-pushed the collapse-expand-advanced-settings branch from 075f9ee to 7dcd95a Compare December 17, 2024 03:58
@manuq manuq merged commit a9059a8 into endlessm:main Dec 17, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collapse/expand blocks for "advanced" settings ($200 bounty)
2 participants