B4J Library [B4X] [XUI] xRotaryKnob class

klaus

Expert
Licensed User
The xRotaryKnob Class does also exist as a B4X libary.
It works on all three products: 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: 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.5
 

Attachments

Last edited:

Cableguy

Expert
Licensed User
Can you add the possibility to use an image for the knob itself (with transparent background of course)
 

klaus

Expert
Licensed User
The xRotaryKnob has been updated to Version 1.1.

Added CustomKnob and CustomKnobFileName properties.
Allows to use a bitmap for the knob image.

Files updated in the first post.
 

GMan

Well-Known Member
Licensed User
+10
 

GMan

Well-Known Member
Licensed User
Last edited:

GMan

Well-Known Member
Licensed User
Could it be a good idea to establish a database (here) with those simple graphical things, ready for usw for B4X ?
 

klaus

Expert
Licensed User
Could it be a good idea to establish a database (here) with those simple graphical things, ready for usw for B4X ?
What exactly do you mean?
If you are speaking about button images, users can post images in this thread and I will move those to the first post.
 

hears

Active Member
Licensed User
this libary can use in B4A ?
 

klaus

Expert
Licensed User
this libary can use in B4A ?
Sure !
If you download the xRotaryKnob_v1_3.zp file, you find a B4A, a B4i and a B4J demo project.
Copy the xRotaryKnob.b4xlib into the B4X subfolder in a AdditionalLibraries folder with a structure like this:

1579360415067.png


If you use the B4X Help Viewer, copy the xRotaryKnob.xml file into the B4XlibXMLFiles subfolder.
 

hears

Active Member
Licensed User
thanks for replay, how to change background image ? this code cannot work:

xRotaryKnob3.CustomKnob=True
xRotaryKnob3.CustomKnobFileName("knob1.png")
 

klaus

Expert
Licensed User
You are right, there was an error in the class code.

In your example in post #17, this line is wrong:
xRotaryKnob3.CustomKnobFileName("knob1.png")
it must be:
xRotaryKnob3.CustomKnobFileName = "knob1.png"

The class has been updated to version 1.4 in the first post.
 

hears

Active Member
Licensed User
thank you,it is working now ✌



You are right, there was an error in the class code.

In your example in post #17, this line is wrong:
xRotaryKnob3.CustomKnobFileName("knob1.png")
it must be:
xRotaryKnob3.CustomKnobFileName = "knob1.png"

The class has been updated to version 1.4 in the first post.
i
 
Top