-
Notifications
You must be signed in to change notification settings - Fork 0
Compass.md
The Compass is used to gives and set the heading direction

-
value : float angle. the heading value in degrees [0-360]
-
angle-range : float angle, default is 90°. the visible angle range = (center +/- angle-range) ex : with 200° :
it could be useful for larger windows -
interactive : boolean. if true the user can drag the compass to choose the direction. The compas can be used as infortive or interactive.
- the buttons uses the
..k2compasclass. The whole list of subclasses are located into K2Compas.uss
you can change the lines rendering using this set of privates options :
--center-line-width: 1;
--center-line-color: rgb(255, 255, 255);
--line-width: 2;
--line-color-1: rgb(145, 145, 145);
--line-color-2: rgb(104, 104, 104);
--line-color-3: rgb(46, 46, 46);
--line-y1: 30;
--line-y5: 25;
--line-y10: 20;
--line-y45: 25;The "center line" is the control center There are 3 levels of lines : 1°, 5°, 10° and 45°. The y value is compued from the bottom of the control.
others uss classes are used for inner labels and main control frame
It can be bound with a Setting<float> or ClampSetting<float>
ex :
public ClampSetting<float> heading = new ClampSetting<float>("my_settings.heading ", 90, 0, 360);
public void init(VisualElement panel)
{
panel.Q<K2Compas>("heading_compas").Bind(heading);
}This control is my favorite. It's the final and more difficult I wanted to code. I've learned much from the main K2Slider and I could write something more complex.
The Control is divided into 3 layers
- The lines : Where Lines are rendered using the Unity Toolkit VectorApi
- the texts : Where label are dynamically added using a factory of buttons and labels
- the shadow : a simple bitmap used to darken the border. (just because it's nicer)
The Lines are dynamically positioned in the function void Draw(MeshGenerationContext ctx)
On the whole with of the control is positionned each line at each value change. The performance is quite good, I've not met any lag using it. Vector Api is quite excellent.
The texts are buttons (For cardinals points N NE S etc...) and simple Labels. They are position using the same logic as lines in void setUpLabels(). I've add to write a little factory to avoid creating new VisualElements. It keeps used Elements in simple cache memory. Without that there were severe performance issues.