Implement runtime UI workflow and editor integration#819
Conversation
adriengivry
left a comment
There was a problem hiding this comment.
Found a bunch of issues that I reported to you directly on Discord.
Didn't dive into the code yet, as it's subject to change.
Some design issues to figure out:
Transformshould be "adaptive", depending on the context (2D/3D).- When in 2D mode, width/height/anchor preset/anchor pivot should be displayed
- When in 3D mode, nothing should change from what was previously shown
- There should be no need for an extra component, the transform should store 2D-related properties under an
std::optionaldata struct.
- Font rendering: currently fonts are rasterized with a fixed font size, so scaling a font will lead to blurry text. This could be fixed by implemented either SDF or dynamic glyph rendering. Dynamic glyph might be easier for now.
CText::m_textshould be displayed as a multiline string. Right now it's not possible to add line breaks in texts.
Some bugs I found so far:
- Anchor presets not working properly (partially addressed, the bounds in scene view are rendering incorrectly)
- Constant-size/scale with screen size issue, if I set the Canvas to 1920x1080, and add an image of size 1920x1080, it doesn't exactly fit the screen. When using scale with screen size (which should be default), we should be able to choose when the ratio is mismatching, to either match Width or Height, shrink, or expand. (see Unity documentation)
- When using multiple Canvas, composition order should be based on their position in the hierarchy.
The reported bugs have been fixed. I also took the opportunity to fix a few other issues that hadn't been reported yet and refactored parts of the code to make it cleaner and more maintainable. I improved the way Clay is used so that more of the 2D element management is handled by the library itself. A number of other changes were made as well. The commit history should give a good overview of the modifications and additions, so the details can be found there. Overall, the PR is in much better shape now |
Description
CCanvas,CTransform2D,CImage,CText.CLayoutGroup,CHorizontalLayout,CVerticalLayout.controlChildrenWidth/Heightsizing.Related Issue(s)
Fixes #631
Review Guidance
CLayoutGroup(controlChildrenWidth/Height).CTransform2Dstretch presets and inspector behavior.CText/Fontmaterial path (EnsureEmbeddedMaterial+ color override).Reviewer Notes (Key integration details)
1) Layout behavior (
CLayoutGroup)controlChildrenWidth/Heightnow effectively writes computed sizes to supported child UI components (CImage,CTextextents,CTransform2Dsize).2) Dedicated layout components
CHorizontalLayoutandCVerticalLayoutare concrete specializations ofCLayoutGroup.3) Transform2D anchor/stretch presets
HORIZONTAL_STRETCH_TOP/MIDDLE/BOTTOMVERTICAL_STRETCH_LEFT/CENTER/RIGHTSTRETCH_BOTH4) Text/Font material flow
Fontnow owns an embedded UI material (EnsureEmbeddedMaterial/GetEmbeddedMaterial).CTextreuses this embedded material and only overrides dynamic text color.5) Editor rendering mode behavior
GameView: always includes UI in screen space.SceneView: always includes UI; toolbar toggle switches screen-space mode on/off for Scene View display.6) Lua exposure
CHorizontalLayoutandCVerticalLayout.Transform2Danchor preset enum values.Screenshots/GIFs
AI Usage Disclosure
Generated new code / Refactored code / Debugging
Build Warnings
The changes generate build warnings, specifically 29 new warnings originating from the
Claylibrary itself.These correspond to typical internal conversions on MSVC side: pointer to
uint32_t(hash),doubletofloat,float/__int64toint32_t.These are true narrowing warnings, but not relevant to our current integration as long as we remain within normal layout/UI sizes.
Note
You can find an Overload project on the
631-demobranch of my Overload fork. It includes scenes and scripts used to test the Lua API, as well as the added and modified source code.Checklist