8000 Fixed layout issue when card spacing is lower than 1. · BraindeadBZH/godot_card_engine@2be2003 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Fixed layout issue when card spacing is lower than 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
BraindeadBZH committed Nov 17, 2021
1 parent 6d99ba3 commit 2be2003
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions _private/containers/hidden_pile/hidden_pile_private.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

[node name="HiddenPilePrivate" instance=ExtResource( 1 )]
script = ExtResource( 2 )

17 changes: 12 additions & 5 deletions addons/cardengine/container/abstract_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func _grid_layout(trans: CardTransform, grid_cell: int, card_size: Vector2):
row_width = _grid_columns * _grid_card_width * _grid_card_spacing.x
col_height = ceil(_store.count() / float(_grid_columns)) * height_adjusted * _grid_card_spacing.y
else:
row_width = _store.count() * _grid_card_width * _grid_card_spacing.x
row_width = _grid_card_width + _store.count() * _grid_card_width * _grid_card_spacing.x
col_height = height_adjusted * _grid_card_spacing.y

if _grid_expand:
Expand All @@ -287,24 +287,31 @@ func _grid_layout(trans: CardTransform, grid_cell: int, card_size: Vector2):
if col_height > rect_size.y || _grid_columns > 0:
rect_min_size.y = col_height

spacing_offset.x = (_grid_card_width * _grid_card_spacing.x - _grid_card_width) / 2.0
spacing_offset.y = (height_adjusted * _grid_card_spacing.y - height_adjusted) / 2.0
if _grid_card_spacing.x < 1.0:
spacing_offset.x = (_grid_card_width * _grid_card_spacing.x) / 2.0
else:
spacing_offset.x = (_grid_card_width * _grid_card_spacing.x - _grid_card_width) / 2.0

if _grid_card_spacing.y < 1.0:
spacing_offset.y = (height_adjusted * _grid_card_spacing.y) / 2.0
else:
spacing_offset.y = (height_adjusted * _grid_card_spacing.y - height_adjusted) / 2.0

match _grid_halign:
HALIGN_LEFT:
grid_offset.x = spacing_offset.x
HALIGN_CENTER:
grid_offset.x = spacing_offset.x + (rect_size.x - row_width) / 2.0
HALIGN_RIGHT:
grid_offset.x = spacing_offset.x + (rect_size.x - row_width)
grid_offset.x = rect_size.x - (row_width + spacing_offset.x)

match _grid_valign:
VALIGN_TOP:
grid_offset.y = spacing_offset.y
VALIGN_CENTER:
grid_offset.y = spacing_offset.y + (rect_size.y - col_height) / 2.0
VALIGN_BOTTOM:
grid_offset.y = spacing_offset.y + (rect_size.y - col_height)
grid_offset.y = rect_size.y - (col_height + spacing_offset.y)

var pos: Vector2 = Vector2(0.0 , 0.0)
# Initial pos
Expand Down

0 comments on commit 2be2003

Please sign in to comment.
0