Skip to content

glgui button string

Walt K edited this page Jan 23, 2016 · 4 revisions

glgui-button-string creates a button with a string label. It supports the generation of a toggle button by specifying a list of strings.

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
str String or a list of strings to use as labels of a toggle button. To update the string(s) later, set parameter 'image. If a non-toggle button, set to a list of 1 item. For example, (list "string").
fnt Font to be render the string in
callback Function to be called if button is pressed
icon Optional: Image texture to use as an icon to the left of the string label. This can also be a list of icons which will be used with a toggle button.

Example

Example 1 from apps/DemoHelloWorld/main.scm,

(define (button-callback g w t x y)
  (let ((oldcolor (glgui-widget-get g w 'color)))
    (if ahooga (audiofile-play ahooga))
    (glgui-widget-set! g w 'color (if (= oldcolor White) Red White))
  )
)
(set! b (glgui-button-string gui bx by bw bh "Me too!!!" ascii_18.fnt 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 strings 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 True If true, the button is a rounded rectangle shape. Otherwise, the button is a rectangle.
multiline False If true, the string label will be wrapped to extra lines if necessary to fit or if newline characters are used.
align GUI_ALIGNCENTER The alignment of the text on the button.
direction GUI_LEFTTORIGHT This is only used if multiline is true and specifies which way to wrap to the next line of text. If set to GUI_RIGHTTOLEFT then text is wrapped with the right end of the string on the top line and the left end on the bottom line, useful for right-to-left languages.
icon-space 5 This is only used if icon is not false. This is the space in pixels between the text and the icon (vertically or horizontally depending on the below parameter).
icon-align GUI_ALIGNLEFT The side the icon is on compared to the text. Choose from GUI_ALIGNLEFT, GUI_ALIGNRIGHT, GUI_ALIGNTOP and GUI_ALIGNBOTTOM.

Examples

Example 2: Aligns the "Me Too!!!" text from Example 1 to the left and makes the background a solid color. It changes the normal background color of the button to Dark Green which changes to Green when the mouse is down on it.

(glgui-widget-set! gui b 'align GUI_ALIGNLEFT)
(glgui-widget-set! gui b 'solid-color #t)
(glgui-widget-set! gui b 'button-normal-color DarkGreen)
(glgui-widget-set! gui b 'button-selected-color Green)

Example 3: Changes text of a toggle button to "a" and "b"

(glgui-widget-set! gui w 'image (map list (list ("a" "b"))))

Clone this wiki locally