Skip to content
Chris Petersen edited this page Oct 16, 2014 · 1 revision

glgui-button creates a button with a texture image. It supports the generation of a toggle button by specifying a list of images.

Parameter Description
g Graphical User Interface (GUI) for this widget
x Lower left corner along the x-axis in pixels
y Lower left corner along the y-axis in pixels
w Width of the element in pixels
h Height of the element in pixels
img Image texture placed centered on the button. This can also be a list of images which will be used with a toggle button.
callback Function to be called if button is pressed

Example

Example 1: Create a button that when clicked changes image color from red to white everytime it is clicked. This widget is diplayed with image texture pushme.img, which is generated from pushme.png in the application's texture folder. This widget is specified with x=0, y=10, width= 60, height= 30, and belongs to gui g.

(define (button-callback g w t x y)
  (glgui-widget-set! g w 'color (if (= (glgui-widget-get g w 'color) White) Red White)))
(glgui-button g 0 10 60 30 pushme.img button-callback)

Attributes

Besides the parameters set in the above procedure, the widget has the following attributes that can be set using glgui-widget-set! and retrieved using glgui-widget-get:

Attribute Default Value Description
value 0 If this is a toggle button (a list of images was given) then this is the index of the currently selected section of the button.
toggle-selected-color Grey This is the background color of the selected section of a toggle button.
toggle-normal-color DimGrey This is the background color of the non-selected section(s) of a toggle button.
button-selected-color Grey This is the background color of the (non-toggle) button when the mouse (finger) is down on it.
button-normal-color DimGrey This is the normal background color of the (non-toggle) button (when the mouse is not down on it).
solid-color False By default, the button background is a texture with a gradient which is partially transparent. If solid-color is set to false, this texture is not used and instead just the above color attributes are used, 100% opaque.
rounded False If set to true, the button is a rounded rectangle shape. Otherwise, the button is a rectangle.

Example

Example 2: An update to example 1 that also changes the background color when the button is clicked, alternating between a white image on a red background and a red image on a white background.

(define (button-callback g w t x y)
  (glgui-widget-set! g w 'color (if (= (glgui-widget-get g w 'color) White) Red White))
  (glgui-widget-set! g w 'button-normal-color (if (= (glgui-widget-get g w 'button-normal-color) White) Red White)))
(set! b (glgui-button g 0 10 60 30 pushme.img button-callback))
(glgui-widget-set! g b 'button-normal-color Red)
Clone this wiki locally