[Bf-blender-cvs] [460318257c4] modifier-panels-ui: Use expanding buttons layout for modifier box headers
Julian Eisel
noreply at git.blender.org
Fri Apr 17 16:36:32 CEST 2020
Commit: 460318257c45bf066bc56baa3864e73a809193bf
Author: Julian Eisel
Date: Fri Apr 17 16:32:42 2020 +0200
Branches: modifier-panels-ui
https://developer.blender.org/rB460318257c45bf066bc56baa3864e73a809193bf
Use expanding buttons layout for modifier box headers
Had to fix a crash in the alignment code for too small areas.
Also changed panel type flag defines to use an enum.
===================================================================
M source/blender/editors/interface/interface_align.c
M source/blender/editors/screen/area.c
M source/blender/makesdna/DNA_screen_types.h
M source/blender/modifiers/intern/MOD_ui_common.c
===================================================================
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c
index 09811fab52d..6529bf8fc5d 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.c
@@ -502,7 +502,7 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
butal->but->drawflag |= align;
butal_other->but->drawflag |= align_opp;
- if (butal->dists[side]) {
+ if (!IS_EQF(butal->dists[side], 0.0f)) {
float *delta = &butal->dists[side];
if (*butal->borders[side] < *butal_other->borders[side_opp]) {
@@ -513,7 +513,7 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
}
co = (*butal->borders[side] += *delta);
- if (butal_other->dists[side_opp]) {
+ if (!IS_EQF(butal_other->dists[side_opp], 0.0f)) {
BLI_assert(butal_other->dists[side_opp] * 0.5f == fabsf(*delta));
*butal_other->borders[side_opp] = co;
butal_other->dists[side_opp] = 0.0f;
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index adbb3314bba..5d88925c6fb 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2379,6 +2379,7 @@ static void ed_panel_draw(const bContext *C,
/* bad fixed values */
int xco, yco, h = 0;
+ int headerend = w - UI_UNIT_X;
if (pt->draw_header_preset && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
/* for preset menu */
@@ -2394,8 +2395,6 @@ static void ed_panel_draw(const bContext *C,
pt->draw_header_preset(C, panel);
- int headerend = w - UI_UNIT_X;
-
UI_block_layout_resolve(block, &xco, &yco);
UI_block_translate(block, headerend - xco, 0);
panel->layout = NULL;
@@ -2403,11 +2402,27 @@ static void ed_panel_draw(const bContext *C,
if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
int labelx, labely;
+
UI_panel_label_offset(block, &labelx, &labely);
- /* for enabled buttons */
- panel->layout = UI_block_layout(
- block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, labelx, labely, UI_UNIT_Y, 1, 0, style);
+ /* Unusual case: Use extending layout (buttons stretch to available width). */
+ if (pt->flag & PNL_LAYOUT_HEADER_EXTEND) {
+ uiLayout *layout = UI_block_layout(block,
+ UI_LAYOUT_VERTICAL,
+ UI_LAYOUT_PANEL,
+ labelx,
+ labely,
+ headerend - 2 * style->panelspace,
+ 1,
+ 0,
+ style);
+ panel->layout = uiLayoutRow(layout, false);
+ }
+ /* Regular case: Normal panel with fixed size buttons. */
+ else {
+ panel->layout = UI_block_layout(
+ block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, labelx, labely, UI_UNIT_Y, 1, 0, style);
+ }
pt->draw_header(C, panel);
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 5456af7aebb..02de4457c2d 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -547,15 +547,18 @@ enum {
/* #define PNL_SNAP_DIST 9.0 */
/* paneltype flag */
-#define PNL_DEFAULT_CLOSED (1 << 0)
-#define PNL_NO_HEADER (1 << 1)
-#define PNL_LAYOUT_VERT_BAR (1 << 2)
-/** This panel type represents data external to the UI. */
-#define PNL_LIST (1 << 3)
-/* Convenience flag to avoid searching through parents to tell if it belongs to a list panel. */
-#define PNL_LIST_SUBPANEL (1 << 4)
-/** This panel marks the start of a list panel sequence. Not recreated on list change. */
-#define PNL_LIST_START (1 << 5)
+enum {
+ PNL_DEFAULT_CLOSED = (1 << 0),
+ PNL_NO_HEADER = (1 << 1),
+ PNL_LAYOUT_HEADER_EXTEND = (1 << 2),
+ PNL_LAYOUT_VERT_BAR = (1 << 3),
+ /** This panel type represents data external to the UI. */
+ PNL_LIST = (1 << 4),
+ /* Convenience flag to avoid searching through parents to tell if it belongs to a list panel. */
+ PNL_LIST_SUBPANEL = (1 << 5),
+ /** This panel marks the start of a list panel sequence. Not recreated on list change. */
+ PNL_LIST_START = (1 << 6),
+};
/* Fallback panel category (only for old scripts which need updating) */
#define PNL_CATEGORY_FALLBACK "Misc"
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c
index f76aac7e967..b798681b51e 100644
--- a/source/blender/modifiers/intern/MOD_ui_common.c
+++ b/source/blender/modifiers/intern/MOD_ui_common.c
@@ -230,7 +230,7 @@ static int modifier_is_simulation(ModifierData *md)
static void modifier_panel_header(const bContext *C, Panel *panel)
{
- uiLayout *row;
+ uiLayout *row, *sub;
uiLayout *layout = panel->layout;
PointerRNA ptr;
@@ -239,6 +239,8 @@ static void modifier_panel_header(const bContext *C, Panel *panel)
ModifierData *md = ptr.data;
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+ int index = panel->runtime.list_index;
/* Modifier Icon. */
row = uiLayoutRow(layout, false);
@@ -249,21 +251,6 @@ static void modifier_panel_header(const bContext *C, Panel *panel)
/* Modifier Name. */
uiItemR(layout, &ptr, "name", 0, "", ICON_NONE);
-}
-
-static void modifier_panel_header_modes(const bContext *C, Panel *panel)
-{
- uiLayout *sub, *row;
- uiLayout *layout = panel->layout;
-
- PointerRNA ptr;
- modifier_panel_get_property_pointers(C, panel, NULL, &ptr);
-
- ModifierData *md = ptr.data;
- const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
- int index = panel->runtime.list_index;
- Object *ob = CTX_data_active_object(C);
- Scene *scene = CTX_data_scene(C);
/* Switch context buttons. */
if (modifier_is_simulation(md) == 1) {
@@ -309,6 +296,9 @@ static void modifier_panel_header_modes(const bContext *C, Panel *panel)
row = uiLayoutRow(layout, false);
uiLayoutSetEmboss(row, UI_EMBOSS_NONE);
uiItemO(row, "", ICON_X, "OBJECT_OT_modifier_remove");
+
+ /* Some extra padding at the end, so 'x' icon isn't too close to drag button. */
+ uiItemS(layout);
}
/** \} */
@@ -336,13 +326,12 @@ PanelType *modifier_panel_register(ARegionType *region_type, const char *name, P
strcpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
panel_type->draw_header = modifier_panel_header;
- panel_type->draw_header_preset = modifier_panel_header_modes;
panel_type->draw = draw;
panel_type->poll = modifier_ui_poll;
/* Give the panel the special flag that says it was built here and corresponds to a
* modifer rather than a PanelType. */
- panel_type->flag = PNL_LIST;
+ panel_type->flag = PNL_LAYOUT_HEADER_EXTEND | PNL_LIST;
panel_type->reorder = modifier_reorder;
panel_type->get_list_data_expand_flag = get_modifier_expand_flag;
panel_type->set_list_data_expand_flag = set_modifier_expand_flag;
More information about the Bf-blender-cvs
mailing list