Open nongvantinh opened 3 months ago
I'm designing a custom button, but when I use PanelContainer
as its parent, I cannot set the anchor to Full Rect because the container controls its children.
I switched to using NinePatchRect
as the parent, which allows me to set the anchor of the button. However, using Patch Margin also forces a minimum size for the NinePatchRect
.
I fallback to the button, I used a theme override for the normal Button and used StyleBoxTexture
just as with PanelContainer
. However, this again imposes a minimum size.
If I only want to retain some corners and edges of the texture, I must set the minimum size for the node using it. I believe this is a flaw in the design.
Project Description
I am working on a project in Godot that requires creating responsive and scalable UI elements that retain their visual integrity across various screen sizes and resolutions. The NinePatchRect node is a key tool in this process, as it allows for creating UI elements with defined corners and edges that scale without distortion. However, the current limitations in defining corner and edge regions, combined with a lack of advanced control over texture behavior during scaling, have made it challenging to achieve the desired visual quality.
Problem or Limitation
The current implementation of NinePatchRect presents two main challenges:
Corner and Edge Integrity: It's difficult to define and maintain the exact shapes and proportions of corners and edges during scaling. This often results in distorted corners or misaligned edges, which can compromise the visual consistency of UI elements.
Limited Slicing Options: The options for controlling how the center and edges of the texture are stretched or tiled during scaling are limited. This makes it challenging to achieve the desired appearance, especially in complex UI designs that require more nuanced control over these areas.
https://github.com/user-attachments/assets/253b8a2b-a99b-418b-b28f-93201b480439
Feature / Enhancement Description
To address these issues, I propose an enhancement to the NinePatchRect node that combines more precise control over the corner and edge regions with advanced slicing options for the texture. This enhancement would include:
Pixel-Perfect Corner and Edge Control:
Advanced Slicing Options:
Visual Guides in the Editor:
Proposal Implementation
The proposal would involve extending the existing NinePatchRect node with new properties and tools within the editor.
Properties:
Corner and Edge Control:
corner_size_top_left: int
(in pixels)corner_size_top_right: int
(in pixels)corner_size_bottom_left: int
(in pixels)corner_size_bottom_right: int
(in pixels)edge_size_top: float
(percentage of texture height)edge_size_bottom: float
(percentage of texture height)edge_size_left: float
(percentage of texture width)edge_size_right: float
(percentage of texture width)Advanced Slicing Options:
center_stretch_mode: enum {Uniform, Horizontal, Vertical, None}
center_stretch_ratio_horizontal: float (0.0 - 1.0)
center_stretch_ratio_vertical: float (0.0 - 1.0)
center_tile_pattern: enum {Repeat, Mirror, StretchToFit}
center_tile_min_size: Vector2
center_tile_max_size: Vector2
Pseudo-Code:
Workaround
Currently, achieving this functionality requires complex and time-consuming workarounds, such as manually adjusting margins and using custom scripts to handle advanced slicing. However, these methods are not only cumbersome but also prone to errors, particularly when dealing with dynamic resizing in-game.
Core Justification
This enhancement should be part of the core engine because it addresses a critical need in UI design: maintaining visual consistency and flexibility in scalable elements. Integrating these features directly into the NinePatchRect node will make it significantly easier for developers to create high-quality, responsive interfaces without relying on external plugins or custom scripts. This functionality is essential for any project that involves complex UI design, making it a valuable addition to the core engine.