Wheel IDE

Online demo »

Buttons

Buttons example

This example shows how to use the button component.

When the blue button is clicked then the onButtonsButtonBlueClick procedure is called, when the green button is clicked then the onButtonsButtonGreenClick procedure is called, when the red button is clicked then the onButtonsButtonRedClick procedure is called.

All the click event procedures have a windowHandle parameter, the value of this paramerer is equal to the return value of the showButtonsForm procedure.

The windowHandle has to be used to address the components on the form, in this example it's used to change the color of the status light with the components.statusLight.setColor procedure.

Code

#project "Buttons example"

#include "lib/modules/standard.whl"
#include "lib/modules/components/component.whl"
#include "lib/modules/components/form.whl"
#include "lib/modules/components/button.whl"
#include "lib/modules/components/statusLight.whl"

#define BUTTONS_BUTTON_BLUE  0x780ACFDE
#define BUTTONS_BUTTON_GREEN 0x4F7DB0F4
#define BUTTONS_BUTTON_RED   0xD846C71A
#define BUTTONS_STATUS_LIGHT 0x18551397

#resource "buttons.wfrm"

; @proc                   Button onClick event.
; @param windowHandle     The handle to the active window.
proc onButtonsButtonBlueClick(number windowHandle)
    components.statusLight.setColor(windowHandle, BUTTONS_STATUS_LIGHT, COMPONENT_COLOR_BLUE)
end

; @proc                   Button onClick event.
; @param windowHandle     The handle to the active window.
proc onButtonsButtonGreenClick(number windowHandle)
    components.statusLight.setColor(windowHandle, BUTTONS_STATUS_LIGHT, COMPONENT_COLOR_GREEN)
end

; @proc                   Button onClick event.
; @param windowHandle     The handle to the active window.
proc onButtonsButtonRedClick(number windowHandle)
    components.statusLight.setColor(windowHandle, BUTTONS_STATUS_LIGHT, COMPONENT_COLOR_RED)
end

; @proc                   Show the form.
; @ret                    The handle to the form.
proc showButtonsForm()
    ret components.form.show("buttons.wfrm")
end

proc main()
    showButtonsForm()
    halt()
end

Screenshot

See also: button