.\" Copyright (c) 2003-2023 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_UCOMBO 3 .Os Agar 1.7 .Sh NAME .Nm AG_UCombo .Nd agar button-triggered drop-down menu widget .Sh SYNOPSIS .Bd -literal #include #include .Ed .Sh DESCRIPTION .\" IMAGE(/widgets/AG_UCombo.png, "A collapsed AG_UCombo") The .Nm widget displays an .Xr AG_Button 3 which triggers the expansion of drop-down menu (a window containing an .Xr AG_Tlist 3 ) when pressed. The drop-down menu collapses if the user selects an item, or clicks outside of the .Nm area. .Sh INHERITANCE HIERARCHY .Xr AG_Object 3 -> .Xr AG_Widget 3 -> .Nm . .Sh INITIALIZATION .nr nS 1 .Ft "AG_UCombo *" .Fn AG_UComboNew "AG_Widget *parent" "Uint flags" .Pp .Ft "void" .Fn AG_UComboSizeHint "AG_UCombo *com" "const char *text" "int nitems" .Pp .Ft "void" .Fn AG_UComboSizeHintPixels "AG_UCombo *com" "int w" "int h" .Pp .nr nS 0 The .Fn AG_UComboNew function allocates, initializes, and attaches a new .Nm widget. Acceptable .Fa flags include: .Bl -tag -width "AG_UCOMBO_SCROLLTOSEL " .It AG_UCOMBO_SCROLLTOSEL Scroll to initial selection if it is not visible. .It AG_UCOMBO_HFILL Expand horizontally in parent container. .It AG_UCOMBO_VFILL Expand vertically in parent container. .It AG_UCOMBO_EXPAND Shorthand for .Dv AG_UCOMBO_HFILL | AG_UCOMBO_VFILL . .El .Pp .Fn AG_UComboSizeHint arranges for the .Xr AG_Tlist 3 widget displayed on popup to request a size large enough to display the given number of items. The .Fn AG_UComboSizeHintPixels variant specifies the size of the list in pixels. .Sh EVENTS The .Nm widget generates the following events: .Pp .Bl -tag -compact -width 2n .It Fn ucombo-selected "AG_TlistItem *item" An item was selected. .It Fn ucombo-expanded "void" The drop-down menu is now visible. May be used to populate .Va list . .It Fn ucombo-collapsed "void" The drop-down menu is now hidden. .El .Sh STRUCTURE DATA For the .Ft AG_UCombo object: .Pp .Bl -tag -compact -width "AG_Button *button " .It Ft AG_Tlist *list The .Xr AG_Tlist 3 displayed by .Nm when expanded, or NULL if collapsed (RO). .It Ft AG_Button *button The .Xr AG_Button 3 which triggers expansion (RO). .El .Sh EXAMPLES The following code fragment generates a drop-down menu and reacts to a selection event by displaying a text dialog: .Bd -literal -offset indent .\" SYNTAX(c) static void ComboExpanded(AG_Event *event) { AG_UCombo *com = AG_UCOMBO_SELF(); AG_Tlist *tl = com->list; AG_TlistAdd(tl, NULL, "Foo"); AG_TlistAdd(tl, NULL, "Bar"); } static void ComboSelected(AG_Event *event) { AG_TlistItem *item = AG_TLISTITEM_PTR(1); AG_TextMsg(AG_MSG_INFO, "Selected item: %s", item->text); } AG_UCombo *com; com = AG_UComboNew(NULL, 0); AG_SetEvent(com, "ucombo-expanded", ComboExpanded, NULL); AG_SetEvent(com, "ucombo-selected", ComboSelected, NULL); .Ed .Sh SEE ALSO .Xr AG_Button 3 , .Xr AG_Combo 3 , .Xr AG_Intro 3 , .Xr AG_Tlist 3 , .Xr AG_Widget 3 , .Xr AG_Window 3 .Sh HISTORY The .Nm widget first appeared in Agar 1.0. "ucombo-expanded" and "ucombo-selected" appeared in Agar 1.7.0.