ErnSur / UI-Toolkit-Plus

Boilerplate Code Generation, Tabs, Reorderable Manipulator, Built-in USS Exporter
MIT License
182 stars 8 forks source link

[FEATURE REQUEST] Template Code Gen #24

Closed Lachee closed 10 months ago

Lachee commented 1 year ago

It would be awesome if the code generation was able to understand templates. At the moment, it just puts it as a TemplateContainer, but i propose it does 2 things:

  1. Creates the template container field with a Template suffix
  2. Creates a typed field without said suffix and initializes it in the assign.

For example, it would go from:

    partial class ProvinceEditor
    {
        private Label title;
        private TemplateContainer areaDropdown;

        protected void AssignQueryResults(VisualElement root)
        {
            title = root.Q<Label>("Title");
            areaDropdown = root.Q<TemplateContainer>("AreaDropdown");
        }
    }

To:

    partial class ProvinceEditor
    {
        private Label title;
        private TemplateContainer areaDropdownTemplate;
        private AreaDropdown areaDropdown;

        protected void AssignQueryResults(VisualElement root)
        {
            title = root.Q<Label>("Title");
            areaDropdownTemplate = root.Q<TemplateContainer>("AreaDropdown");
            areaDropdown = new AreaDropdown(areaDropdownTemplate);
        }
    }

Not entirely sure if the template is even required to be exposed outside of the AssignQueryResults function.

ErnSur commented 11 months ago

Hi @Lachee Do you have any ideas on how would that feature work exactly? Some things to consider with this.

Example logic: If we need to create a field for a TemplateContainer

I would also like to see a project where this feature is actually useful. In my experience all of the .gen.cs types I used required initialisation. For this reason I most often used constructors with more parameters.

ErnSur commented 10 months ago

No further input- closing