B4J Library [B4X] [XUI] xRotaryKnob class

The xRotaryKnob Class does also exist as a B4X libary.
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 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.
ALLWAY snaps allways during moving, the lower green knob.
NEVER doesn't snap at all, displays the current value, the upper right knob,

The zip file contains three folders, one for each platform (B4A, B4i and B4J).
There is only one xRotaryKnob.bas file in the B4J folder.
For the two other platforms, there is a relative link, in the IDE, to the file in the B4J folder.

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


jxRotaryKnob
  • 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)
  • Version: 1.6
 

Attachments

  • xRotaryKnob_V1_6.zip
    110.7 KB · Views: 98
  • xRotaryKnob.b4xlib
    5.4 KB · Views: 93
  • xRotaryKnob.xml
    9.3 KB · Views: 88
Last edited:

klaus

Expert
Licensed 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
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
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
 
Top