Skip to content
shaybeau731 edited this page Jun 1, 2016 · 6 revisions

glgui-datepicker creates a date entry widget consisting of date (of month), month, and year verticalvaluepickers. Using this widget, a user can enter a date between the datemin and datemax. Parameters, attributes and procedures in this widget are very similar to those available in glgui-datewheels.

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. The date text is centered in this height.
datemin The minimum (earliest) date (in seconds) allowed to be chosen in the widget. If false, Jan 1st 1970 is used
datemax The maximum (latest) date (in seconds) allowed to be chosen in the widget. If false, then the end of the next year is used.
colorarrows Color of the up and down arrows in the widget
colorhighlight Color of the the highlighting on the buttons behind the arrows that appears only when they are pressed
colorvalue Color of the selected date text
colorbg Background color of the entire widget. This can be #f to not have a background color.
numfont Font for the selected date and year values
monthfont Font for the selected month value

Example

Example 1: Creates datepicker at coordinates 20,20, width 240, height 110 with the date range limited between 1950 and 2015. The arrow buttons are grey with a faded blue highlight when pressed. The same font (arial_20) is used for all text, which is White. There is no background color used.

(set! dp (glgui-datepicker gui 20 20 240 110                         
           (string->seconds "1950/01/01 00:00" "%Y/%m/%d %H:%M")
           (string->seconds "2015/12/31 00:00" "%Y/%m/%d %H:%M")
           Grey (color-shade Blue 0.5) White #f arial_20.fnt arial_20.fnt))

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
callback False If a procedure, this procedure is called when a date change is finished being made in the date picker. If Button1 (or your finger on a mobile platform) is being held down for cycling through dates, the callback is not called until you release.
defaultvalue Today's Date This is initially set the same as the value. This is not used internally by the widget, but can be used to store a default date.
displayorder GUI_YEAR_MONTH_DAY The order of the date elements in the date picker. This can also be set to GUI_DAY_MONTH_YEAR or GUI_MONTH_DAY_YEAR.
hidden False If true, the widget is not displayed.
scalearrows False If true, the size of the arrow buttons will be proportional to the height of the widget.
topdown False By default, later dates are reached by pressing the up arrows. By setting this to true, the values are reversed, with the down arrows going to later dates.
value Today's Date The current date to show on the date picker (in seconds). This defaults to today's date unless that is out of the range given, and then it uses the datemin or datemax, which ever is closest to today's date.

Example

Example 2: Retrieves the current date value of the datepicker created in Example 1. This is a Unix timestamp (number of seconds since January 1st, 1970).

(glgui-widget-get gui dp 'value)

Procedures

Besides glgui-datepicker, there are three other procedures that operate on a datepicker.

The following procedure changes the display of months from the default of "Jan", "Feb", etc to a list of strings you provide. It should be of length 12. This is useful for using a different language. This will affect all datepickers in the app.

(glgui-datepicker-update-months strlist)

Under normal circumstances the day, month, and year value pickers do not allow the user to choose a date outside the datemin - datemax range or a date that does not exist. For example, if the range is from January 1st, 2013 to March 1st, 2013, the month picker will not include months after March. Also, if the month picker were set to February then the date picker would only show values between 1 and 28, since there is no February 29th in 2013. If the value pickers are arranged with the day picker on the left and the user uses this picker first these restrictions can be confusing. For example, if the date picker displays 15 Feb 2013 and the user wants to enter 30 Jan 2013, they will find that picking 30 is not possible because Feb is chosen.

(glgui-datepicker-unlimited g wgt)

Calling the above procedure with the GUI and datepicker widget causes the day picker to display all days from 1-31 and the month picker to display all months regardless of the datemin and datemax parameters or even which days exist. Thus, a user changing the date from 15 Feb 2013 to 30 Jan 2013 could change the day and then the month rather than having to change the month first. It is useful to call this procedure when first displaying the datepicker.

Note: The effects of the above procedure are temporary. When the year is adjusted, the month and day limits are automatically restricted depending on the year. Similarly, when the month is adjusted, the day limits are automatically restricted as well. If only the day is adjusted after the above procedure this may lead to a date being chosen that is outside the datemin and datemax range or one that doesn't exist at all.

(glgui-datepicker-update-limits g wgt)

The above procedure enforces the datemin and datemax as well as the existence of dates across all three value pickers. It will also return a corrected date if the currently displayed date within the new range shown on the datepicker is invalid. It is useful to call this procedure when the user is done entering the date in the datepicker, to ensure this date is a valid one.

Note: This procedure is only needed if the procedure above it was called sometime before it.

Clone this wiki locally