Adding a check box widget

Unlike the button widget, the check box widget has a state; it is either checked or not checked. Therefore, you must bind a boolean variable to the check box, just like you would bind a text variable to a text field in a console form. When the user selects the check box, the variable is set to TRUE, and when the user clears the check box, the variable is set to FALSE.
  1. In a console form, create the check box by using the consoleCheckbox predefined part.
    Record checkForm type ConsoleForm {formSize=[12,40]}
        myCheck consoleCheckbox 
           {name = "simpleCheck", 
            text = "Click here", 
            bounds=[4,4,1,15]};
    end
  2. At minimum, specify the following properties for the check box:
    name
    A mnemonic that you will use later to link the check box to an event handler
    text
    The label for the check box
    bounds
    An array of four integers that represent the row, column, height, and width of the check box, respectively
  3. Create a boolean variable to represent the state of the check box:
    checkState boolean = false;
  4. With an openUI statement, open the form and bind the variable to the check box:
    myForm checkForm {};
    openUI myForm
        bind checkState
        //event handlers go here
    end
  5. Within the openUI statement, specify an event handler for the check box's STATE_CHANGED event:
    onEvent(ConsoleCheckbox.STATE_CHANGED : "simpleCheck")
        if (checkState == true)
            SysLib.writeStderr("Checked");
        else
            SysLib.writeStderr("Cleared");
        end

A complete example of a Console UI program that uses a check box in this way follows:

In the file programs/simpleCheckbox.egl:
package programs;

import forms.checkForm;

program simpleCheckbox type BasicProgram 
    
    function main()
        myWindow WINDOW {name="myWindow", position = [1,1]};
        openWindow(myWindow);
        
        myForm checkForm {};
        displayForm(myForm);
        
        textValue string = "Text.";
        keepGoing boolean = true;
        myCheckVar boolean = false;
        while (keepGoing == true)
            openUI myForm 
                bind textValue, myCheckVar
                onEvent(ConsoleButton.PUSHED : "exitButton")
                    keepGoing = false;
                onEvent(ConsoleCheckbox.STATE_CHANGED : "simpleCheck")
                    if (myCheckVar == true)
                        textValue = "Checked";
                    else
                        textValue = "Cleared";
                    end
            end
        end
    end
    
end
In the file forms/checkForm.egl:
package forms;

record checkForm type ConsoleForm { formsize=[12,40] }
    introText consoleField 
       {name="introText", 
        position = [1,1], 
        fieldLen = 20};
    myCheck consoleCheckbox 
       {name="simpleCheck",
        text="Checkbox", 
        bounds=[3,5,1,15]};
    exitButton consoleButton 
       {name = "exitButton", 
        text = "Click to exit", 
        bounds=[6,4,1,15]};
end

Feedback