The use of justinmind's computation expression and condition is troublesome for beginners.
Combined with an online tutorial, this article mainly uses the calculation expressions and conditions for the calculator examples.
Goal: calculate the amount automatically based on the unit price (static) and quantity (dynamic. :
Add two rectangular parts to the right of the quantity text box. The top side is +, the bottom side is-, and click + or-automatically minus 1. If the number is 0, the calculation is not allowed.
[STEP] (focus only)
1. Select +; 2. Add events (Click + to set the number of events + 1 ):
3. The event is "when you click the mouse" (default); 4. Select "Set Value" for the action; 5. Select the object part with the set value; 6. Select "Calculate "; 7. Click "(add expression)" to bring up the window:
8 ~ 9. Drag and Drop the "+" in the quantity component and computing function to the number expression above. 10. Enter "1 ":
11 ~ 12 Confirm twice and return to the main Workspace:
13. Add a click event again (calculate the amount based on the changed quantity ):
14 ~ 19. I will not repeat it again. Now the "+" button has added two click events:
Next, we will add the same event to the "-" button, but click "quantity-1" at a time, and determine that when the number is 0, the calculation amount will not be reduced by 1.
We only need to copy the "+" button event and change the number + 1 to-1.
20. If the "+" button is selected, click the "Copy event" icon below:
21. Select the "-" button. 22. Click the paste button below:
23. Double-click the event with the number + 1:
24. Edit the expression:
25 ~ 28. Change + -:
29. Add a condition limit on the number-1 event (when the number is greater than or equal to 1)
30 ~ 32. Set the condition judgment:
33. OK. Return to the main workspace and click "simulate" to view the generated prototype:
Justinmind tutorial (2) -- Calculation Expression and condition usage