* Added option for panel to be closed by default.
* Added support for RNA property and enum icons in buttons.
* Remove some deprecated RNA menu code.
* Fix issue with newly created panels not being inserted in the
  right place.
* Fix issue with 3-split layout not being divided correctly.
* FIx issue with menu items not drawing correct using python UI.
This commit is contained in:
Brecht Van Lommel 2009-06-16 01:08:39 +00:00
parent 51fbc95e8c
commit f10541f7cf
10 changed files with 121 additions and 104 deletions

@ -157,6 +157,8 @@ typedef struct PanelType {
int space_type; int space_type;
int region_type; int region_type;
int flag;
/* verify if the panel should draw or not */ /* verify if the panel should draw or not */
int (*poll)(const struct bContext *, struct PanelType *); int (*poll)(const struct bContext *, struct PanelType *);
/* draw header (optional) */ /* draw header (optional) */

@ -491,7 +491,7 @@ void autocomplete_end(AutoComplete *autocpl, char *autoname);
void uiBeginPanels(const struct bContext *C, struct ARegion *ar); void uiBeginPanels(const struct bContext *C, struct ARegion *ar);
void uiEndPanels(const struct bContext *C, struct ARegion *ar); void uiEndPanels(const struct bContext *C, struct ARegion *ar);
struct Panel *uiBeginPanel(struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open); struct Panel *uiBeginPanel(struct ScrArea *sa, struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open);
void uiEndPanel(uiBlock *block, int width, int height); void uiEndPanel(uiBlock *block, int width, int height);
/* Handlers /* Handlers
@ -539,8 +539,6 @@ void UI_exit(void);
uiBut *uiDefMenuButO(uiBlock *block, char *opname, char *name); uiBut *uiDefMenuButO(uiBlock *block, char *opname, char *name);
uiBut *uiDefMenuSep(uiBlock *block); uiBut *uiDefMenuSep(uiBlock *block);
uiBut *uiDefMenuSub(uiBlock *block, uiBlockCreateFunc func, char *name);
uiBut *uiDefMenuTogR(uiBlock *block, struct PointerRNA *ptr, char *propname, char *propvalue, char *name);
/* Layout /* Layout
* *

@ -1859,18 +1859,24 @@ void ui_check_but(uiBut *but)
case ICONTOG: case ICONTOG:
case ICONTOGN: case ICONTOGN:
if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
if(but->flag & UI_SELECT) but->iconadd= 1; if(but->flag & UI_SELECT) but->iconadd= 1;
else but->iconadd= 0; else but->iconadd= 0;
}
break; break;
case ICONROW: case ICONROW:
if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
value= ui_get_but_val(but); value= ui_get_but_val(but);
but->iconadd= (int)value- (int)(but->hardmin); but->iconadd= (int)value- (int)(but->hardmin);
}
break; break;
case ICONTEXTROW: case ICONTEXTROW:
if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
value= ui_get_but_val(but); value= ui_get_but_val(but);
but->iconadd= (int)value- (int)(but->hardmin); but->iconadd= (int)value- (int)(but->hardmin);
}
break; break;
} }
@ -2267,7 +2273,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
uiBut *but; uiBut *but;
PropertyRNA *prop; PropertyRNA *prop;
PropertyType proptype; PropertyType proptype;
int freestr= 0; int freestr= 0, icon= 0;
prop= RNA_struct_find_property(ptr, propname); prop= RNA_struct_find_property(ptr, propname);
@ -2279,14 +2285,22 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
if(type == MENU && proptype == PROP_ENUM) { if(type == MENU && proptype == PROP_ENUM) {
const EnumPropertyItem *item; const EnumPropertyItem *item;
DynStr *dynstr; DynStr *dynstr;
int i, totitem; int i, totitem, value;
RNA_property_enum_items(ptr, prop, &item, &totitem); RNA_property_enum_items(ptr, prop, &item, &totitem);
value= RNA_property_enum_get(ptr, prop);
dynstr= BLI_dynstr_new(); dynstr= BLI_dynstr_new();
BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop)); BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop));
for(i=0; i<totitem; i++) for(i=0; i<totitem; i++) {
if(item[i].icon)
BLI_dynstr_appendf(dynstr, "|%s %%i%d %%x%d", item[i].name, item[i].icon, item[i].value);
else
BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value); BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value);
if(value == item[i].value)
icon= item[i].icon;
}
str= BLI_dynstr_get_cstring(dynstr); str= BLI_dynstr_get_cstring(dynstr);
BLI_dynstr_free(dynstr); BLI_dynstr_free(dynstr);
@ -2297,15 +2311,20 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
int i, totitem; int i, totitem;
RNA_property_enum_items(ptr, prop, &item, &totitem); RNA_property_enum_items(ptr, prop, &item, &totitem);
for(i=0; i<totitem; i++) for(i=0; i<totitem; i++) {
if(item[i].value == (int)max) if(item[i].value == (int)max) {
str= (char*)item[i].name; str= (char*)item[i].name;
icon= item[i].icon;
}
}
if(!str) if(!str)
str= (char*)RNA_property_ui_name(prop); str= (char*)RNA_property_ui_name(prop);
} }
else else {
str= (char*)RNA_property_ui_name(prop); str= (char*)RNA_property_ui_name(prop);
icon= RNA_property_ui_icon(prop);
}
} }
if(!tip) { if(!tip) {
@ -2384,6 +2403,13 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
if(type == IDPOIN) if(type == IDPOIN)
uiButSetCompleteFunc(but, ui_rna_ID_autocomplete, but); uiButSetCompleteFunc(but, ui_rna_ID_autocomplete, but);
}
if(icon) {
but->icon= (BIFIconID)icon;
but->flag |= UI_HAS_ICON;
but->flag|= UI_ICON_LEFT;
} }
if (!prop || !RNA_property_editable(&but->rnapoin, prop)) { if (!prop || !RNA_property_editable(&but->rnapoin, prop)) {
@ -2653,8 +2679,10 @@ uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, short x1, s
but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
if(but) { if(but) {
if(icon) {
but->icon= (BIFIconID) icon; but->icon= (BIFIconID) icon;
but->flag|= UI_HAS_ICON; but->flag|= UI_HAS_ICON;
}
ui_check_but(but); ui_check_but(but);
} }
@ -2736,8 +2764,10 @@ uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, char *s
but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
if(but) { if(but) {
if(icon) {
but->icon= (BIFIconID) icon; but->icon= (BIFIconID) icon;
but->flag|= UI_HAS_ICON; but->flag|= UI_HAS_ICON;
}
but->flag|= UI_ICON_LEFT; but->flag|= UI_ICON_LEFT;
ui_check_but(but); ui_check_but(but);
} }
@ -2779,60 +2809,6 @@ uiBut *uiDefMenuSep(uiBlock *block)
return uiDefBut(block, SEPR, 0, "", 0, y, MENU_WIDTH, MENU_SEP_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); return uiDefBut(block, SEPR, 0, "", 0, y, MENU_WIDTH, MENU_SEP_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
} }
uiBut *uiDefMenuSub(uiBlock *block, uiBlockCreateFunc func, char *name)
{
int y= ui_menu_y(block) - MENU_ITEM_HEIGHT;
return uiDefIconTextBlockBut(block, func, NULL, ICON_BLANK1, name, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT-1, "");
}
uiBut *uiDefMenuTogR(uiBlock *block, PointerRNA *ptr, char *propname, char *propvalue, char *name)
{
uiBut *but;
PropertyRNA *prop;
PropertyType type;
const EnumPropertyItem *item;
int a, value, totitem, icon= ICON_CHECKBOX_DEHLT;
int y= ui_menu_y(block) - MENU_ITEM_HEIGHT;
prop= RNA_struct_find_property(ptr, propname);
if(prop) {
type= RNA_property_type(prop);
if(type == PROP_BOOLEAN) {
if(RNA_property_boolean_get(ptr, prop))
icon= ICON_CHECKBOX_HLT;
return uiDefIconTextButR(block, TOG, 0, icon, name, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT-1, ptr, propname, 0, 0, 0, 0, 0, NULL);
}
else if(type == PROP_ENUM) {
RNA_property_enum_items(ptr, prop, &item, &totitem);
value= 0;
for(a=0; a<totitem; a++) {
if(propvalue && strcmp(propvalue, item[a].identifier) == 0) {
value= item[a].value;
if(!name)
name= (char*)item[a].name;
if(RNA_property_enum_get(ptr, prop) == value)
icon= ICON_CHECKBOX_HLT;
break;
}
}
if(a != totitem)
return uiDefIconTextButR(block, ROW, 0, icon, name, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT-1, ptr, propname, 0, 0, value, 0, 0, NULL);
}
}
/* not found */
uiBlockSetButLock(block, 1, "");
but= uiDefIconTextBut(block, BUT, 0, ICON_BLANK1, propname, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
uiBlockClearButLock(block);
return but;
}
/* END Button containing both string label and icon */ /* END Button containing both string label and icon */
void uiSetButLink(uiBut *but, void **poin, void ***ppoin, short *tot, int from, int to) void uiSetButLink(uiBut *but, void **poin, void ***ppoin, short *tot, int from, int to)

@ -427,19 +427,29 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon
uiBlockSetCurLayout(block, layout); uiBlockSetCurLayout(block, layout);
} }
static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int x, int y, int w, int h) static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, char *uiname, int x, int y, int w, int h)
{ {
const EnumPropertyItem *item; const EnumPropertyItem *item;
int a, totitem, itemw; const char *identifier;
const char *propname; char *name;
int a, totitem, itemw, icon, value;
propname= RNA_property_identifier(prop); identifier= RNA_property_identifier(prop);
RNA_property_enum_items(ptr, prop, &item, &totitem); RNA_property_enum_items(ptr, prop, &item, &totitem);
uiBlockSetCurLayout(block, ui_item_local_sublayout(layout, layout, 1)); uiBlockSetCurLayout(block, ui_item_local_sublayout(layout, layout, 1));
for(a=0; a<totitem; a++) { for(a=0; a<totitem; a++) {
itemw= ui_text_icon_width(block->curlayout, (char*)item[a].name, 0); name= (!uiname || uiname[0])? (char*)item[a].name: "";
uiDefButR(block, ROW, 0, NULL, 0, 0, itemw, h, ptr, propname, -1, 0, item[a].value, -1, -1, NULL); icon= item[a].icon;
value= item[a].value;
itemw= ui_text_icon_width(block->curlayout, name, icon);
if(icon && strcmp(name, "") != 0)
uiDefIconTextButR(block, ROW, 0, icon, name, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
else if(icon)
uiDefIconButR(block, ROW, 0, icon, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
else
uiDefButR(block, ROW, 0, name, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
} }
uiBlockSetCurLayout(block, layout); uiBlockSetCurLayout(block, layout);
} }
@ -732,6 +742,8 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper
/* set name and icon */ /* set name and icon */
if(!name) if(!name)
name= (char*)RNA_property_ui_name(prop); name= (char*)RNA_property_ui_name(prop);
if(!icon)
icon= RNA_property_ui_icon(prop);
if(ELEM5(type, PROP_INT, PROP_FLOAT, PROP_STRING, PROP_ENUM, PROP_POINTER)) if(ELEM5(type, PROP_INT, PROP_FLOAT, PROP_STRING, PROP_ENUM, PROP_POINTER))
name= ui_item_name_add_colon(name, namestr); name= ui_item_name_add_colon(name, namestr);
@ -764,7 +776,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper
} }
/* expanded enum */ /* expanded enum */
else if(type == PROP_ENUM && expand) else if(type == PROP_ENUM && expand)
ui_item_enum_row(layout, block, ptr, prop, 0, 0, w, h); ui_item_enum_row(layout, block, ptr, prop, name, 0, 0, w, h);
/* property with separate label */ /* property with separate label */
else if(type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER) else if(type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER)
ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h); ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h);
@ -858,7 +870,7 @@ static void ui_item_menu(uiLayout *layout, char *name, int icon, uiMenuCreateFun
uiBlockSetCurLayout(block, layout); uiBlockSetCurLayout(block, layout);
if(layout->root->type == UI_LAYOUT_HEADER) if(layout->root->type == UI_LAYOUT_HEADER)
uiBlockSetEmboss(block, UI_EMBOSSP); uiBlockSetEmboss(block, UI_EMBOSS);
if(!name) if(!name)
name= ""; name= "";
@ -869,7 +881,7 @@ static void ui_item_menu(uiLayout *layout, char *name, int icon, uiMenuCreateFun
h= UI_UNIT_Y; h= UI_UNIT_Y;
if(layout->root->type == UI_LAYOUT_HEADER) /* ugly .. */ if(layout->root->type == UI_LAYOUT_HEADER) /* ugly .. */
w -= 3; w -= 10;
if(icon) if(icon)
but= uiDefIconTextMenuBut(block, func, arg, icon, (char*)name, 0, 0, w, h, ""); but= uiDefIconTextMenuBut(block, func, arg, icon, (char*)name, 0, 0, w, h, "");
@ -1484,6 +1496,7 @@ static void ui_litem_layout_split(uiLayout *litem)
{ {
uiLayoutItemSplt *split= (uiLayoutItemSplt*)litem; uiLayoutItemSplt *split= (uiLayoutItemSplt*)litem;
uiItem *item; uiItem *item;
float percentage;
int itemh, x, y, w, tot=0, colw=0; int itemh, x, y, w, tot=0, colw=0;
x= litem->x; x= litem->x;
@ -1495,8 +1508,10 @@ static void ui_litem_layout_split(uiLayout *litem)
if(tot == 0) if(tot == 0)
return; return;
percentage= (split->percentage == 0.0f)? 1.0f/(float)tot: split->percentage;
w= (litem->w - (tot-1)*litem->space); w= (litem->w - (tot-1)*litem->space);
colw= w*split->percentage; colw= w*percentage;
colw= MAX2(colw, 0); colw= MAX2(colw, 0);
for(item=litem->items.first; item; item=item->next) { for(item=litem->items.first; item; item=item->next) {
@ -1506,7 +1521,7 @@ static void ui_litem_layout_split(uiLayout *litem)
x += colw; x += colw;
if(item->next) { if(item->next) {
colw= (w - (w*split->percentage))/(tot-1); colw= (w - (int)(w*percentage))/(tot-1);
colw= MAX2(colw, 0); colw= MAX2(colw, 0);
x += litem->space; x += litem->space;
@ -1637,7 +1652,7 @@ uiLayout *uiLayoutSplit(uiLayout *layout, float percentage)
split->litem.enabled= 1; split->litem.enabled= 1;
split->litem.context= layout->context; split->litem.context= layout->context;
split->litem.space= layout->root->style->columnspace; split->litem.space= layout->root->style->columnspace;
split->percentage= (percentage == 0.0f)? 0.5f: percentage; split->percentage= percentage;
BLI_addtail(&layout->items, split); BLI_addtail(&layout->items, split);
uiBlockSetCurLayout(layout->root->block, &split->litem); uiBlockSetCurLayout(layout->root->block, &split->litem);

@ -69,6 +69,7 @@
#define PNL_ACTIVE 2 #define PNL_ACTIVE 2
#define PNL_WAS_ACTIVE 4 #define PNL_WAS_ACTIVE 4
#define PNL_ANIM_ALIGN 8 #define PNL_ANIM_ALIGN 8
#define PNL_NEW_ADDED 16
typedef enum uiHandlePanelState { typedef enum uiHandlePanelState {
PANEL_STATE_DRAG, PANEL_STATE_DRAG,
@ -157,18 +158,20 @@ static void ui_panel_copy_offset(Panel *pa, Panel *papar)
pa->ofsy= papar->ofsy + papar->sizey-pa->sizey; pa->ofsy= papar->ofsy + papar->sizey-pa->sizey;
} }
Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt, int *open) Panel *uiBeginPanel(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, int *open)
{ {
uiStyle *style= U.uistyles.first; uiStyle *style= U.uistyles.first;
Panel *pa, *patab, *palast, *panext; Panel *pa, *patab, *palast, *panext;
char *panelname= pt->label; char *drawname= pt->label;
char *tabname= pt->label; char *idname= pt->idname;
char *tabname= pt->idname;
char *hookname= NULL; char *hookname= NULL;
int newpanel; int newpanel;
int align= panel_aligned(sa, ar);
/* check if Panel exists, then use that one */ /* check if Panel exists, then use that one */
for(pa=ar->panels.first; pa; pa=pa->next) for(pa=ar->panels.first; pa; pa=pa->next)
if(strncmp(pa->panelname, panelname, UI_MAX_NAME_STR)==0) if(strncmp(pa->panelname, idname, UI_MAX_NAME_STR)==0)
if(strncmp(pa->tabname, tabname, UI_MAX_NAME_STR)==0) if(strncmp(pa->tabname, tabname, UI_MAX_NAME_STR)==0)
break; break;
@ -181,13 +184,21 @@ Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt, int *open)
/* new panel */ /* new panel */
pa= MEM_callocN(sizeof(Panel), "new panel"); pa= MEM_callocN(sizeof(Panel), "new panel");
pa->type= pt; pa->type= pt;
BLI_strncpy(pa->panelname, panelname, UI_MAX_NAME_STR); BLI_strncpy(pa->panelname, idname, UI_MAX_NAME_STR);
BLI_strncpy(pa->tabname, tabname, UI_MAX_NAME_STR); BLI_strncpy(pa->tabname, tabname, UI_MAX_NAME_STR);
if(pt->flag & PNL_DEFAULT_CLOSED) {
if(align == BUT_VERTICAL)
pa->flag |= PNL_CLOSEDY;
else
pa->flag |= PNL_CLOSEDX;
}
pa->ofsx= 0; pa->ofsx= 0;
pa->ofsy= style->panelouter; pa->ofsy= style->panelouter;
pa->sizex= 0; pa->sizex= 0;
pa->sizey= 0; pa->sizey= 0;
pa->runtime_flag |= PNL_NEW_ADDED;
BLI_addtail(&ar->panels, pa); BLI_addtail(&ar->panels, pa);
@ -207,6 +218,8 @@ Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt, int *open)
} }
} }
BLI_strncpy(pa->drawname, drawname, UI_MAX_NAME_STR);
/* if a new panel is added, we insert it right after the panel /* if a new panel is added, we insert it right after the panel
* that was last added. this way new panels are inserted in the * that was last added. this way new panels are inserted in the
* right place between versions */ * right place between versions */
@ -235,7 +248,6 @@ Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt, int *open)
if(pa->flag & PNL_CLOSED) return pa; if(pa->flag & PNL_CLOSED) return pa;
*open= 1; *open= 1;
pa->drawname[0]= 0; /* otherwise closes panels show wrong title */
return pa; return pa;
} }
@ -244,6 +256,12 @@ void uiEndPanel(uiBlock *block, int width, int height)
{ {
Panel *pa= block->panel; Panel *pa= block->panel;
if(pa->runtime_flag & PNL_NEW_ADDED) {
pa->runtime_flag &= ~PNL_NEW_ADDED;
pa->sizex= width;
pa->sizey= height;
}
else if(!(width == 0 || height == 0)) {
if(pa->sizex != width || pa->sizey != height) { if(pa->sizex != width || pa->sizey != height) {
pa->runtime_flag |= PNL_ANIM_ALIGN; pa->runtime_flag |= PNL_ANIM_ALIGN;
pa->ofsy += pa->sizey-height; pa->ofsy += pa->sizey-height;
@ -251,6 +269,7 @@ void uiEndPanel(uiBlock *block, int width, int height)
pa->sizex= width; pa->sizex= width;
pa->sizey= height; pa->sizey= height;
}
} }
#if 0 #if 0

@ -1448,10 +1448,8 @@ void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type)
void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname) void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
{ {
uiBlock *block;
uiLayout *uRow, *uSplit, *uCol; uiLayout *uRow, *uSplit, *uCol;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *type;
int groups, cols, layers; int groups, cols, layers;
int group, col, layer, row; int group, col, layer, row;

@ -874,9 +874,9 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
and offset the text label to accomodate it */ and offset the text label to accomodate it */
if (but->flag & UI_HAS_ICON) { if (but->flag & UI_HAS_ICON) {
widget_draw_icon(but, but->icon, 0, rect); widget_draw_icon(but, but->icon+but->iconadd, 0, rect);
rect->xmin += UI_icon_get_width(but->icon); rect->xmin += UI_icon_get_width(but->icon+but->iconadd);
if(but->editstr || (but->flag & UI_TEXT_LEFT)) if(but->editstr || (but->flag & UI_TEXT_LEFT))
rect->xmin += 5; rect->xmin += 5;

@ -1106,6 +1106,7 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *context) void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *context)
{ {
ScrArea *sa= CTX_wm_area(C);
uiStyle *style= U.uistyles.first; uiStyle *style= U.uistyles.first;
uiBlock *block; uiBlock *block;
PanelType *pt; PanelType *pt;
@ -1143,7 +1144,7 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
/* draw panel */ /* draw panel */
if(pt->draw && (!pt->poll || pt->poll(C, pt))) { if(pt->draw && (!pt->poll || pt->poll(C, pt))) {
block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS); block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS);
panel= uiBeginPanel(ar, block, pt, &open); panel= uiBeginPanel(sa, ar, block, pt, &open);
if(vertical) if(vertical)
y -= header; y -= header;
@ -1161,7 +1162,6 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
} }
if(open) { if(open) {
panel->type= pt;
panel->layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, panel->layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
style->panelspace, 0, w-2*style->panelspace, em, style); style->panelspace, 0, w-2*style->panelspace, em, style);
@ -1173,8 +1173,10 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex
yco -= 2*style->panelspace; yco -= 2*style->panelspace;
uiEndPanel(block, w, -yco); uiEndPanel(block, w, -yco);
} }
else else {
yco= 0; yco= 0;
uiEndPanel(block, w, 0);
}
uiEndBlock(C, block); uiEndBlock(C, block);

@ -205,6 +205,9 @@ typedef struct ARegion {
#define PNL_SNAP_DIST 9.0 #define PNL_SNAP_DIST 9.0
/* paneltype flag */
#define PNL_DEFAULT_CLOSED 1
/* screen handlers */ /* screen handlers */
#define SCREEN_MAXHANDLER 8 #define SCREEN_MAXHANDLER 8

@ -603,6 +603,10 @@ static void rna_def_panel(BlenderRNA *brna)
prop= RNA_def_property(srna, "context", PROP_STRING, PROP_NONE); prop= RNA_def_property(srna, "context", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "type->context"); RNA_def_property_string_sdna(prop, NULL, "type->context");
RNA_def_property_flag(prop, PROP_REGISTER); RNA_def_property_flag(prop, PROP_REGISTER);
prop= RNA_def_property(srna, "default_closed", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "type->flag", PNL_DEFAULT_CLOSED);
RNA_def_property_flag(prop, PROP_REGISTER);
} }
static void rna_def_header(BlenderRNA *brna) static void rna_def_header(BlenderRNA *brna)