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 ClampSettingInt int_item = new ClampSettingInt("my_settings.int_item", -5, -10, 10);
   public ClampSetting<float> float_item = new ClampSetting<float>("my_settings.float_item", 5, 0, 100);

   public void init(VisualElement panel)
   {
        // min max values are taken from the settings
        panel.Q<K2SliderInt>("int_settings").Bind(int_item);
        panel.Q<K2Slider>("float_settings").Bind(settings.float_item);
   }

uss classes

  • the buttons uses the .k2-slider class. The whole list of subclasses are located into K2Slider.uss

Thoses classes mainly overload defaults uss values from the standard Slider.

What is inside the K2Compass..

This control is deeply inspired from the tutorial Nj Tutorial

thanks for this excellent tutorial. I've learn much there.

The controler is mainly a modified version of the Standard Unity Slider. The Label is moved depending on the label_on_top value. It has been tricky to make without anoying the rest of default Slider Behavior. There were many case of flickering from left to top. so take care if you want to do modifications of the codes.

The green line is added using a Visualelement that is aligned with the Dragger Element. It is located inside the round center line to avoid flickering.

The Min - Max Is a new labels added on bottom.

Clone this wiki locally