Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @tool
- extends VBoxContainer
- class_name VBoxColumnOrganizer
- ## Every immediate child of this node that is an HBoxContainer will have its
- ## children's [code]custom_minimum.size.x[/code] set by this node's
- ## [code]column_width[/code]. The number of column widths automatically set by
- ## this node is equal to the number of elements in the [code]column_width[/code]
- ## array.
- ## Sets the minimum width of all Control nodes that are children of this node's
- ## immediate HBoxContainer children.[br]
- ## [b]Note:[/b] These values are being set in real time, and removing a column does not
- ## reset the affected elements' minimum widths to what they were prior to the
- ## adjustment. If you want to reset all of those elements to zero, you can set
- ## them to zero before deleting the column's setting from the array.
- @export var column_width : Array[int] = [0] : set = set_column_width
- ## This will automatically set the last child in each HBoxContainer to expand
- ## horizontally.
- @export var expand_last_column : bool = true : set = set_expand_last_column
- ## Selecting this will allow CheckBox and CheckButton nodes in the last column
- ## to expand when [code]expand_last_column[/code] is set to true. This is
- ## [b]typically not the behavior you want,[/b] so it is set to false by default.
- @export var also_expand_checkbox : bool = false : set = set_also_expand_checkbox
- func set_column_width(n):
- column_width = n
- _act()
- func set_expand_last_column(n):
- expand_last_column = n
- _act()
- func set_also_expand_checkbox(n):
- also_expand_checkbox = n
- _act()
- func _ready():
- _act()
- child_entered_tree.connect(_act)
- child_exiting_tree.connect(_act)
- child_order_changed.connect(_act)
- func _act(_input = null):
- var children = get_children()
- for i in children:
- if i is HBoxContainer: _adjust_row(i)
- func _adjust_row(row_hbox : HBoxContainer):
- var children : Array = row_hbox.get_children()
- for i in len(column_width):
- if children[i] is Control:
- children[i].custom_minimum_size.x = column_width[i]
- if expand_last_column:
- var c = children[-1]
- if !also_expand_checkbox:
- if c is CheckBox or c is CheckButton: return
- if c is Control:
- children[-1].size_flags_horizontal = 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement