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

Follow the CSS-style "top, right, bottom, left" order in methods that specify coordinates in 4 directions #2141

Closed
Calinou opened this issue Jan 18, 2021 · 5 comments

Comments

@Calinou
Copy link
Member

Calinou commented Jan 18, 2021

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

In classes such as Rect2 and StyleBoxFlat, there are methods that specify coordinates in all directions. A Godot-specific order is used:

  • Left
  • Top
  • Right
  • Bottom

Godot already uses the CSS order for methods whose parameters refer to individual corners (such as StyleBoxFlat::set_corner_radius_individual():

  • Top-left
  • Top-right
  • Bottom-right
  • Bottom-left

Therefore, this proposal is only about sides/directions, not corners.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Use an established de facto standard order such as the CSS direction order. This order similar to the current one (it's clockwise), except it starts at the top instead of the left. The four directions in order are:

  • Top
  • Right
  • Bottom
  • Left

For methods that specify 3 coordinates in the form of "top/sides/bottom", the order is:

  • Top
  • Sides
  • Bottom

I'm not sure if any methods that accept 3 directions exist in Godot, but it's worth checking for anyway.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For instance, turn Rect2's grow_individual() method signature:

grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom);

Into:

grow_individual(real_t p_top, real_t p_right, real_t p_bottom, real_t p_left);

This change will break compatibility and should be considered for 4.0 only, given that it's difficult to find it out naturally – scripts won't break after this change. Still, I think it's worth pursuing to get a more consistent API that reuses web developers' muscle memory 🙂

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, as this is a core API change.

Is there a reason why this should be core and not an add-on in the asset library?

This is a core API change.

@kleonc
Copy link
Member

kleonc commented Sep 13, 2021

In classes such as Rect2 and StyleBoxFlat, there are methods that specify coordinates in all directions. A Godot-specific order is used:

Left
Top
Right
Bottom

That's not Godot-specific order. It's the same for example in Android's Rect.

Godot already uses the CSS order for methods whose parameters refer to individual corners (such as StyleBoxFlat::set_corner_radius_individual():

Top-left
Top-right
Bottom-right
Bottom-left

Indeed such order is used but it's not CSS-specific. It's the same for example in Android's RoundRectShape (order of data in the outerRaddi/innerRadii arrays). So it's not like it's taken specifically from the CSS.

Use an established de facto standard order such as the CSS direction order.

I guess we could argue that Godot is already following an established de facto standard order such as the Android's direction order.

The thing is there are always many different approaches/standards and I'd say the question should be: which one of them makes the most sense to follow?

In this proposal I don't see actual arguments why the proposed order (top-right-bottom-left) is better than the current one (left-top-right-bottom). For me what's being proposed is to follow an arbitrarily choosen approach (CSS-like) just for the sake of following it.

Personally, I find the left-top-right-bottom order more intuitive because rectangles are usually defined by position (x, y) and size (width, height) in such order and kinda the same order is being reflected in the left-top-right-bottom order:

top-left corner + size left-top-right-bottom top-right-bottom-left
x left = x top = y
y top = y right = x + width
width right = x + width bottom = y + height
height bottom = y + height left = x

@YuriSizov
Copy link
Contributor

We actually don't follow any specific order in a lot of places, so for unification sake we can choose any single one of them.

@YuriSizov
Copy link
Contributor

As mentioned in godotengine/godot#52624 I think I agree with @kleonc, after some consideration. Left-top-right-bottom matches the X/Y order and the Rect definition order. It just makes more sense in terms of screen space and matches a lot of existing logic.

We probably still need to break compatibility in some places that don't use that order.

@aaronfranke
Copy link
Member

Left-top-right-bottom matches the X/Y order

In terms of X/Y order, the best for that would be left-right-top-bottom. This is the order I used for Input.get_vector in godotengine/godot#42976 (which shouldn't be changed btw, since it's kind of a superset of get_axis).

@akien-mga
Copy link
Member

We discussed this in a proposals review meeting and agreed to stick to Left Top Right Bottom, which seems to be the convention used in OpenGL (according to reduz) and which seems intuitive with regard to x/y/width/height as described by @kleonc.

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

No branches or pull requests

5 participants