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

Re-implement rendering/2d/options/ninepatch_mode or an equivalent in 4.x #10932

Open
Voxybuns opened this issue Oct 8, 2024 · 4 comments
Open

Comments

@Voxybuns
Copy link

Voxybuns commented Oct 8, 2024

Describe the project you are working on

A game that uses nine-slice panels to render UI elements with shapes other than rectangles and rounded rectangles.

Describe the problem or limitation you are having in your project

In Godot 4.3, I'm using a StyleBoxTexture to render some UI elements, like panels, using nine-slice textures in order to create elements with a squircle-like shape that cannot be recreated with a default stylebox.

However, if the resulting element is made to be too small to fit the entire texture, the appearance of the element will break:

Godot_v4 3-stable_win64_jqz4XWr3ke

If I want to be able to use this specific shape on elements of different sizes (like buttons), I'd need to create multiple variants of my texture at different scales, and create matching StyleBoxTextures, which is cumbersome.

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

In Godot 3.6, it's possible to set the rendering/2d/options/ninepatch_mode property to scaled, which allows the nine-slice texture to be rescaled based on the size of the element in such a way that the corners retain their aspect ratios, and the filling sections still behave as normal.

Godot_v3 6-stable_win64_5ivDlzRQDQ

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

The proposal would involve reintroducing this feature into Godot 4.x, either by making it a project wide setting, or by making it a per-stylebox setting.

Having such an option has been discussed in a previous proposal but was ultimately not added. I believe allowing the nine-slice texture to be rescaled would be really useful to better support UI designs that use custom shapes, as only one texture and one stylebox would be necessary to support a wide array of elements of different sizes.

While it is not appropriate for some art styles (for example pixel art games, or textures that integrate a border due to the loss of uniformity), making it an option would allow the end user to decide whether they would benefit from this change in behavior.

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

The only alternative I can think of is maintaining multiple styleboxes, which is not convenient.

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

This proposal is about solving a regression from 3.x to 4.x

@Voxybuns Voxybuns changed the title Re-implement rendering/2d/options/ninepatch_mode in 4.x Re-implement rendering/2d/options/ninepatch_mode or an equivalent in 4.x Oct 8, 2024
@sockeye-d
Copy link

This should be an definitely be an option on the StyleBoxTexture. IMO how it renders overlapping sections needs to be fixed, that is clearly wrong. I think it could have more utility with these options:

  • overlap: The default, to maintain backwards compatibility
  • shrink: the corners will maintain a 1:1 texel:pixel ratio unless they are taking up too much space, then they will shrink similarly to 3.x
  • clipped: it clips the corners so they don't overlap
  • scale_keep_aspect: Equivalent to how it works in 3.x, on two sides of the box the corners will take up the full space but the corners will keep their aspect ratio
  • scale: Like scale, but selecting this option will reveal another property, ratio. The corners will be scaled unevenly to fill ratio percent of the box

@Calinou
Copy link
Member

Calinou commented Oct 11, 2024

If this is only needed to emulate squircle corners (due to not being viable with textures that have borders), it might be worth implementing a squircle corner radius mode in StyleBoxFlat instead. This would allow for vector-based rendering as well, which would look good at any resolution and allow for more real-time customization.

@sockeye-d
Copy link

Hmm, maybe overhauling the StyleBoxFlat corner system to allow for the use of a Curve resource to drive the corner profiles would be better then? That seems like a different topic though, it would still not replace the StyleBoxTexture

@Voxybuns
Copy link
Author

If this is only needed to emulate squircle corners (due to not being viable with textures that have borders), it might be worth implementing a squircle corner radius mode in StyleBoxFlat instead. This would allow for vector-based rendering as well, which would look good at any resolution and allow for more real-time customization.

Well, I am using this to render squircles but nine-patch textures can emulate all kinds of shapes, really. ^^

My issue isn't really "I'd like a better way to render squircles" but "I'd like nine-patch textures to be more flexible again, like they used to be in 3.x"

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