.\" Copyright (c) 2002-2022 Julien Nadeau Carriere .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES .\" (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd December 21, 2022 .Dt AG_RADIO 3 .Os Agar 1.7 .Sh NAME .Nm AG_Radio .Nd agar radio group widget .Sh SYNOPSIS .Bd -literal #include #include .Ed .Sh DESCRIPTION .\" IMAGE(/widgets/AG_Radio.png, "An AG_Radio widget") The .Nm widget implements a group of "radio" buttons. .Sh INHERITANCE HIERARCHY .Xr AG_Object 3 -> .Xr AG_Widget 3 -> .Nm . .Sh INITIALIZATION .nr nS 1 .Ft "AG_Radio *" .Fn AG_RadioNew "AG_Widget *parent" "Uint flags" "const char *items[]" .Pp .Ft "AG_Radio *" .Fn AG_RadioNewFn "AG_Widget *parent" "Uint flags" "const char *items[]" "AG_EventFn fn" "const char *fmt" "..." .Pp .Ft "AG_Radio *" .Fn AG_RadioNewInt "AG_Widget *parent" "Uint flags" "const char *items[]" "int *value" .Pp .Ft "AG_Radio *" .Fn AG_RadioNewUint "AG_Widget *parent" "Uint flags" "const char *items[]" "Uint *value" .Pp .Ft void .Fn AG_RadioSetDisposition "AG_Radio *radio" "AG_RadioType type" .Pp .Ft void .Fn AG_RadioItemsFromArray "AG_Radio *radio" "const char *items[]" .Pp .Ft "void" .Fn AG_RadioSizeHint "AG_Radio *radio" "Uint nLines" "const char *text" .Pp .Ft int .Fn AG_RadioAddItem "AG_Radio *radio" "const char *format" "..." .Pp .Ft int .Fn AG_RadioAddItemS "AG_Radio *radio" "const char *text" .Pp .Ft int .Fn AG_RadioAddItemHK "AG_Radio *radio" "AG_KeySym hotkey" "const char *format" "..." .Pp .Ft int .Fn AG_RadioAddItemHKS "AG_Radio *radio" "AG_KeySym hotkey" "const char *text" .Pp .Ft void .Fn AG_RadioClearItems "AG_Radio *radio" .Pp .nr nS 0 The .Fn AG_RadioNew function allocates, initializes, and attaches a new .Nm widget. If .Fa items is not NULL, it should point to a NULL-terminated array of strings. Acceptable .Fa flags include: .Pp .Bl -tag -width "AG_RADIO_HOMOGENOUS " -compact .It AG_RADIO_HOMOGENOUS Divide space equally between radio items. .It AG_RADIO_HFILL Expand horizontally in parent container. .It AG_RADIO_VFILL Expand vertically in parent container. .It AG_RADIO_EXPAND Shorthand for .Dv AG_RADIO_HFILL | AG_RADIO_VFILL . .El .Pp .Fn AG_RadioNewFn creates a new radio group and also sets an event handler for the .Sq radio-changed event. .Pp .Fn AG_RadioNew{Int,Uint} creates a new radio group bound to an integer. .Pp .Fn AG_RadioSetDisposition selects whether items are packed horizontally or vertically (the default): .Bd -literal .\" SYNTAX(c) typedef enum ag_radio_type { AG_RADIO_VERT, /* Vertical disposition */ AG_RADIO_HORIZ /* Horizontal disposition */ } AG_RadioType; .Ed .Pp .Fn AG_RadioItemsFromArray generates (appends) a set of radio buttons from the given NULL-terminated array of C strings. .Pp .Fn AG_RadioSizeHint specifies an alternate initial size requisition expressed as a number of lines .Fa nLines (or -1 = auto) and the rendered pixel width of .Fa text (or NULL = auto). By default, .Nm will auto-size based on the set of radio items at the time of the size requisition. .Pp .Fn AG_RadioAddItem inserts a single radio button. The .Fn AG_RadioAddItemHK variant also assigns a hotkey to the button. .Pp .Fn AG_RadioClearItems removes all radio buttons from the group. .Sh BINDINGS The .Nm widget provides the following bindings: .Pp .Bl -tag -compact -width "int *value" .It Va int *value Index of selected item, or -1 if there is no selection. .El .Sh EVENTS The .Nm widget generates the following events: .Bl -tag -width 2n .It Fn radio-changed "int index" Selection changed to item at index .Fa index . The .Sq value binding remains locked throughout the event handler's execution. .El .Sh STRUCTURE DATA For the .Ft AG_Radio object: .Bl -tag -width "int oversel " .It Ft int oversel Index of last selection under the cursor (read-only). .El .Sh EXAMPLES The following code fragment connects an .Nm to an enum: .Bd -literal -offset indent .\" SYNTAX(c) enum fruit { APPLE, ORANGE, BANANA } fruit = APPLE; const char *fruitNames[] = { "Apple", "Orange", "Banana", NULL }; AG_RadioNewInt(NULL, 0, fruitNames, &fruit); .Ed .Pp The following code fragment specifies a callback routine: .Bd -literal -offset indent .\" SYNTAX(c) void MyCallback(AG_Event *event) { const int newSelection = AG_INT(1); printf("Selected item %d\\n", newSelection); } .Li ... AG_Radio *rad; rad = AG_RadioNewFn(NULL, 0, fruitNames, MyCallback, NULL); AG_BindInt(rad, "value", &fruit); .Ed .Sh SEE ALSO .Xr AG_Intro 3 , .Xr AG_Widget 3 , .Xr AG_Window 3 .Sh HISTORY The .Nm widget first appeared in Agar 1.0. .Fn AG_RadioSetDisposition and .Fn AG_RadioSizeHint appeared in Agar 1.6.0. The .Dv AG_RADIO_HOMOGENOUS option appeared in Agar 1.6.1.