Add fixed width/height parameter for layouts

New parameters to define a fixed size for a layout. This allows to avoid UI changes when the text length changes.

This commit implements D3725
This commit is contained in:
2018-09-25 20:59:04 +02:00
parent 0f7e858f06
commit f4f99d1d75
3 changed files with 61 additions and 0 deletions

View File

@@ -991,6 +991,8 @@ void uiLayoutSetAlignment(uiLayout *layout, char alignment);
void uiLayoutSetKeepAspect(uiLayout *layout, bool keepaspect);
void uiLayoutSetScaleX(uiLayout *layout, float scale);
void uiLayoutSetScaleY(uiLayout *layout, float scale);
void uiLayoutSetUnitsX(uiLayout *layout, int unit);
void uiLayoutSetUnitsY(uiLayout *layout, int unit);
void uiLayoutSetEmboss(uiLayout *layout, char emboss);
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep);
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep);
@@ -1004,6 +1006,8 @@ bool uiLayoutGetKeepAspect(uiLayout *layout);
int uiLayoutGetWidth(uiLayout *layout);
float uiLayoutGetScaleX(uiLayout *layout);
float uiLayoutGetScaleY(uiLayout *layout);
int uiLayoutGetUnitsX(uiLayout *layout);
int uiLayoutGetUnitsY(uiLayout *layout);
int uiLayoutGetEmboss(uiLayout *layout);
bool uiLayoutGetPropSep(uiLayout *layout);
bool uiLayoutGetPropDecorate(uiLayout *layout);

View File

@@ -169,6 +169,7 @@ struct uiLayout {
bool variable_size; /* For layouts inside gridflow, they and their items shall never have a fixed maximal size. */
char alignment;
char emboss;
int units[2]; /* for fixed width or height to avoid UI size changes */
};
typedef struct uiLayoutItemFlow {
@@ -3856,6 +3857,16 @@ void uiLayoutSetScaleY(uiLayout *layout, float scale)
layout->scale[1] = scale;
}
void uiLayoutSetUnitsX(uiLayout *layout, int unit)
{
layout->units[0] = unit;
}
void uiLayoutSetUnitsY(uiLayout *layout, int unit)
{
layout->units[1] = unit;
}
void uiLayoutSetEmboss(uiLayout *layout, char emboss)
{
layout->emboss = emboss;
@@ -3921,6 +3932,16 @@ float uiLayoutGetScaleY(uiLayout *layout)
return layout->scale[1];
}
int uiLayoutGetUnitsX(uiLayout *layout)
{
return layout->units[0];
}
int uiLayoutGetUnitsY(uiLayout *layout)
{
return layout->units[1];
}
int uiLayoutGetEmboss(uiLayout *layout)
{
if (layout->emboss == UI_EMBOSS_UNDEFINED) {
@@ -4011,6 +4032,14 @@ static void ui_item_estimate(uiItem *item)
default:
break;
}
/* force fixed size */
if (litem->units[0] > 0) {
litem->w = UI_UNIT_X * litem->units[0];
}
if (litem->units[1] > 0) {
litem->h = UI_UNIT_Y * litem->units[1];
}
}
}

View File

@@ -947,6 +947,26 @@ static void rna_UILayout_scale_y_set(PointerRNA *ptr, float value)
uiLayoutSetScaleY(ptr->data, value);
}
static int rna_UILayout_units_x_get(PointerRNA *ptr)
{
return uiLayoutGetUnitsX(ptr->data);
}
static void rna_UILayout_units_x_set(PointerRNA *ptr, int value)
{
uiLayoutSetUnitsX(ptr->data, value);
}
static int rna_UILayout_units_y_get(PointerRNA *ptr)
{
return uiLayoutGetUnitsY(ptr->data);
}
static void rna_UILayout_units_y_set(PointerRNA *ptr, int value)
{
uiLayoutSetUnitsY(ptr->data, value);
}
static int rna_UILayout_emboss_get(PointerRNA *ptr)
{
return uiLayoutGetEmboss(ptr->data);
@@ -1036,6 +1056,14 @@ static void rna_def_ui_layout(BlenderRNA *brna)
prop = RNA_def_property(srna, "scale_y", PROP_FLOAT, PROP_UNSIGNED);
RNA_def_property_float_funcs(prop, "rna_UILayout_scale_y_get", "rna_UILayout_scale_y_set", NULL);
RNA_def_property_ui_text(prop, "Scale Y", "Scale factor along the Y for items in this (sub)layout");
prop = RNA_def_property(srna, "ui_units_x", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_funcs(prop, "rna_UILayout_units_x_get", "rna_UILayout_units_x_set", NULL);
RNA_def_property_ui_text(prop, "Units X", "Fixed Size along the X for items in this (sub)layout");
prop = RNA_def_property(srna, "ui_units_y", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_funcs(prop, "rna_UILayout_units_y_get", "rna_UILayout_units_y_set", NULL);
RNA_def_property_ui_text(prop, "Units Y", "Fixed Size along the Y for items in this (sub)layout");
RNA_api_ui_layout(srna);
prop = RNA_def_property(srna, "emboss", PROP_ENUM, PROP_NONE);