Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centering a scaled container centers relative to the original size of the container #85091

Closed
Starkandco opened this issue Nov 19, 2023 · 5 comments

Comments

@Starkandco
Copy link

Godot version

v4.1.3.stable.official [f06b6836a]

System information

Godot v4.1.3.stable - Windows 10.0.22621 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3070 (NVIDIA; 31.0.15.3699) - Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz (16 Threads)

Issue description

I am expecting a scaled container to be correctly centered relative to its scaled size using center for anchor preset and alignment but it seems to retain the center coords for the original size

Steps to reproduce

Tested with box containers:

  1. Set up control for full screen size
  2. Add box container
  3. Increase scale on box container
  4. Center box container alignment and anchor preset

Expected:
Center is relevant to scaled container

Actual:
Center is relevant to original container size

Expected result would be similar to manually increasing container size and centering as below:
image

Actual result is offset:
image

Minimal reproduction project

image

@Starkandco
Copy link
Author

Starkandco commented Nov 19, 2023

This also affects other canvas items - tested with scaled panel, label, control in place of container

@Sauermann
Copy link
Contributor

Sauermann commented Nov 19, 2023

godot/scene/gui/control.cpp

Lines 1227 to 1229 in 80de898

case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
data.offset[0] = x * (0.5 - data.anchor[0]) - new_size.x / 2 + parent_rect.position.x;

new_size is in the local coordinate system of the Control node.
parent_rect.position is in the coordinate system of the parent Control node.
Mixing different coordinate systems is never a good idea.

@Starkandco
Copy link
Author

@Sauermann @AThousandShips I think this is a duplicate of

#19068

Also I see a similar looking issue opened 14d ago

#85668

I guess mine and the more recent ticket can be closed

@Calinou
Copy link
Member

Calinou commented Dec 16, 2023

Thanks for the report! Consolidating in #19068.

@Calinou Calinou closed this as completed Dec 16, 2023
@cidwel
Copy link

cidwel commented Dec 16, 2023

I think this might be also related:
#56746

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants