B4A Library Wheel by B4A Class

The new version 2 is amazing !
Here is the wheel library converted to b4a class at a very short time, and with better handling and options for the user/developer.

Documentation is within the class, a demo program is running the class - all very simple.

Applause to Erel :icon_clap:

Edit: updated to include a ReadWheel method, which I found necessary as well.
SetByIndex corrected to refer to the original array index.

Edit: Ver 2 can be used as custom view (starting b4a ver. 2.71) and also by code definition. If by designer - define the size of wheel, the properties of the text and then by code use "SetObject" to input the numbers of the wheel. The height of the internal labels is by default 1/3.2 of the view's height, or the "Text" field if you want it otherwise (or change by code using "SetStep").
If defined by code you have to use "initialize", then "CodeCreationView" and then add the view to its parent. In that case several display parameters are the defaults but can be changed by property subs.
To my opinion - it is much easier to define the wheel now by the designer :)(thanks Erel !). I wish it was possible to read the color of the lbl but it is writeable only...:(

Edit: I found a go around solution to define the color of the wheel as the color of the custom view in the designer, attached as ver. 2.1
Edit: Ver 2.2 enables definition of cyclic property in the designer. The text property may include 0,1 or 2 parameters, as defined in the following table:
table.png

Edit: Horizontal WheelView added, with the same properties. The table above refer to Width instead of Height.
Edit: Both vertical wheel and horizontal wheel were updated to use resumeable subs.

Note: The wheel is very sensitive to delay parameter (when setting it to show a value). You have to check the performance with Release mode.
 

Attachments

  • scsh.png
    scsh.png
    34.7 KB · Views: 1,950
  • Hscreen.png
    Hscreen.png
    21.6 KB · Views: 736
  • wheelview_3.zip
    18.3 KB · Views: 394
  • HWheelView_3.zip
    14.3 KB · Views: 338
Last edited:

TrisectDevelopment

Active Member
Licensed User
Longtime User
I tried this in my App on the Wheel is working okay but not the _Roll event.
It just do not get called.

I implement the Wheel.bas file and use the following code:
B4X:
Dim wSetKilometer1 As Wheel
B4X:
wSetKilometer1.Initialize("main",svstep,True,"wc1", str1)
Activity.AddView(wSetKilometer1.AsView,0,170dip,80,svheight)
wSetKilometer1.SetAppearance(Colors.Yellow,Colors.Blue,16,Gravity.CENTER)

B4X:
Sub wc1_Roll(stepval As String)
    ToastMessageShow(stepval, False)
End Sub

The wc1_Roll event does not fire.
 

derez

Expert
Licensed User
Longtime User
Please check with version 2.1
(Usually you put event name like the object name so you can remember which is what, but it should work like you did).
The initialization in ver 2.1 is different.
Also - are you calling the class from Main or other activity ?
 
Last edited:

derez

Expert
Licensed User
Longtime User
No I'm not calling it from main, but from another activity.
Then the initialize command should have the activity name instead of "main".
B4X:
wSetKilometer1.Initialize("main",svstep,True,"wc1", str1)
 

Eldritch

Member
Licensed User
Longtime User
Hi Derez

In v2 how do you set cyclic when using the designer?

' cyclic - if the wheel is a loop or a line.

/Eldritch
 

derez

Expert
Licensed User
Longtime User
In the following code from the class:

B4X:
'Run by designer only
Private Sub DesignerCreateView(base As Panel, Lbl As Label, Props As Map)'ignore
mp = base
If Lbl.Text <> "" Then Wwheelstep = Lbl.text Else Wwheelstep = Lbl.Height/3.2
Wcyclic = Lbl.Visible
...
The Cyclic variable is set by the visibility of the label but this property does not exist in the designer, the visibility is for the base panel.
So currently there is no way to set non cyclic by the designer, since the default is true.
I'll have to modify it a little to add the functionality...
 

derez

Expert
Licensed User
Longtime User
Ver 2.2 provides addition to enable definition of cyclic in the designer, by this table:
table.png
 

Dario126

Member
Licensed User
Longtime User
iPhone Spinner for dates, etc

Just added an example with even more padding (more useful for a lists of items that I have in mind than dates).

Also, I've split the 9-patches up so the thin middle bar can be made thinner/bigger depending on the font size you pick.

For the app in mind, I alread have a basic list that shows 7 items at any time in the bottom half of the screen.

Finally, I fixed a leak in the original code that did not remove old labels when you update any of the label properties (eg colour or style) - this is only visible on transparent labels that then overlap.

Allan

This is beautiful upgrade on also very useful class.
Any pointers how to incorporate this into dialog, maybe inside custom dialog like BetterDialog http://www.b4x.com/android/forum/threads/lib-betterdialogs.30739/#content
 

Dario126

Member
Licensed User
Longtime User
I have seen that one, and your pointer to that is probably ok. Probably easiest way to "redesign" that one.

At first I disregarded because back panel was black, and fixed with no sub for changing. Code is not really commented and I was discouraged at first to change it. With some effort I was able to redesign it, but it's still not even close to your iPhone imitation. I still need to make paddings, and try some (blue transparent) panels like in your example ..

Anyhow, tnx ..

Btw. control like yours or Klauses, I would expect that is natively part of b4a .. unfortunately it's not :=(
 

luke2012

Well-Known Member
Licensed User
Longtime User
The new version 2 is amazing !
Here is the wheel library converted to b4a class at a very short time, and with better handling and options for the user/developer.

Documentation is within the class, a demo program is running the class - all very simple.

Applause to Erel :icon_clap:

Edit: updated to include a ReadWheel method, which I found necessary as well.
SetByIndex corrected to refer to the original array index.

Edit: Ver 2 can be used as custom view (starting b4a ver. 2.71) and also by code definition. If by designer - define the size of wheel, the properties of the text and then by code use "SetObject" to input the numbers of the wheel. The height of the internal labels is by default 1/3.2 of the view's height, or the "Text" field if you want it otherwise (or change by code using "SetStep").
If defined by code you have to use "initialize", then "CodeCreationView" and then add the view to its parent. In that case several display parameters are the defaults but can be changed by property subs.
To my opinion - it is much easier to define the wheel now by the designer :)(thanks Erel !). I wish it was possible to read the color of the lbl but it is writeable only...:(

Edit: I found a go around solution to define the color of the wheel as the color of the custom view in the designer, attached as ver. 2.1
Edit: Ver 2.2 enables definition of cyclic property in the designer. The text property may include 0,1 or 2 parameters, as defined in the following table:
View attachment 23597

@derez is it possible to let the user choose the wheel value using Click event instead of TIP event ?
 

luke2012

Well-Known Member
Licensed User
Longtime User
iPhone Spinner for dates, etc

Just added an example with even more padding (more useful for a lists of items that I have in mind than dates).

Also, I've split the 9-patches up so the thin middle bar can be made thinner/bigger depending on the font size you pick.

For the app in mind, I alread have a basic list that shows 7 items at any time in the bottom half of the screen.

Finally, I fixed a leak in the original code that did not remove old labels when you update any of the label properties (eg colour or style) - this is only visible on transparent labels that then overlap.

Allan

Hi @AllanH,
my compliments! It looks great!
I understood that the wheel handle the _Roll event.
It's possible to handle also the _click or _touch event ?
 
Last edited:

derez

Expert
Licensed User
Longtime User
It's possible to handle also the _click or _touch event ?
You can modify the class to have a click event on the labels of the wheel, though I don't see a use for such method since the data had been provided when the wheel stopped.
Change this :
B4X:
Private Sub putlabels(n As Int)
For i = 0 To n-1
    lbw.initialize("lbl")
....

and add this:
B4X:
Private Sub lbl_click
If SubExists(Wmodule, WEventName & "_Roll") Then
  CallSub2(Wmodule,WEventName & "_Roll",Wvalues(newposition/Wwheelstep))
End If
End Sub

If you plan this event to do something else, I think you should not since the program will not know if you start a roll or a click.
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
You can modify the class to have a click event on the labels of the wheel, though I don't see a use for such method since the data had been provided when the wheel stopped.
Change this :
B4X:
Private Sub putlabels(n As Int)
For i = 0 To n-1
    lbw.initialize("lbl")
....

and add this:
B4X:
Private Sub lbl_click
If SubExists(Wmodule, WEventName & "_Roll") Then
  CallSub2(Wmodule,WEventName & "_Roll",Wvalues(newposition/Wwheelstep))
End If
End Sub

If you plan this event to do something else, I think you should not since the program will not know if you start a roll or a click.

Thanks @derez!
My need is to let the user to select a value with the roll event and than "confirm" the selected value with a click.
Doing this the user click only hide the iWheel and the value selected il stored on a visible panel.
 

derez

Expert
Licensed User
Longtime User
put your confirmation code in a sub (in the calling module) and callsub this from sub lbl_click instead of what I wrote.
B4X:
Private Sub lbl_click
If SubExists(Wmodule, WEventName & "_Confirm") Then
  CallSub(Wmodule,WEventName & "_Confirm")
End If
End Sub
 
Last edited:

holdemadvantage

Active Member
Licensed User
Longtime User
a beautiful view, great for user input! Entering numbers by user interaction always works fine, but setting a value programatically can lead to unexpected results: the displayed value differs from the value, which was passed by the method call (often, not always).

I could not dive deep into the program logic, just tested the view with three wheels (each with a range of 0-9). When i tried to set the three wheels programatically to 1 0 0, sometimes 190 or 200 or 101 or 099 was displayed.

Same results for me, method .SetByIndex and .SetByValue seems not working correctly ( i am trying THIS example), anyone has solved this issue?
 

derez

Expert
Licensed User
Longtime User
method .SetByIndex and .SetByValue seems not working correctly ( i am trying THISexample)
The examples use an old version of the class. Please check again with the last version.
 
Top