Adding a button widget

The button widget is the simplest rich client widget because it does not need to maintain a state like the others. You only need to create the button and specify an event handler to run when the button is clicked.
  1. In a console form, create the button by using the consoleButton predefined part. This part represents the button widget.
    Record buttonForm type ConsoleForm {formSize=[12,40]}
        myButton consoleButton 
           {name = "simpleButton", 
            text = "Click here", 
            bounds=[4,4,1,15]};
    end
  2. At minimum, specify the following properties for the button:
    name
    A mnemonic that you will use later to link the button to an event handler
    text
    The label for the button
    bounds
    An array of four integers that represent the row, column, height, and width of the button, respectively
  3. Within an openUI statement, specify an event handler for the button's PUSHED event:
    onEvent(ConsoleButton.PUSHED : "simpleButton")
        SysLib.writeStderr("You pushed the button.");

A complete example of a Console UI program that uses a button in this way follows.

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

import forms.buttonForm

program simpleButton type BasicProgram 
    
    textValue string;
    counter int=0;
    function main()
        myWindow WINDOW {name="myWindow", 
            position = [1,1]};
        openWindow(myWindow);
        
        myForm buttonForm {};
        displayForm(myForm);
        
        keepGoing boolean = true;
        while (keepGoing == true)
            openUI { bindingByName=no } 
                myForm 
                bind textValue
                OnEvent(ConsoleButton.PUSHED : "simpleButton")
                    counter+=1;
                    textValue = "You have clicked the button "
                        +counter+" times.";
                    SysLib.writeStderr(textValue);
                onEvent(ConsoleButton.PUSHED : "exitButton")
                    keepGoing = false;
            end
        end
    end
    
end
In the file forms/buttonForm.egl:
package forms;

record buttonForm type ConsoleForm { formsize=[12,40] }
    introText consoleField 
       {name="introText", 
        position = [1,1], 
        fieldLen = 20};
    myButton consoleButton 
       {name = "simpleButton", 
        text = "Click here", 
        bounds=[4,4,1,15]};
    exitButton consoleButton 
       {name = "exitButton", 
        text = "Click to exit", 
        bounds=[6,4,1,15]};
end

Feedback