diff options
author | Ton Roosendaal <ton@blender.org> | 2009-06-29 15:29:52 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2009-06-29 15:29:52 +0400 |
commit | 7ca31bb171b2c94f8e9b928990363a42af8716fb (patch) | |
tree | 371eee682709fb52f3c6b2722a006d35b5b8576e /source/blender/editors/interface | |
parent | c50bbe5ae726edfb265bd54cb7ce0e547e3f4b31 (diff) |
2.5
Search Menu: added feature that on opening, it shows the
current ID block, and selects it. Same can be used for other
searches, just pass on pointer to active item for the search
callback.
Also fixed arrow triangle draw for search.
Diffstat (limited to 'source/blender/editors/interface')
5 files changed, 58 insertions, 11 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index a9866d8898e..fcea74cc22b 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2919,15 +2919,15 @@ uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxle } /* 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) diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 94280ec37d3..f9816235b88 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -936,7 +936,7 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN 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); } } diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 61cf612e912..49e3abf4d0c 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -437,6 +437,7 @@ struct uiSearchItems { int *icons; AutoComplete *autocpl; + void *active; }; typedef struct uiSearchboxData { @@ -459,6 +460,14 @@ int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int icon 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; @@ -597,20 +606,52 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, int reset) /* 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], '|'); @@ -666,13 +707,15 @@ static void ui_searchbox_region_draw(const bContext *C, ARegion *ar) } /* 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); } } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index a006187c4aa..b128da7b97f 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -112,6 +112,7 @@ static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem) { static char search[256]; static TemplateID template; + PointerRNA idptr; wmEvent event; wmWindow *win= CTX_wm_window(C); uiBlock *block; @@ -122,6 +123,9 @@ static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem) /* 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); @@ -129,7 +133,7 @@ static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem) 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); diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 3ed81a3e9bc..eb79848d7d2 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -327,7 +327,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_params) 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); |