Skip to content

Sliders.md

cfloutier edited this page Apr 27, 2024 · 8 revisions

Sliders are modified to have a better look than unity standard.

It adds

  • Options to define the label position
  • Options to write the value in the label
  • Min - Max limits drawn on bottom
  • a green line (just for the look)

image

Int or float

use the K2Slider or K2SliderInt, they share the same style and attributes. but the behavior is slightly different

UI Builder's Attributes

image

  • Label : if none the Label is hidden
  • Label On Top : if true label is located on top of slider, if false on the left
  • Print Value : print values in the label image
  • Min Max Label : adds a line on the bottom to show min and max values.
    • use the x value, the real Min Max value will be printed there : image
    • use a formated string like cold-hot (separated with a -) image
  • Value : the startvalue
  • Min : The minimum value
  • Max : the maximum value

precise correction

like standard Unity Editor fields it can be finely adjusted by draging the label. image

Binding

It can be bound with a Setting<float> or ClampSetting<float> for K2Slider

and with Setting and ClampSettingInt for the K2SliderInt.

If you bind a ClampSetting, min and max properties are copied from the settings to the UI.

ex :

   public ClampSetting<int> int_item = new ClampSetting<int>("my_settings.int_item", -5, -10, 10);

   public void init(VisualElement panel)
   {
        panel.Q<K2SliderInt>("int_settings").Bind(int_item);
   }

Clone this wiki locally