Skip to content

Commit

Permalink
Added properties to override horizontal padding
Browse files Browse the repository at this point in the history
The property applies the padding to all the HBoxContainer children.
  • Loading branch information
dfego committed Feb 18, 2024
1 parent 4c54455 commit 68e3ff9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions addons/table_container/table_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ class_name TableContainer extends VBoxContainer
## Update interval, in frames, if [member auto_update_in_game] is true
@export var update_interval_in_game: int = 60

## Flag for whether to apply [member horizontal_separation]
@export var override_horizontal_separation: bool = false:
set(value):
override_horizontal_separation = value
_apply_horizontal_override(value, _horizontal_separation)
if not override_horizontal_separation:
_horizontal_separation = 0

## Override for horizontal padding between elements, in pixels.
@export var horizontal_separation: int:
set(value):
if not override_horizontal_separation:
override_horizontal_separation = true

_horizontal_separation = value
_apply_horizontal_override(true, value)
get:
return _horizontal_separation

# Underlying variable for [member horizontal_separation]
var _horizontal_separation: int = 0

# Update counter used in [_process] for the editor
var _update_counter_editor: int = 0

Expand Down Expand Up @@ -144,3 +166,13 @@ func _get_configuration_warnings() -> PackedStringArray:
warnings.append("All rows should be the same length")

return warnings


# Apply horizontal override to all child [HBoxContainer] rows based on [param on]
func _apply_horizontal_override(on: bool, value: int = 0) -> void:
var rows: Array[HBoxContainer] = _get_table_children()
for row: HBoxContainer in rows:
if on:
row.add_theme_constant_override("separation", value)
else:
row.remove_theme_constant_override("separation")

0 comments on commit 68e3ff9

Please sign in to comment.