Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

How do we create a FloatInput (FloatField without label)?

Discussion in 'UI Toolkit' started by Vapid-Linus, Aug 7, 2019.

  1. Vapid-Linus

    Vapid-Linus

    Joined:
    Aug 6, 2013
    Posts:
    64
    How do we create float field without a label?

    Looking at how FloatField does it, it uses a FloatInput:


    However, we do not have access to the FloatInput:

    Code (JavaScript):
    1. <FloatInput text="123" />
    My use case at the moment is creating a ranged slider, which looks like the one created by the Range attribute:


    You can see the little input field to the right of the slider. That's what I'm trying to create.

    The current Slider tag creates a slider without the input field:

    Code (JavaScript):
    1. <VisualElement class="row">
    2.     <Slider label="Speed Loss Per Level" binding-path="SpeedLossPerLevelFactor" class="grow" />
    3.     <FloatInput binding-path="SpeedLossPerLevelFactor" class="grow" />
    4.   </VisualElement>
    5.  
    So how do we create a float input field without a label? Why is the FloatInput class an internal class for FloatField?

    Edit:
    My temporary "solution" to the slider problem is to just display a label after it. Doesn't look as good as the intended input field and it's not editable, so it's not a perfect solution but works for me. I also round mine to one decimal, but here's my solution in case it's useful for someone:

    template
    style
    custom editor
     
    Last edited: Aug 7, 2019
  2. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    101
    Hi,

    You can try to create a FloatField without a label, this should give you the FloatInput as desired.
     
  3. fumobox

    fumobox

    Joined:
    Oct 19, 2014
    Posts:
    2
    I solved it ;)

    Code (JavaScript):
    1.  
    2. xmlns:engine="UnityEngine.UIElements"
    3. xmlns:editor="UnityEditor.UIElements"
    4.  
    5. <editor:FloatField name="param1"/>
    6.  
    Use "editor", not "engine".
     
unityunity