-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add proper border support for UI nodes #5924
Comments
Previously attempted in #3991. |
I'm willing to revisit this at some point when #5513 is merged. I think one big concern was the amount of changes that was necessary in the UI rendering to implement it. Another concern for me was the anti-aliasing for borders which was implemented directly in the shader by fading the borders a little bit. As someone with limited experience writing rendering code, I'm down to try and write something that works, but I would prefer that it goes through thorough review to find the most optimal solution. #90 would offer a completely different and much more flexible approach to do this, but I think we would gain from having both be available since one is a simple way to define border properties while the other would be a full drawing API. |
Agreed, I'd be frustrated if the only way to draw simple borders was a canvas API. |
Also, first DioxusLabs/taffy#223 needs to be done, since it's not possible to differentiate between |
This could potentially be exposed by Taffy as an output, but it is possible to differentiate by referring to the input styles. Where the style is a pixel value this can be taken as-is. Where the style is a percentage, this can be resolved against the width of the parent node (as computed by Taffy) |
# Objective Implement borders for UI nodes. Relevant discussion: #7785 Related: #5924, #3991 <img width="283" alt="borders" src="https://user-images.githubusercontent.com/27962798/220968899-7661d5ec-6f5b-4b0f-af29-bf9af02259b5.PNG"> ## Solution Add an extraction function to draw the borders. --- Can only do one colour rectangular borders due to the limitations of the Bevy UI renderer. Maybe it can be combined with #3991 eventually to add curved border support. ## Changelog * Added a component `BorderColor`. * Added the `extract_uinode_borders` system to the UI Render App. * Added the UI example `borders` --------- Co-authored-by: Nico Burns <[email protected]>
@ickshonpe @JMS55 So, on the one hand I really want rounded corners. I want them NOW. However, I also realize that rounded corners are only useful within the context of a particular visual style. Specifically, the style of a web app, where most UI elements are flat-shaded. Since the advent of Material UI, most web sites, and some productivity apps, have converged on a particular look that has rounded corners. The Bevy editor mockups make liberal use of rounded corners, because it's trying to look like Unity. But many games will have a visual style that has no use for rounded corners (or shadows for that matter). A lot of games will use nine-patches, custom shaders, or other techniques to produce widgets that are novel and flashy. Rather than building in support for rounded corners in Bevy, we could consider a different option: custom ui materials. Someone building an editor is likely going to rely on a widget library that has an opinionated look, and this library could include custom shaders that render rounded corners and shadows. This means extra work for the widget author, but not much if there are examples showing how to do it. It won't be extra work for people actually using the widgets in their apps. If I had an example showing how to render rounded corners in a custom ui material, my problems would be solved :) And it wouldn't require a change to Bevy. Also, adding rounded corners and shadows to Bevy UI nodes entails a number of web-centric assumptions. For example, it assumes that shadows are not separate entities, but are an extension of normal UI nodes. But for someone building a widget library, it's not especially burdensome to add an extra entity for the drop-shadow, which is ordered so that it renders beneath the element. However, there's one aspect to all this that a custom material cannot easily provide: clipping. A custom material has no effect on child elements, so child elements can't be clipped to the rounded corners. However, I think the solution here is to allow custom clipping regions to be defined, because (again) not all games are going to use rounded corners, but some of them might want to use other shapes besides rectangles. |
I'd like to note that Bevy already supports most of what you would want to use for "game" UIs:
The only notable thing missing, out of all the things mentioned in this issue, are rounded corners. To me, they seem unimportant, given that Nine-Patch is supported. You can draw your own rounded corners and make them look how you like. Bevy already gives you everything to have fully-themable / skinnable UIs. I do agree with the previous comment that having a CSS-like rounded corner property feels needlessly web-centric, making assumptions about visual style that do not necessarily hold for most games. If you are making a quick and dirty UI, you don't need round corners. If you are making a pretty-looking UI, might as well go all the way and create Nine-Patch assets. Should we close this issue? |
I believe rounded corners are actually already supported as of #12500 |
Agreed, the important parts of this issue have already been tackled, I'll close it out. If we see the need for more advanced features like shadows or outlines, they probably warrant a separate issue as they are more controversial. |
I just want to add my agreement to closing this issue. I don't think Bevy should support shadows as a built-in feature, because:
|
What problem does this solve or what need does it fill?
Adding borders to UI elements is a common need, both for design and debugging.
Currently, we can only set the width of the border, but not the color. So it doesn't have a real visual effect at the moment.
What solution would you like?
Ideally, we should be able to define the following properties:
We could also think about supporting more complex styles, like dashed borders.
Once #5513 is merged, it probably makes sense to have all of these together in a style component.
Additionally, we could think about supporting outlines as well. These are essentially additional borders around the normal borders and can be used for accessibility features like visualizing keyboard focus.
What alternative(s) have you considered?
Currently it's sort of possible to make "borders" by wrapping the node in another node that is slightly larger and has a background color.
This approach is very limited and not ergonomic at all.
Additional context
The text was updated successfully, but these errors were encountered: