ugfx/include/gwin/list.h

244 lines
7.6 KiB
C
Raw Normal View History

2013-07-17 15:49:21 +00:00
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
2013-07-21 20:20:37 +00:00
* http://ugfx.org/license.html
2013-07-17 15:49:21 +00:00
*/
/**
* @file include/gwin/list.h
* @brief GWIN list widget header file
*
* @defgroup List List
* @ingroup GWIN
*
* @details GWIN allows it to create a list widget.
*
* @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h
* @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
* @pre GDISP_NEED_TEXT must be set to TRUE in your gfxconf.h
* @pre GWIN_NEED_LIST must be set to TRUE in your gfxconf.h
* @pre The font you want to use must be enabled in your gfxconf.h
*
* @{
*/
#ifndef _GWIN_LIST_H
#define _GWIN_LIST_H
// This file is included within "gwin/gwin.h"
/**
* @brief The event type for a list event
*/
#define GEVENT_GWIN_LIST (GEVENT_GWIN_FIRST+4)
/**
* @brief A list event
*/
typedef struct GEventGWinList {
2013-07-25 17:15:51 +00:00
GEventType type; // The type of this event (GEVENT_GWIN_LIST)
GHandle list; // The list
int item; // The item that has been selected (or unselected in a multi-select listbox)
2013-07-17 15:49:21 +00:00
} GEventGWinList;
// A list window
typedef struct GListObject {
GWidgetObject w;
2013-07-28 21:18:59 +00:00
#if GINPUT_NEED_TOGGLE
uint16_t t_up;
uint16_t t_dn;
#endif
2013-07-25 17:15:51 +00:00
int cnt; // Number of items currently in the list (quicker than counting each time)
int top; // The element at the top of the visible list area
2013-07-25 17:15:51 +00:00
gfxQueueASync list_head; // The list of items
2013-07-17 15:49:21 +00:00
} GListObject;
#ifdef __cplusplus
extern "C" {
#endif
2013-07-28 01:31:45 +00:00
/**
* @brief Create a list widget
*
* @note The drawing color and the background color get set to the current defaults. If you haven't called
* @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are Black and White.
* @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then
* there is no default font and text drawing operations will not display anything.
* @note A list remembers its normal drawing state. If there is a window manager then it is automatically
* redrawn if the window is moved or its visibility state is changed.
* @note The list contains no elements after creation.
* @note A slider supports mouse, toggle. Note: toggle only works correctly for single-select lists.
2013-07-28 01:31:45 +00:00
* @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than
2013-07-28 05:04:04 +00:00
* one toggle to a role, it will forget the previous toggle. Two roles are supported:
* Role 0 = toggle for down, role 1 = toggle for up
2013-07-28 01:31:45 +00:00
*
* @param[in] widget The GListObject structure to initialize. If this is NULL, the structure is dynamically allocated.
* @param[in] pInit The initialization parameters to use
2013-08-01 05:58:46 +00:00
* @param[in] multiselect If TRUE the list is multi-select instead of single-select.
2013-07-28 01:31:45 +00:00
*
* @return NULL if there is no resulting drawing area, otherwise a window handle.
*
* @api
*/
2013-08-01 05:58:46 +00:00
GHandle gwinListCreate(GListObject *widget, GWidgetInit *pInit, bool_t multiselect);
2013-07-17 15:49:21 +00:00
2013-07-28 01:31:45 +00:00
/**
* @brief Add an item to the list
*
* @note The ID you get returned is not static. If items get removed from the list, the list items get
* reordered.
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The string which shall be displayed in the list afterwards
* @param[in] useAlloc If set to TRUE, the string will be dynamically allocated. A static buffer must be passed otherwise
*
* @return The current ID of the item. The ID might change if you remove items from the middle of the list
*
* @api
*/
2013-07-25 17:15:51 +00:00
int gwinListAddItem(GHandle gh, const char* item, bool_t useAlloc);
2013-07-28 01:31:45 +00:00
/**
* @brief Get the name behind an item with a given ID
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
*
* @return The string of the list item or NULL on error
*
* @api
*/
const char* gwinListItemGetText(GHandle gh, int item);
2013-07-27 20:55:32 +00:00
2013-07-28 01:31:45 +00:00
/**
* @brief Get the ID of an item with a given name
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] text The item name
*
* @return The id of the list item or -1 on error
*
* @api
*/
2013-07-27 20:55:32 +00:00
int gwinListFindText(GHandle gh, const char* text);
2013-07-28 01:31:45 +00:00
/**
* @brief Set the custom parameter of an item with a given ID
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
* @param[in] param The parameter to be set
*
* @api
*/
2013-07-27 20:55:32 +00:00
void gwinListItemSetParam(GHandle gh, int item, uint16_t param);
2013-07-28 01:31:45 +00:00
/**
* @brief Get the custom parameter of an item with a given ID
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
*
* @return The parameter
*
* @api
*/
2013-07-27 20:55:32 +00:00
uint16_t gwinListItemGetParam(GHandle gh, int item);
2013-07-28 01:31:45 +00:00
/**
* @brief Delete all the items of the list
*
* @param[in] gh The widget handle (must be a list handle)
*
* @api
*/
void gwinListDeleteAll(GHandle gh);
2013-07-27 20:55:32 +00:00
2013-07-28 01:31:45 +00:00
/**
* @brief Delete an item from the list
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
*
* @api
*/
2013-07-27 20:55:32 +00:00
void gwinListItemDelete(GHandle gh, int item);
2013-07-28 01:31:45 +00:00
/**
* @brief Get the amount of items within the list
*
* @param[in] gh The widget handle (must be a list handle)
*
* @return The amount of items in the list
*
* @api
*/
2013-07-27 20:55:32 +00:00
int gwinListItemCount(GHandle gh);
2013-07-28 01:31:45 +00:00
/**
* @brief Check if an item with a given ID is selected
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
*
* @return TRUE if the item is selected, FALSE otherwise
*
* @api
*/
2013-07-27 20:55:32 +00:00
bool_t gwinListItemIsSelected(GHandle gh, int item);
2013-07-28 01:31:45 +00:00
/**
* @brief Get the ID of the selected item
*
* @param[in] gh The widget handle (must be a list handle)
*
* @return The ID of the selected list item for a single-select list.
*
* @note It always returns -1 (nothing selected) for a multi-select list.
* Instead use @p gwinListItemIsSelected() to get the selection status
* for a multi-select list.
2013-07-28 01:31:45 +00:00
*
* @api
*/
2013-07-27 20:55:32 +00:00
int gwinListGetSelected(GHandle gh);
#if GWIN_NEED_LIST_IMAGES
/**
* @brief Set the image for a list item
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
* @param[in] pimg The image to be displayed or NULL to turn off the image for this list item.
*
* @note The image should be up to 4 x (the font height) and a width of (the font height).
* The 1st (top) part of the image is displayed for a selected item.
* The 2nd part of the image is displayed for an unselected item.
* The 3rd part of the image is displayed for a disabled selected item.
* The 4th part of the image is displayed for a disabled unselected item.
* If the image is less than 4 times the font height then the image use is collapsed
* into the available height. For example, an image that equals the font height will use
* the same image for all four states.
* @note The image is only displayed while it is open. It is up to the application to open
* the image.
* @note The same image can be used on more than one list item.
* @note Images are aligned with the top (not the baseline) of the list item.
* @note When any item in the list has an image attached, space is allocated to display
* the images even if the image is closed or has been removed by calling @p gwinListItemSetImage()
* with a NULL image or by calling @p gwinListItemDelete(). The only way to turn-off the image area
* for this list is to call gwinListDeleteAll().
*
*/
void gwinListItemSetImage(GHandle gh, int item, gdispImage *pimg);
#endif
2013-07-17 15:49:21 +00:00
#ifdef __cplusplus
}
#endif
#endif // _GWIN_LIST_H
/** @} */