Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Custom control NumberField

Discussion in 'UI Toolkit' started by visose, Feb 28, 2021.

  1. visose

    visose

    Joined:
    Nov 2, 2014
    Posts:
    28
    I'd like to make a custom NumberField similar to FloatField but for runtime use.
    I was looking into extending TextInputBaseField<TValueType>, but it looks like several members that need to be overridden are marked internal. The nested class TextInputBase in particular has its constructor marked as internal.

    Should I assume this class is not intended to be extended by users of this package? What would be the most practical approach to make this control?

    Just a note, since C# 7 you can use 'private protected' private protected - C# Reference | Microsoft Docs to keep protected members not show up outside the assembly.
     
  2. visose

    visose

    Joined:
    Nov 2, 2014
    Posts:
    28
    For now I've implemented it extending TextField. No the most elegant approach but will do for the time being.
     
  3. digital-void

    digital-void

    Joined:
    May 7, 2018
    Posts:
    8
    I tried the same ... but failed due to the same reasons as visose with the Unity 2021.2.1f1 version.
    I need a NumericalUnitField : TextInputBaseField<float> .... with databinding, input filtering and some conversion etc
    For example: Why is the ctor of TextInputBaseField<T>.TextInputBase set to internal. Why?
    It kind of seems that we are not supposed to create custom UI Controls.
    @visose - In my opinion it wouldn't help to set the internal stuff to private protected - if I compile the assembly myself couldn't I just put my custom code in the namespace UnityEngine.UIElements and achieve the same?
    I don't get why this class has to be private and its ctor set to internal ... what about just have it's member in the Textinput protected?

    I will try to extent TextField as well - but that everything ist set to private and not to protected doesn't leave much room for hope.