Skip to content

GetBindableChilds ignores bindable children from template files #20

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

Closed
Hellfim opened this issue May 31, 2023 · 1 comment · Fixed by #21
Closed

GetBindableChilds ignores bindable children from template files #20

Hellfim opened this issue May 31, 2023 · 1 comment · Fixed by #21
Assignees
Labels
bug Something isn't working

Comments

@Hellfim
Copy link
Contributor

Hellfim commented May 31, 2023

Method GetBindableChilds from VisualElementExtensions incorrectly handles cases with bindable elements in templates. Suppose there is an empty scene with 1 GameObject called View and 2 attached components (UI Document and TestCaseView). If one would run such scene and click THE BUTTON he would see a "Normal button pressed" in the console, however if he clicks on a pink background there is no "Background button pressed" in the console.
Listing of the files is provided below.

WindowContainer.uxml:

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <ui:VisualElement name="window-root" style="flex-grow: 1;">
        <UnityMvvmToolkit.UITK.BindableUIElements.BindableButton command="BackgroundButtonCommand" name="window-closer" class="0; 0; 0;" style="position: absolute; top: 0; left: 0; bottom: 0; right: 0; background-color: rgb(236, 166, 166);" />
        <ui:VisualElement name="content-container" contentContainer="true" picking-mode="Ignore" style="flex-grow: 1; align-items: center; justify-content: space-around;" />
    </ui:VisualElement>
</ui:UXML>

TestCaseWindow.uxml:

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <ui:Template name="WindowContainer" src="project://database/Assets/TestCase/WindowContainer.uxml?fileID=9197481963319205126&amp;guid=54cc8b8584dd8494a83f70ca4058d5b4&amp;type=3#WindowContainer" />
    <ui:Instance template="WindowContainer" style="flex-grow: 1;">
        <UnityMvvmToolkit.UITK.BindableUIElements.BindableButton command="NormalButtonCommand" text="THE BUTTON" name="ok-button" style="width: 300px; height: 200px; font-size: 50px;" />
    </ui:Instance>
</ui:UXML>

TestCaseViewModel.cs:

    public class TestCaseViewModel : IBindingContext
    {
        public ICommand NormalButtonCommand { get; }
        public ICommand BackgroundButtonCommand { get; }

        public TestCaseViewModel()
        {
            NormalButtonCommand = new Command(() => Debug.Log("Normal button pressed"));
            BackgroundButtonCommand = new Command(() => Debug.Log("Background button pressed"));
        }
    }

TestCaseView.cs:

    public class TestCaseView : DocumentView<TestCaseViewModel>
    {
    }
@Hellfim Hellfim added the bug Something isn't working label May 31, 2023
@Hellfim
Copy link
Contributor Author

Hellfim commented May 31, 2023

Fix should be applied to logic which evaluates VisualElement's children in VisualElementExtensions:

- 27            var itemChildCount = visualElement.childCount;
+ 27            var itemChildCount = visualElement.hierarchy.childCount;

29            for (var i = 0; i < itemChildCount; i++)
30            {
- 31                GetBindableElements(visualElement[i], bindableChilds);
+ 31                GetBindableElements(visualElement.hierarchy[i], bindableChilds);
32            }

- 124            var itemChildCount = visualElement.childCount;
+ 124            var itemChildCount = visualElement.hierarchy.childCount;

126            for (var i = 0; i < itemChildCount; i++)
127            {
- 128                GetBindableElements(visualElement[i], elements);
+ 128                GetBindableElements(visualElement.hierarchy[i], elements);
129            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants