How to resolve the algorithm GUI enabling/disabling of controls step by step in the LiveCode programming language
How to resolve the algorithm GUI enabling/disabling of controls step by step in the LiveCode programming language
Table of Contents
Problem Statement
In addition to fundamental GUI component interaction, an application should dynamically enable and disable GUI components, to give some guidance to the user, and prohibit (inter)actions which are inappropriate in the current state of the application.
Similar to the task GUI component interaction, write a program that presents a form with three components to the user:
The field is initialized to zero. The user may manually enter a new value into the field, increment its value with the "increment" button, or decrement the value with the "decrement" button. The input field should be enabled only when its value is zero. The "increment" button only as long as the field's value is less then 10: When the value 10 is reached, the button should go into a disabled state. Analogously, the "decrement" button should be enabled only as long as the value is greater than zero. Effectively, the user can now either increment up to 10, or down to zero. Manually entering values outside that range is still legal, but the buttons should reflect that and enable/disable accordingly.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm GUI enabling/disabling of controls step by step in the LiveCode programming language
Source code in the livecode programming language
command enableButtons v
switch
case v <= 0
put 0 into fld "Field1"
set the enabled of btn "Button1" to true
set the enabled of btn "Button2" to false
break
case v >= 10
put 10 into fld "Field1"
set the enabled of btn "Button1" to false
set the enabled of btn "Button2" to true
break
default
set the enabled of btn "Button1" to true
set the enabled of btn "Button2" to true
put v into fld "Field1"
end switch
end enableButtons
on mouseUp
put field "Field1" into x
add 1 to x
enableButtons x
end mouseUp
on mouseUp
put field "Field1" into x
subtract 1 from x
enableButtons x
end mouseUp
on rawKeyDown k
if numToChar(k) is among the items of "1,2,3,4,5,6,7,8,9,0" then
if (numToChar(k) + the text of me) <= 10 then
enableButtons (numToChar(k) + the text of me)
end if
else if k = 65288 then
pass rawKeyDown
end if
end rawKeyDown
You may also check:How to resolve the algorithm Ascending primes step by step in the 11l programming language
You may also check:How to resolve the algorithm Honaker primes step by step in the Perl programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Befunge programming language
You may also check:How to resolve the algorithm Mian-Chowla sequence step by step in the Sidef programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the ALGOL 68 programming language