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

Popup with container and autowrap Label doesn't sort properly #83546

Open
nathanfranke opened this issue Oct 18, 2023 · 10 comments
Open

Popup with container and autowrap Label doesn't sort properly #83546

nathanfranke opened this issue Oct 18, 2023 · 10 comments

Comments

@nathanfranke
Copy link
Contributor

nathanfranke commented Oct 18, 2023

Godot version

v4.2.beta1.official [b137180]

System information

Arch on 6.5.7-arch1-1

Issue description

I'm not sure exactly what the issue is, but easy to reproduce.

Even in the project manager, this window is much bigger in 4.2.beta1 than 4.1.2.stable.
image

In both cases the increased height is the Label wrapping with a width of zero.

Closing and re-opening the popup works around the issue.

4.1.2:
image

4.2.beta1:
image

Steps to reproduce

Launch MRP in 4.2.beta1+ or click an outdated project in the project manager.

Minimal reproduction project

test7-sizing.zip

extends Node

func _ready() -> void:
	var dialog := AcceptDialog.new()
	dialog.name = "AcceptDialog"
	add_child(dialog)
	
	var container := PanelContainer.new()
	container.custom_minimum_size.x = 200.0 # Not necessary for reproducing.
	dialog.add_child(container)
	
	var label := Label.new()
	label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
	label.text = "a b c d e f"
	container.add_child(label)
	
	dialog.popup_centered()
@nathanfranke nathanfranke changed the title Popup with container doesn't sort children perfectly [Regression 4.1.2 to 4.2] [Regression 4.1.2.stable to 4.2.beta1] Popup with container doesn't sort children perfectly Oct 18, 2023
@nathanfranke nathanfranke changed the title [Regression 4.1.2.stable to 4.2.beta1] Popup with container doesn't sort children perfectly [Regression 4.1.2.stable to 4.2.beta1] Popup with container and autowrap Label doesn't sort properly Oct 18, 2023
@nathanfranke
Copy link
Contributor Author

Related to #47005, #76000

But there seems to be a regression newer than either of those issues.

@KaddieZ
Copy link

KaddieZ commented Oct 18, 2023

Can confirm this bug in 4.2-beta1_mono, just happened to reproduce it while testing out GraphNode, a Label will break the height calculation of the GraphNode as soon as Autowrap (any mode) is activated.
image
In this picture, first node has no Autowrap. All the others are Autowrap Word Smart. Height of GraphNode seems to depends on the number of words in the label somehow.

Important note: height calculation works fine in the godot editor, only breaks while in-game.
Height calculation in the godot editor seems to work fine until you reload the project and the size is now broken the same in the editor as in game. Bottom anchor offset can be manually fixed but wont register.

Edit : here's the project I made to test this label_wrap_bug.zip

@akien-mga akien-mga changed the title [Regression 4.1.2.stable to 4.2.beta1] Popup with container and autowrap Label doesn't sort properly Popup with container and autowrap Label doesn't sort properly Oct 30, 2023
@akien-mga
Copy link
Member

I can confirm the bug with the two MRPs in this issue.

It seems to have been introduced in 4.2-dev3 (4.2-dev2 behaves like 4.1.2-stable).

If someone wants to bisect further between dev2 and dev3, that would be very useful.

@nathanfranke
Copy link
Contributor Author

I bisected to b156e24, #77280
CC @Rindbee

git checkout df616c9a17dfd9e5248c8fdebe20bd192f95266f # good
git checkout b156e24216f81aefcbc4f7983cdb7c6515d7ac76 # bad

@Rindbee
Copy link
Contributor

Rindbee commented Nov 2, 2023

Seems similar to #80218.
#83546 (comment) seems similar to #74052.

@YuriSizov
Copy link
Contributor

See my exhaustive comment here #80218 (comment). This is not something we can currently fix at its core. You should ensure your labels have at least some reasonable minimum size, and everything should work correctly. For editor widgets we should add minimum sizes where they are required as well.

@Rindbee
Copy link
Contributor

Rindbee commented Nov 3, 2023

In case of autowrap_mode != TextServer::AUTOWRAP_OFF. Maybe we can use the following code based on the fact that Label::_shape() bases on width and the default initial width is 0, to avoid giving an excessively large minimum height when width is undetermined.

 Size2 Label::get_minimum_size() const {
+       if (autowrap_mode != TextServer::AUTOWRAP_OFF && get_size() == Size2()) {
+               return Size2(); 
+       }
+

@YuriSizov
Copy link
Contributor

The behavior of the label is technically correct, so this isn't really a good solution. In any case, I wouldn't touch it at all right now. Because of the underlying issues every time we touch these nodes, we risk multiple regressions. The problem is documented, it's fine for the release in this state. This is better than introducing potential and unknown issues without any time to test everything.

@akien-mga
Copy link
Member

#84662 adds a node configuration warning for Labels using autowrap in containers, to make users aware that this is not a stable setting unless a custom minimum size is specified.

So this alleviates the problem for 4.2, until we can rework the sizing logic to follow a better approach.

@akien-mga akien-mga modified the milestones: 4.2, 4.3 Nov 9, 2023
@nathanfranke
Copy link
Contributor Author

This also works around the MRP:

label.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)

Slightly cleaner than set_custom_minimum_size IMO, but still needs an explanatory comment.

Zylann added a commit to Zylann/godot_heightmap_plugin that referenced this issue Jan 16, 2024
Labels with autowrap inside a Container must have a minimum size.
See godotengine/godot#83546
njamster added a commit to njamster/habituary that referenced this issue Jul 23, 2024
- Instead of `DisplayServer.window_set_min_size` the project now uses
  `get_window().min_size = ...` everywhere (as the docs recommend).
- Overlay components are now checked for two meta property `x_padding`
  and `y_padding` which can be used to increase the minimum size of the
  window in cases where the component is bigger than the previous min.
- Each component `item_rect_changed` signal is now connected to the new
  `_update_min_size` function when opened, which ensures that the window
  will always big enough to contain the entire component.
- A label in the settings panel uses auto-wrapping, which currently
  leads to issues when the label has no custom_minimum_size, see:
  godotengine/godot#83546
  I opted for an alternative fix (as proposed by nathanfranke in the
  issue linked above) which involves setting the anchors and offset of
  the label to the TOP_WIDE preset.
@KoBeWi KoBeWi modified the milestones: 4.3, 4.x Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants