Skip to content
Dustin edited this page May 31, 2016 · 2 revisions

glgui-list creates a scrollable list with selectable items that are each drawing procedures. This widget has a callback procedure and an optional keyboard callback procedure.

Parameter Description
g The Graphical User Interface (GUI) belonging to this widget
x The lower left corner along the x-axis in pixels
y The lower left corner along the y-axis in pixels
w The width of the element in pixels
h The height of the element in pixels
dh The height of line for each element in list (Delta Height)
lst The list of drawing procedures to be called
cb The callback procedure to be run if clicked
kcb Optional: specifies a keyboard callback procedure

The items in the list (lst) must be procedures that take the following parameters:

Parameter Description
g The Graphical User Interface (GUI) which will be the GUI the list is in.
wgt This will be the list widget itself.
bx The lower left corner along the x-axis in pixels of where this item is being drawn in the list
by The lower left corner along the y-axis in pixels of where this item is being drawn in the list
bw The width of the area this item is being drawn in, equal to the list width (w) or the width - 8 when a scrollbar is shown.
bh The height of the area this item is being drawn in, equal to the list Delta Height (dh) of the list
selected? This will be true if this is the currently selected item in the list.

Example

Example 1: Make a list of numbers from 0 to 10 that if clicked display their value on the console.

(define (numeric-callback g wgt t x y)
  (display (fix (glgui-widget-get g wgt 'current))))
(define (numeric-list-element num)
  (lambda (g wgt bx by bw bh selected?)
    (glgui:draw-text-left (+ bx 13) (+ by 3) 50 24 (number->string num) ascii_24.fnt White)
  ))
(define (build-list)
  (let loop ((i 0) (result (list)))
    (if (fx= i 10) result
      (loop (+ i 1)(append result (list (numeric-list-element i))))
    )))
(glgui-list gui 0 0 (glgui-width-get) (glgui-height-get) 25 (build-list) numeric-callback)

Attributes

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

Attribute Default Value Description
current -1 Set by the list to the index of the current item when an item is clicked. This is only done if one or both of cb or cbb are not false. The draw procedure at this index is called with selected? = true. Set this to change the selection programmatically.
offset 0. Set by the list to the index of the top visible item. If the list is scrolled down then this will be greater than 0. Set this to change the scrolling programmatically.
callbackbeyond False Another callback that is called when the user clicks an empty entry past the end of the current list items. The current parameter is not set to this out of range index.
focus True If true and 'key_callback (kcb) is specified then the kcb procedure is called with the current index and the key code each time a EVENT_KEYRELEASE occurs.
hidden False If true, the widget is not displayed.
bordercolor False If set to a color, this color is used for a 1 pixel border around the list (adding to the dimensions) and for the 1 pixel gaps between each item. If not set, whatever is behind the list widget will be seen between the items.
bgcol1 (color-shade White 0.2) This color and bgcol2 are alternately used to draw a rectangle for each list entry before the drawing procedure for that entry is called to draw on top.
bgcol2 (color-shade White 0.25) bgcol1 and this colour are alternately used to draw a rectangle for each list entry before the drawing procedure for that entry is called to draw on top.
scrollcolor DimGray The color of the scrollbar.
scrollw 5. The width of the scrollbar.
scrollrounded #f If set to true, the scrollbar is drawn as a rounded box.

Example

Example 2: Get the current selected item in list1 (a widget in gui1) and scroll it to the top of the visible list. Note that current would only be set if there is a callback procedure (or 'callback is just set to true).

(glgui-widget-set! gui1 list1 'offset (glgui-widget-get gui1 list1 'current))
Clone this wiki locally