How can I reduce the button size in a box container that I added by script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By proletariatt

I added a button node, then an icon on it. Icon’s size is smaller than 50 pixel, which was the previous pixel size of the container boxes. My cancel icon is making the whole xbox container items grow slightly even after these codes. There are some empty slots around the icon, like the background of the button node. What do i need to size it properly? I think I need to clear background but I dont get why I cant reduce its size with set_size() or the others.

var cancel_icon = preload(“res://resources/symbol/cancel.png”)
var cancel = Button.new()
var cancel_size = Vector2(33,33)
cancel.set(“icon”, cancel_icon)
cancel.size_flags_vertical= Button.SIZE_SHRINK_CENTER
cancel.size_flags_horizontal = Button.SIZE_SHRINK_CENTER
cancel.set(“rect_size”, cancel_size)
cancel.set_size(cancel_size)
self.add_child(cancel)

Some thoughts:

  • you don’t need call set() for icon or rect_size or size, you can just access the properties directly by name
  • you don’t need to use self to call functions that belong to current script
  • setting the size of a control node that is the child of a container is pointless because the container controls the size of its children and it will be ignored
  • I don’t actually know what the problem is? How can the icon cause the container items to grow if it’s SMALLER than the previous size? Can you post a screenshot?

exuin | 2023-02-25 09:11

I’m quite a beginner so…

  1. Do you mean something like: cancel.icon =“cancelicon” ? Idk how am i suppose to use names.
  2. ok, thanks:D
    3.-4 : My problem is the rightest box distrups the others. Someone said to put a container, so things will automoatically shrink to its size. Plus, It wasnt suppose to change the line’s margin/order (?) after being added since it will be there before any icon being added . Because I want to make it appear sometimes and vanish at another.this godot symbol is in margin container that is slighly smaller than the boxes, yet it results like this: https://ibb.co/Xkw2Cq3
    Thanks for the reply

proletariatt | 2023-02-25 12:01

cancel.icon = cancel_icon

I think the issue is that the items are centered. If you don’t center them then the extra icon will not move the other ones.

exuin | 2023-02-25 15:26

Thanks, it means a lot for someone as noob as me:D

Still trying to figure out locating stuff, eventualy I will get it.

proletariatt | 2023-02-25 18:49