Import code animation kit

Hello,

maybe this is a stupid question but can i import the following code to xojo so that it creates the subclass , methods, properties etc. automatic?

[code]Class CountingLabel Inherits Label
Public Sub Add (Amount As Integer)
Self.Value = Self.Value + Amount
End Sub

Public Sub AnimationStep (Identifier As Text, Value As Double)
// Part of the AnimationKit.ValueAnimator interface.

Select Case Identifier
Case "Text"
  Self.Text = Str(Round(Value), "-0")
End Select

End Sub

Public Sub Subtract (Amount As Integer)
Self.Value = Self.Value - Amount
End Sub

Public Function Value () As Integer
Return Val(Self.Text)
End Function

Public Sub Value (Assigns NewValue As Integer)
If Task <> Nil And Not (Task.Completed Or Task.Cancelled) Then
Task.Cancel
Task = Nil
End If

Task = New AnimationKit.ValueTask(Self, "Text", Self.Value, Value)
Task.DurationInSeconds = 1
Task.Curve = AnimationKit.Curve.CreateEaseOut
Task.Run

End Sub

Private Property Task As AnimationKit.ValueTask
End Class[/code]

Create the Class (Class CountingLabel Inherits Label) manually, then
Select it in the Navigation pane,
Copy / Paste each atom (above)

and you will be done.

Now, with the correct license, you may try to paste the whole in a .bas (use the correct file extension for git files) and drop it into the navigation pane (not tested).

Edit:
You do not disclore the source (provenance) of the code above, so I can only guess an how to do.

this is from:
https://docs.thezaz.com/animationkit/3.0.0/AnimationKit.ValueAnimator/

i am trying to reproduce this but i can’t get it running…

Oh I just responded to your email and did not understand your question.

You should be able to do what @Emile Schwarz said. Create the class, set the Super to Label, then click the Interfaces button and choose AnimationKit.ValueAnimator. Then you can copy and paste each method into your navigator/sidebar. You may have two AnimationStep methods at that point, so delete the empty one.

It’s just a quick and dirty example of what the ValueAnimator can do, I’d have packaged it up as a usable class if I expected people to actually use it for something.

Thanks Thom for your mail and reply…

so now i set up the subclass as you wrote, dragged an instance to my window and then?

Do i have to create a value animator?

if i run, i get:

CountingLabel.Value, line 1
Not enough arguments: missing Double value for parameter “Time”
If Task <> Nil And Not (Task.Completed Or Task.Cancelled) Then

CountingLabel.Value, line 1
Undefined operator. Type Int32 does not define “Or” with type Boolean
If Task <> Nil And Not (Task.Completed Or Task.Cancelled) Then

Ah, bad example code. Change If Task <> Nil And Not (Task.Completed Or Task.Cancelled) Then to the simpler If Task <> Nil Then because it’s perfectly safe to cancel a task that is already finished or cancelled.

thanks, it runs now … but

say, my countinglabel has text 100

and i want on my button action to count down to 0, what code do i have to put in my button.action?

CountingLabel1.Value=100 CountingLabel1.Subtract(100)

does not work? sorry, if i am too stupid to understand how this works…

No, that won’t work because you’re setting Value up to 100, then immediately setting it back down to 0. The second action cancels the first, and since the value hasn’t actually changed yet, nothing actually happens.

Try setting CountingLabel1.Text = "100" first so the animation is avoided and the value updated immediately.

Got an error with this line (There is more than one item with this name and it’s n to clear to witch this refers) :

Task = New AnimationKit.ValueTask(Self, “Text”, Self.Value, Value)

That line is correct. So something else must be going on. Maybe the class hasn’t implemented the AnimationKit.ValueAnimator interface?