最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gdscript - Buttons don't resize correctlly with warping text in Godot - Stack Overflow

programmeradmin1浏览0评论

I have a set of buttons with some text written on them. I want these buttons to have the same width as the screen, no matter the screen size. I also have text warp enabled, so that if the text is longer than the screen it takes two lines.

However if textwarp is needed, the button won't be big enough. This is what I see when there are two lines of text:

The weird thing is, if I resize the window to any other size and then back to the original size, the problem fixes itself.

I don't know why it works. The code currently is

func _ready() -> void:
  hide()
  get_tree().get_root().size_changed.connect(resize)
  resize()
  show()

func resize() -> void:
  custom_minimum_size.x = get_viewport_rect().size.x

Where i'm hiding it and showing it again to fix a different error (where the first button would inexplicably be really large for no reason). If it's relevant, the buttons are childeren of a VBox, and they are instantiated entirely through code.

I have tried forcing it to redraw but queue_redraw() does nothing. I've tried setting a custom minimum y size, but I can't seem to find how to tell if textwarp has happened, and get_visible_line_count() seems to only be a thing with rich text.

Does anyone understand why this is happening or how to fix this?

I have a set of buttons with some text written on them. I want these buttons to have the same width as the screen, no matter the screen size. I also have text warp enabled, so that if the text is longer than the screen it takes two lines.

However if textwarp is needed, the button won't be big enough. This is what I see when there are two lines of text:

The weird thing is, if I resize the window to any other size and then back to the original size, the problem fixes itself.

I don't know why it works. The code currently is

func _ready() -> void:
  hide()
  get_tree().get_root().size_changed.connect(resize)
  resize()
  show()

func resize() -> void:
  custom_minimum_size.x = get_viewport_rect().size.x

Where i'm hiding it and showing it again to fix a different error (where the first button would inexplicably be really large for no reason). If it's relevant, the buttons are childeren of a VBox, and they are instantiated entirely through code.

I have tried forcing it to redraw but queue_redraw() does nothing. I've tried setting a custom minimum y size, but I can't seem to find how to tell if textwarp has happened, and get_visible_line_count() seems to only be a thing with rich text.

Does anyone understand why this is happening or how to fix this?

Share Improve this question asked Mar 4 at 13:46 SkilopsarosSkilopsaros 676 bronze badges 2
  • Are you creating buttons on the fly via Button.new(), or through PackedScene instanting? – liggiio Commented Mar 9 at 10:00
  • it was through PackedScene instanting. The issue was aparently a known bug with Godot 4.3, upgrading to 4.4 fixed it. – Skilopsaros Commented Mar 10 at 11:05
Add a comment  | 

1 Answer 1

Reset to default 0

This was apparently a known bug with Godot 4.3, fixed in Godot 4.4. Upgrading the code to Godot 4.4 fixed the issue.

发布评论

评论列表(0)

  1. 暂无评论