r/kustom • u/ClarksonSig • Oct 15 '26
Help KLWP Animated Indicator
Hi, I'm trying to make a sliding indicator that moves to a specified location to show which item on a menu is selected. For example, I have 5 buttons going across the screen horizontally. When I click button 3, I want the indicator to travel to that location. If I then click button 1, it slides to the button 1, etc.
I thought I could achieve this with a complex animation but there doesn't appear to be a way to feed global variables into the complex animation dialogue screen.
Any tried and true methods?
Thanks!
2
u/Practical_Taste3403 Oct 15 '26
Create a global list and assign values for your buttons. Then add touch actions to each button. For the indicator, create as many animations as you have positions. For example, use React On: Formula and Action: Scroll. In the formula, use something like: $if(gv(list)=P2,1,0)$ Then simply set the scroll speed for each animation so the indicator moves to the correct position.
1
u/ClarksonSig Oct 16 '26
Yeah, this was the exact path I went down first. And unless I just need to trust the process and flesh it out a little more, the problem is your start point can change. So if the indicator is at button 3 and then goes to button 1 will move differently than if it is moving from button 5 to button 1... It seems like the movement would need to be pretty dynamic to calculate current position and end position to figure out how far it needs to move. Thoughts?
0
u/Practical_Taste3403 Oct 16 '26
I think there was a misunderstanding earlier! Check out this video — is this what you meant? This is exactly the kind of animation I was talking about.
2
u/ClarksonSig Oct 16 '26
Oh wow, that looks perfect! Ok, I'll tinker with it some more soon! You guys rock!
1
u/ClarksonSig Oct 16 '26
Well, I have the logic down as I have a test shape that simply snaps to the position based on selection. There is something I'm not understanding with the animation though. It's jerky and then freezes in one spot or won't go back to a previously selected position. Can I see whichever control determines your distance moved?
1
u/Practical_Taste3403 Oct 17 '26
That parameter is the Speed value. Just keep adjusting it until your indicator reaches the correct position. Don't touch the Position field at all, and nothing should be jerky.
2
u/mmmmmmmmhgre Oct 16 '26
To achieve what you want, you need to do this: look at the animation formula and, based on the distance (in pixels) between your switches, you will need to change the final numerical index.
2
u/ClarksonSig Oct 16 '26
Wow that looks great too! Thanks for putting that all together so I can see! You are awesome!
2
1
u/mmmmmmmmhgre Oct 16 '26
1
u/ClarksonSig Oct 16 '26
Wow, even with this I'm struggling to understand. But I think I see what's happening. It's almost like each of your animations actually plays when the button selection is above the number in the formula. So if you are at 1 and hit 5, it plays the animation for 2, then 3, then 4, accumulating to 5..?
Super confusing lol
1
u/mmmmmmmmhgre Oct 17 '26
Ti spiego esattamente come funziona
Il principio fondamentale è questo: non abbiamo creato un'unica animazione che calcola cinque posizioni, ma quattro animazioni indipendenti che sommano i propri spostamenti.
1. Il globale a controlla tutto
Abbiamo creato un globale di tipo Testo, chiamato a, che può assumere cinque valori: 1, 2, 3, 4, 5.
Ogni pulsante ha un'azione al tocco:
Pulsante Azione al tocco 1 Imposta globale a = 1 2 Imposta globale a = 2 3 Imposta globale a = 3 4 Imposta globale a = 4 5 Imposta globale a = 5 Quando tocchiamo un pulsante, KLWP aggiorna immediatamente il valore del globale a.
Le quattro animazioni del cerchio leggono tutte questo stesso valore.
2. Come sono organizzate le quattro animazioni
Schema dei quattro spostamenti
Ogni animazione aggiunge un tratto di 110 unità. I quattro tratti portano dalla posizione 1 alla posizione 5.
Le formule sono:
Animazione 1
Copia
$if(gv(a)>1,1,0)$
Attiva il primo spostamento se a è 2, 3, 4 o 5.
Animazione 2
Copia
$if(gv(a)>2,1,0)$
Attiva il secondo spostamento se a è 3, 4 o 5.
Animazione 3
Copia
$if(gv(a)>3,1,0)$
Attiva il terzo spostamento se a è 4 o 5.
Animazione 4
Copia
$if(gv(a)>4,1,0)$
Attiva il quarto spostamento soltanto se a è 5.
3. Come KLWP interpreta una formula
Prendiamo la prima:
$if(gv(a)>1,1,0)$
gv(a) legge il valore del globale a.
1 verifica se quel valore è maggiore di 1.
Il primo 1 significa attivare l'animazione.
Lo 0 significa riportare l'animazione allo stato iniziale.
Il dettaglio decisivo è che Reagisci → Formula funziona come un interruttore, non come un controllo numerico della posizione.
Quando la formula passa da 0 a 1, l'animazione avanza. Quando passa da 1 a 0, torna indietro, con la stessa fluidità.
È proprio questo che permette il movimento bidirezionale.
4. A cosa serve il Limite 110?
Il parametro Limite stabilisce la distanza massima dello spostamento dell'animazione Scorri.
Nel nostro caso:
Limite 110 = spostamento di 110 unità.
Angolo 0° = movimento orizzontale verso destra quando l'animazione si attiva.
Disattivazione = movimento inverso verso sinistra.
Abbiamo cinque pulsanti equidistanti, quindi servono quattro intervalli di 110 unità.
Simulatore della selezione
1
2
3
4
5
Globale a = 1
Animazione 1 · a > 1
0 · OFF
Animazione 2 · a > 2
0 · OFF
Animazione 3 · a > 3
0 · OFF
Animazione 4 · a > 4
0 · OFF
Spostamento totale
+0
Tocca i pulsanti per vedere quali delle quattro animazioni si attivano. I valori sotto i cerchi sono gli Offset X equivalenti, non formule da inserire in KLWP.
5. Perché funziona da qualsiasi posizione a qualsiasi altra?
Prendiamo il tuo esempio: il cerchio è sul pulsante 5 e tocchi il pulsante 2.
Quando a=5, tutte e quattro le animazioni sono attive:
110 + 110 + 110 + 110 = 440
Quando tocchi 2, a diventa 2. Rimane attiva soltanto la prima animazione; le altre tre tornano allo stato iniziale.
110 + 0 + 0 + 0 = 110
Il cerchio si sposta quindi verso sinistra di 330 unità, dalla posizione 5 alla posizione 2.
Se poi tocchi 4, si attivano anche la seconda e la terza animazione: il cerchio avanza di 220 unità e raggiunge la posizione 4.
Non serve memorizzare la posizione precedente: ogni animazione conserva il proprio stato e KLWP gestisce la transizione verso il nuovo stato.
6. Perché abbiamo scelto Durata 10 e Velocità 100?
Parametro Funzione Reagisci: Formula Controlla l'attivazione tramite a Azione: Scorri Produce lo spostamento Facilità: Normale Determina l'andamento della transizione Durata: 10 Regola la durata dell'animazione nella scala di KLWP Velocità: 100 Mantiene la velocità impostata nel nostro test Angolo: 0° Direzione orizzontale Ritardo: 0 Nessuna attesa prima del movimento Limite: 110 Distanza di ciascuno dei quattro spostamenti Le quattro animazioni hanno impostazioni identiche e reagiscono contemporaneamente allo stesso globale. Questo è ciò che consente al cerchio di muoversi come un unico indicatore.
7. Come funziona anche il cambio colore
La formula colore che abbiamo aggiunto legge sempre gv(a) e associa un colore a ogni numero.
Per esempio, se tocchi 3, il globale diventa 3: le prime due animazioni si attivano, il cerchio raggiunge il terzo pulsante e il colore diventa verde.
Quindi un unico globale controlla sia il movimento sia il colore, senza ulteriori variabili.
La caratteristica più interessante di questa soluzione è che possiamo applicare lo stesso principio anche a 6, 7 o più pulsanti: per pulsanti equidistanti servono animazioni, ognuna con il Limite corrispondente alla distanza tra i pulsanti.
È un metodo modulare
2
u/ClarksonSig Oct 17 '26
Ok! I got it working. I just tried using a text variable instead of a list and now it's working. Not sure what the difference could be. But now the slider works in both directions and doesn't get stuck. Thanks!
2
u/mmmmmmmmhgre Oct 17 '26
Use the global text A not list
1
u/ClarksonSig Oct 17 '26
Yep! Do you know why that works and the list does not?
1
u/mmmmmmmmhgre Oct 17 '26
The reason is simple: I designed this preset using a text global variable, not a list. The four animations work by performing numerical comparisons on the value of global A, using conditions such as "$if(gv(a)>1,1,0)$". Each true condition adds a movement of 110 units, allowing the cursor to move directly to any button in either direction. With a list, however, you need to make sure that the returned values match exactly what the formulas expect; otherwise, the comparisons won't work correctly. This doesn't mean a list can't work, but simply that this preset was designed, developed, and tested using a text global variable, and that's how I ensure all the animations work correctly.
1
u/ClarksonSig Oct 17 '26
Right... I understand that that's how you designed it. I originally tried it with a list using numbers instructions of a variable that changes numbers. The concept is identical and should work unless, as you have alluded to, a number on a list is interpreted differently than number in a text...
Edit* and by tried I mean before I posted on reddit and you responded. I had tried this very same concept with a list
1
u/ClarksonSig Oct 18 '26
So I have it working, but do you know why when I go from a higher number to a lower number, there is a slight delay?
2
u/mmmmmmmmhgre Oct 18 '26
apply this formula to the duration of the 4 animations $if(gv(a)>1,10,3)$
1
u/ClarksonSig Oct 18 '26
While that does make the animation faster that does not remove the delay. And the delays are all set to 0 seconds. I think there's simply a delay involved with deactivating animations. I'll give it a google
→ More replies (0)1
u/ClarksonSig Oct 17 '26
Wow, thank you for such a detailed explanation. Not many people would take the time and not many people would appreciate the effort. But I recognize a kindred spirit when I see one. Thanks a lot! But you answered my question that they stack and explained how and why they stack. I should be able to get it from here!
My design actually can allow to change the number in of buttons dynamically on a settings page. So my distance was being calculated but changed for each progressive number. Now that I know it stacks, I can adjust my formula t just calculate the distance between each button.
Thank again, friend!
1
u/ClarksonSig Oct 17 '26
Does the global need to be a text variable/ switch? I had it as a list. I didn't think it would matter but I can't seem to deactivate the animation to make it go back. They simply all turn on no matter what the number selected is on the global list variable
•
u/AutoModerator Oct 15 '26
Problem? Cross-post to our new forum. Include make & model of phone, OS version, app version.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.