forked from RepoMirrors/bemenu
Setter first, then getter.
This commit is contained in:
parent
702d808b28
commit
9525c77f55
61
lib/bemenu.h
61
lib/bemenu.h
@ -218,15 +218,6 @@ int bmMenuRemoveItemAt(bmMenu *menu, unsigned int index);
|
||||
*/
|
||||
int bmMenuRemoveItem(bmMenu *menu, bmItem *item);
|
||||
|
||||
|
||||
/**
|
||||
* Get highlighted item from bmMenu instance.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get highlighted item.
|
||||
* @return Selected bmItem instance, **NULL** if none highlighted.
|
||||
*/
|
||||
bmItem* bmMenuGetHighlightedItem(const bmMenu *menu);
|
||||
|
||||
/**
|
||||
* Highlight item in menu by index.
|
||||
*
|
||||
@ -245,13 +236,12 @@ int bmMenuSetHighlightedIndex(bmMenu *menu, unsigned int index);
|
||||
int bmMenuSetHighlighted(bmMenu *menu, bmItem *item);
|
||||
|
||||
/**
|
||||
* Get selected items from bmMenu instance.
|
||||
* Get highlighted item from bmMenu instance.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get selected items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
* @param menu bmMenu instance from where to get highlighted item.
|
||||
* @return Selected bmItem instance, **NULL** if none highlighted.
|
||||
*/
|
||||
bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
bmItem* bmMenuGetHighlightedItem(const bmMenu *menu);
|
||||
|
||||
/**
|
||||
* Set selected items to bmMenu instance.
|
||||
@ -266,27 +256,13 @@ bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
int bmMenuSetSelectedItems(bmMenu *menu, bmItem **items, unsigned int nmemb);
|
||||
|
||||
/**
|
||||
* Get filtered (displayed) items from bmMenu instance.
|
||||
* Get selected items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
|
||||
* Do not store this pointer.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get filtered items.
|
||||
* @param menu bmMenu instance from where to get selected items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
|
||||
/**
|
||||
* Get items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function may be invalid after removing or adding new items.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
|
||||
/**
|
||||
* Set items to bmMenu instance.
|
||||
@ -301,6 +277,29 @@ bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
*/
|
||||
int bmMenuSetItems(bmMenu *menu, const bmItem **items, unsigned int nmemb);
|
||||
|
||||
/**
|
||||
* Get items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function may be invalid after removing or adding new items.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
|
||||
/**
|
||||
* Get filtered (displayed) items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
|
||||
* Do not store this pointer.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get filtered items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb);
|
||||
|
||||
/** @} Menu Items */
|
||||
|
||||
/**
|
||||
|
102
lib/menu.c
102
lib/menu.c
@ -265,25 +265,6 @@ int bmMenuRemoveItem(bmMenu *menu, bmItem *item)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highlighted item from bmMenu instance.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get highlighted item.
|
||||
* @return Selected bmItem instance, **NULL** if none highlighted.
|
||||
*/
|
||||
bmItem* bmMenuGetHighlightedItem(const bmMenu *menu)
|
||||
{
|
||||
assert(menu);
|
||||
|
||||
unsigned int count;
|
||||
bmItem **items = bmMenuGetFilteredItems(menu, &count);
|
||||
|
||||
if (!items || count <= menu->index)
|
||||
return NULL;
|
||||
|
||||
return items[menu->index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight item in menu by index.
|
||||
*
|
||||
@ -323,16 +304,22 @@ int bmMenuSetHighlighted(bmMenu *menu, bmItem *item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get selected items from bmMenu instance.
|
||||
* Get highlighted item from bmMenu instance.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get selected items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
* @param menu bmMenu instance from where to get highlighted item.
|
||||
* @return Selected bmItem instance, **NULL** if none highlighted.
|
||||
*/
|
||||
bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb)
|
||||
bmItem* bmMenuGetHighlightedItem(const bmMenu *menu)
|
||||
{
|
||||
assert(menu);
|
||||
return _bmItemListGetItems(&menu->selection, outNmemb);
|
||||
|
||||
unsigned int count;
|
||||
bmItem **items = bmMenuGetFilteredItems(menu, &count);
|
||||
|
||||
if (!items || count <= menu->index)
|
||||
return NULL;
|
||||
|
||||
return items[menu->index];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -352,38 +339,16 @@ int bmMenuSetSelectedItems(bmMenu *menu, bmItem **items, unsigned int nmemb)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filtered (displayed) items from bmMenu instance.
|
||||
* Get selected items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
|
||||
* Do not store this pointer.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get filtered items.
|
||||
* @param menu bmMenu instance from where to get selected items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb)
|
||||
bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb)
|
||||
{
|
||||
assert(menu);
|
||||
|
||||
if (menu->filtered.list)
|
||||
return _bmItemListGetItems(&menu->filtered, outNmemb);
|
||||
|
||||
return _bmItemListGetItems(&menu->items, outNmemb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function may be invalid after removing or adding new items.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb)
|
||||
{
|
||||
assert(menu);
|
||||
return _bmItemListGetItems(&menu->items, outNmemb);
|
||||
return _bmItemListGetItems(&menu->selection, outNmemb);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -411,6 +376,41 @@ int bmMenuSetItems(bmMenu *menu, const bmItem **items, unsigned int nmemb)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function may be invalid after removing or adding new items.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb)
|
||||
{
|
||||
assert(menu);
|
||||
return _bmItemListGetItems(&menu->items, outNmemb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filtered (displayed) items from bmMenu instance.
|
||||
*
|
||||
* @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
|
||||
* Do not store this pointer.
|
||||
*
|
||||
* @param menu bmMenu instance from where to get filtered items.
|
||||
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
|
||||
* @return Pointer to array of bmItem pointers.
|
||||
*/
|
||||
bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb)
|
||||
{
|
||||
assert(menu);
|
||||
|
||||
if (menu->filtered.list)
|
||||
return _bmItemListGetItems(&menu->filtered, outNmemb);
|
||||
|
||||
return _bmItemListGetItems(&menu->items, outNmemb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render bmMenu instance using chosen draw method.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user