B4J Library [B4X] [XUI] xRotaryKnob class

The xRotaryKnob Class is a B4X libary.
NEW The demo project is a B4XPages project.
The zip file contains the B4XPages project.
It works on all three platforms: B4A, B4i and B4J.
The xRotaryKnob.b4xlib and the xRotaryKnob.xml files are attached.
You need to copy the xRotaryKnob.b4xlib file to the AdditionlLibraries\B4X folder!
Donā€™t copy the xRotaryKnob.xml file to the AdditionalLibraries folder, copy it in another folder for all b4xlib xml files.
Example: AdditionlLibraries\B4XlibXMLFiles
The xRotaryKnob.xml file is for help purposes only and is useful with the B4X Help Viewer or the B4XObjectBrowser.
The xRotaryKnob.xml was generated with this tool: b4xlib - XML generation

After a request from HERE, I made it as a XUI challenge.
You can turn the button, and it snaps onto the nearest value.
A click in the middle selects the next value, a LonkClick in the middle selects the prevous value.
There are three snap modes:
AFTERMOVE snaps when the knob is released, upper left knob.
ALLWAYS snaps allways during moving, the lower green knob.
NEVER doesn't snap at all, displays the current value.

EDIT: 2024.01.04 Version 1.8
Added ValueChanged event when the Value is set by code

EDIT: 2023.08.10 Version 1.7
Added ValueChanged event for all SnapModes
Attention: Changed the Value variable type in the ValueChanged event from Int To Double
If you use the ValueChanged event you need to change it in your projects !
Amended problem of highlighted scale value
The demo project is now a B4XPages project !

EDIT: 2021.04.02 Version 1.6
Added HandleLineColor property
Amended error with mAngle0 and B4i

EDIT: 2020.06.23 Version 1.5
Added following properties:
SnapToZero when True snaps to ZERO after releasing the knob.
If there is no ZERO position in the scale, it snaps to the position nearest to ZERO.
The duration of the snap can be set with the SnapToZeroDuration property
SnapToZeroDuration in milliseconds.
Updated the Tag property according to Erels recommendation:
https://www.b4x.com/android/forum/t...lv-or-any-other-container.117992/#post-738358

EDIT: 2019.04.09 Version 1.4
Amended CustomKnobFileName property variable type.

EDIT: 2019.04.09 Version 1.3
Added Visible property.

EDIT: 2019.04.08 Version 1.2
Added Value property, allowing to preset the knob.

EDIT: 2019.01.27 Version 1.1
Added CustomKnob and CustomKnobFileName properties.
Allows to use a bitmap for the knob image.

upload_2019-1-27_18-19-30.gif


xRotaryKnob Version: 1.7
  • xRotaryKnob
    • Events:
      • ValueChanged (Value As Int)
    • Functions:
      • AddToParent (Parent As B4XView, Left As Double, Top As Double, Width As Double, Height As Double) As String
      • Class_Globals As String
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map) As String
        Base type must be Object
      • Initialize (Callback As Object, EventName As String) As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
    • Properties:
      • BackgroundColor As Int
        gets or sets the BackgroundColor property
      • CustomKnob As Boolean
        gets or sets the CustomKnob property
        CustomKnob with a Bitmap.
        The file must be in File.DirAsset
      • CustomKnobFileName As String
        gets or sets the CustomKnobFileName property
        CustomKnob Bitmap file name
        Valid only with CustomKnob = True
        The file must be in File.DirAsset
      • HighlightTextColor As Int
        gets or sets the HighlightTextColor property
      • KnobBorderColor As Int
        gets or sets the KnobBorderColor property
      • KnobColor As Int
        gets or sets the KnobColor property
      • Left As Double
        gets or sets the Left property
      • LineColor As Int
        gets or sets the LineColor property
      • OffsetAngle As Int
        gets or sets the OffsetAngle property
      • ScaleMaxValue As Int
        gets or sets the ScaleMaxValue property
      • ScaleMinValue As Int
        gets or sets the ScaleMinValue property
      • ScaleNbValues As Int
        gets or sets the ScaleNbValues property
      • SnapMode As String
        gets or sets the SnapMode property
        possible values:
        AFTERMOVE the knob snaps only when the knob is released, default value.
        ALLWAYS the knob snaps during moving.
        NEVER the knob doesn't snap at all, it displays the current position.
      • SnapToZero As Boolean
        sets or gets the SnapToZero property of the knob
        When True snaps to the ZERO position after releasing the knob
        If there is no ZERO position in the scale, it snaps to the position nearest to ZERO
        The duration of the snap can be set with the SnapToZeroDuration property
      • SnapToZeroDuration As Int
        sets or gets the SnapToZeroDuration property of the knob
      • TextColor As Int
        gets or sets the TextColor property
      • Top As Double
        gets or sets the Top property
      • Value As Int
        gets or sets the Value property, allows to preset the knob to a given value
      • Visible As Boolean
        gets or sets the Visible property
      • Width As Double
        gets or sets the Width property
        there is no Height property because the object is square
  • Author: Klaus CHRISTL (klaus)
 

Attachments

  • xRotaryKnob.zip
    213.8 KB · Views: 88
  • xRotaryKnob.xml
    9.3 KB · Views: 72
  • xRotaryKnob.b4xlib
    5.6 KB · Views: 35
Last edited:

klaus

Expert
Licensed User
Longtime User
The class has been updated to version 1.5 in the first post.

Added following properties:
SnapToZero when True snaps to ZERO after releasing the knob.
If there is no ZERO position in the scale, it snaps to the position nearest to ZERO.
The duration of the snap can be set with the SnapToZeroDuration property
SnapToZeroDuration in milliseconds.
Updated the Tag property according to Erels recommendation:
https://www.b4x.com/android/forum/t...lv-or-any-other-container.117992/#post-738358
 

james_sgp

Active Member
Licensed User
Longtime User
Hi,
I`m updating my existing B4i app that uses Rotaryknob, but i`m getting an error when compiling:

Error: ** BUILD FAILED **


The following build commands failed:
CompileC /Users/blank/Downloads/App\ Stuff/B4iBuildServer/UploadedProjects/<user id>/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_xrotaryknob.o /Users/blank/Downloads/App\ Stuff/B4iBuildServer/UploadedProjects/<user id>/B4iProject/b4i_xrotaryknob.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

I`m on B4i 7.2 & Xcode 12.5.

Not sure whats happened, appreciate any advice.
 

james_sgp

Active Member
Licensed User
Longtime User
Ok, I switched over to using the Class instead of the latest B4X library; and it's working again now. NOTE the latest class 1.5 also generates an error due to the MOD function on line 212.

James
 

klaus

Expert
Licensed User
Longtime User
It does not work with AFTERMOVE either.
I my mind there was no need to have the ValueChanged event because the knob snaps to a value on the scale and the result is clearly seen.
I will look at it to see if i can add the ValueChanged event after the snap.
 

klaus

Expert
Licensed User
Longtime User
The xRotaryKnob library has been updated to version Version 1.7
Added ValueChanged event for all SnapModes
Attention: Changed the Value variable type in the ValueChanged event from Int To Double
If you use the ValueChanged event you need to change it in your projects !
Amended problem of highlighted scale value
The demo project is now a B4XPages project !
 
Top