/* use inside searchfunc to add items */
int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid);
/* bfunc gets search item *poin as arg2, or if NULL the old string */
-void uiButSetSearchFunc (uiBut *but, uiButSearchFunc sfunc, void *arg1, uiButHandleFunc bfunc);
+void uiButSetSearchFunc (uiBut *but, uiButSearchFunc sfunc, void *arg1, uiButHandleFunc bfunc, void *active);
/* height in pixels, it's using hardcoded values still */
int uiSearchBoxhHeight(void);
}
/* arg is user value, searchfunc and handlefunc both get it as arg */
-void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc)
+/* if active set, button opens with this item visible and selected */
+void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc, void *active)
{
but->search_func= sfunc;
but->search_arg= arg;
- uiButSetFunc(but, bfunc, arg, NULL);
+ uiButSetFunc(but, bfunc, arg, active);
}
-
/* Program Init/Exit */
void UI_init(void)
but->rnasearchprop= searchprop;
but->flag |= UI_ICON_LEFT|UI_TEXT_LEFT;
- uiButSetSearchFunc(but, rna_search_cb, but, NULL);
+ uiButSetSearchFunc(but, rna_search_cb, but, NULL, NULL);
}
}
int *icons;
AutoComplete *autocpl;
+ void *active;
};
typedef struct uiSearchboxData {
return 1;
}
+ /* hijack for finding active item */
+ if(items->active) {
+ if(poin==items->active)
+ items->offset_i= items->totitem;
+ items->totitem++;
+ return 1;
+ }
+
if(items->totitem>=items->maxitem) {
items->more= 1;
return 0;
/* reset vars */
data->items.totitem= 0;
data->items.more= 0;
- if(reset==0)
+ if(reset==0) {
data->items.offset_i= data->items.offset;
+ }
else {
data->items.offset_i= data->items.offset= 0;
data->active= 0;
+
+ /* handle active */
+ if(but->search_func && but->func_arg2) {
+ data->items.active= but->func_arg2;
+ but->search_func(C, but->search_arg, but->editstr, &data->items);
+ data->items.active= NULL;
+
+ /* found active item, calculate real offset by centering it */
+ if(data->items.totitem) {
+ /* first case, begin of list */
+ if(data->items.offset_i < data->items.maxitem) {
+ data->active= data->items.offset_i+1;
+ data->items.offset_i= 0;
+ }
+ else {
+ /* second case, end of list */
+ if(data->items.totitem - data->items.offset_i <= data->items.maxitem) {
+ data->active= 1 + data->items.offset_i - data->items.totitem + data->items.maxitem;
+ data->items.offset_i= data->items.totitem - data->items.maxitem;
+ }
+ else {
+ /* center active item */
+ data->items.offset_i -= data->items.maxitem/2;
+ data->active= 1 + data->items.maxitem/2;
+ }
+ }
+ }
+ data->items.offset= data->items.offset_i;
+ data->items.totitem= 0;
+ }
}
/* callback */
if(but->search_func)
but->search_func(C, but->search_arg, but->editstr, &data->items);
- if(reset) {
+ /* handle case where editstr is equal to one of items */
+ if(reset && data->active==0) {
int a;
- /* handle case where editstr is equal to one of items */
+
for(a=0; a<data->items.totitem; a++) {
char *cpoin= strchr(data->items.names[a], '|');
}
/* indicate more */
if(data->items.more) {
+ ui_searchbox_butrect(&rect, data, data->items.maxitem-1);
glEnable(GL_BLEND);
- UI_icon_draw((data->bbox.xmax-data->bbox.xmin)/2, 8, ICON_TRIA_DOWN);
+ UI_icon_draw((rect.xmax-rect.xmin)/2, rect.ymin-9, ICON_TRIA_DOWN);
glDisable(GL_BLEND);
}
if(data->items.offset) {
+ ui_searchbox_butrect(&rect, data, 0);
glEnable(GL_BLEND);
- UI_icon_draw((data->bbox.xmax-data->bbox.xmin)/2, data->bbox.ymax-13, ICON_TRIA_UP);
+ UI_icon_draw((rect.xmax-rect.xmin)/2, rect.ymax-7, ICON_TRIA_UP);
glDisable(GL_BLEND);
}
}
{
static char search[256];
static TemplateID template;
+ PointerRNA idptr;
wmEvent event;
wmWindow *win= CTX_wm_window(C);
uiBlock *block;
/* arg_litem is malloced, can be freed by parent button */
template= *((TemplateID*)arg_litem);
+ /* get active id for showing first item */
+ idptr= RNA_property_pointer_get(&template.ptr, template.prop);
+
block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
- uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb);
+ uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
uiBoundsBlock(block, 6);
uiBlockSetDirection(block, UI_DOWN);
uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
- uiButSetSearchFunc(but, id_search_cb, ¶ms, id_search_call_cb);
+ uiButSetSearchFunc(but, id_search_cb, ¶ms, id_search_call_cb, NULL);
uiBoundsBlock(block, 6);
uiBlockSetDirection(block, UI_DOWN);
static char search[256]= "";
uiBut *but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, xco+5, yco, 120, 19, "");
- uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb);
+ uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
xco+= 125;
}
uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, OP_MAX_TYPENAME, 10, 0, 150, 19, "");
- uiButSetSearchFunc(but, operator_search_cb, arg_listbase, operator_call_cb);
+ uiButSetSearchFunc(but, operator_search_cb, arg_listbase, operator_call_cb, NULL);
uiBoundsBlock(block, 6);
uiBlockSetDirection(block, UI_DOWN);