Page MenuHome
Paste P768

Patch with different alignment options for the 2.8 single-column layout
ActivePublic

Authored by Inês Almeida (brita_) on Aug 16 2018, 1:01 AM.
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index f7507223f31..753357614e2 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -774,6 +774,7 @@ extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *s
void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep);
void ui_draw_preview_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
+#define UI_PROP_ERRADICATE_COLONS
#define UI_TEXT_MARGIN_X 0.4f
#define UI_POPUP_MARGIN (UI_DPI_FAC * 12)
/* margin at top of screen for popups */
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index f3f08b10257..823dee27d30 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -64,12 +64,32 @@
#include "interface_intern.h"
+
+/* Suggestions:
+always: UI_PROP_DECORATE ON, UI_PROP_SEP_ICON_WIDTH_EXCEPTION OFF
+1: UI_PROP_TEXT_LEFT + UI_PROP_ARRAY_SUBLABELS_EMBEDDED
+2: UI_PROP_DECORATE_LEFT + UI_PROP_ARRAY_SUBLABELS_EMBEDDED
+3: 1 + UI_PROP_ARRAY_LABELS_ON_TOP
+ */
+
+
/* Show an icon button after each RNA button to use to quickly set keyframes,
* this is a way to display animation/driven/override status, see T54951. */
#define UI_PROP_DECORATE
+//#define UI_PROP_DECORATE_LEFT
+
/* Alternate draw mode where some buttons can use single icon width,
* giving more room for the text at the expense of nicely aligned text. */
-#define UI_PROP_SEP_ICON_WIDTH_EXCEPTION
+//#define UI_PROP_SEP_ICON_WIDTH_EXCEPTION
+
+/* Align the properties' name left-to-right */
+#define UI_PROP_ALIGN_LEFT_TO_RIGHT
+
+/* If the text should be on the left and the value on the right or the other way */
+#define UI_PROP_TEXT_LEFT
+
+//#define UI_PROP_ARRAY_LABELS_ON_TOP /* don't turn this on without the embedded labels */
+#define UI_PROP_ARRAY_SUBLABELS_EMBEDDED
/************************ Structs and Defines *************************/
@@ -1604,6 +1624,7 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
icon_only = (flag & UI_ITEM_R_ICON_ONLY) != 0;
no_bg = (flag & UI_ITEM_R_NO_BG) != 0;
compact = (flag & UI_ITEM_R_COMPACT) != 0;
+ bool checkbox = (type == PROP_BOOLEAN && (icon == ICON_NONE) && !icon_only);
/* get size */
ui_item_rna_size(layout, name, icon, ptr, prop, index, icon_only, compact, &w, &h);
@@ -1616,41 +1637,72 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
/* Split the label / property. */
if (use_prop_sep) {
uiLayout *layout_row = NULL;
-#ifdef UI_PROP_DECORATE
+
+ #ifdef UI_PROP_DECORATE
if (ui_decorate.use_prop_decorate) {
layout_row = uiLayoutRow(layout, true);
layout_row->space = 0;
ui_decorate.len = max_ii(1, len);
+
+ uiLayout *col_left = uiLayoutColumn(layout_row, true);
+ uiLayout *col_right = uiLayoutColumn(layout_row, true);
+ #ifdef UI_PROP_DECORATE_LEFT
+ ui_decorate.layout = col_left;
+ ui_decorate.but = block->buttons.last;
+ layout_row = col_right;
+ #else
+ ui_decorate.layout = col_right;
+ ui_decorate.but = block->buttons.last;
+ layout_row = col_left;
+ #endif
}
-#endif /* UI_PROP_DECORATE */
+ #endif /* UI_PROP_DECORATE */
+
+ uiLayout *layout_split = NULL;
+ uiLayout *layout_sub_left = NULL;
+ uiLayout *layout_sub_right = NULL;
+ #ifdef UI_PROP_ARRAY_LABELS_ON_TOP
+ if (checkbox)
+ layout_row = uiLayoutRow(layout_row ? layout_row : layout, true);
+ else
+ layout_row = uiLayoutColumn(layout_row ? layout_row : layout, true);
+ #else
+ layout_split = uiLayoutSplit(
+ layout_row ? layout_row : layout,
+ UI_ITEM_PROP_SEP_DIVIDE, true);
+ layout_sub_left = uiLayoutColumn(layout_split, true);
+ layout_sub_right = uiLayoutColumn(layout_split, true);
+
+ /* Set the layout for the name */
+ #ifdef UI_PROP_TEXT_LEFT
+ UI_block_layout_set_current(block, layout_sub_left);
+ #else
+ UI_block_layout_set_current(block, layout_sub_right);
+ #endif
+ #endif
+
if (name[0] == '\0') {
/* Ensure we get a column when text is not set. */
- layout = uiLayoutColumn(layout_row ? layout_row : layout, true);
- layout->space = 0;
+ //layout = uiLayoutColumn(layout_row ? layout_row : layout, true);
+ //layout->space = 0;
}
else {
const PropertySubType subtype = RNA_property_subtype(prop);
- uiLayout *layout_split;
-#ifdef UI_PROP_SEP_ICON_WIDTH_EXCEPTION
- if (type == PROP_BOOLEAN && (icon == ICON_NONE) && !icon_only) {
+
+ #ifdef UI_PROP_SEP_ICON_WIDTH_EXCEPTION
+ if (checkbox) {
w = UI_UNIT_X;
layout_split = uiLayoutRow(layout_row ? layout_row : layout, true);
}
- else
-#endif /* UI_PROP_SEP_ICON_WIDTH_EXCEPTION */
- {
- layout_split = uiLayoutSplit(
- layout_row ? layout_row : layout,
- UI_ITEM_PROP_SEP_DIVIDE, true);
- }
- layout_split->space = 0;
- uiLayout *layout_sub = uiLayoutColumn(layout_split, true);
- layout_sub->space = 0;
+ #endif /* UI_PROP_SEP_ICON_WIDTH_EXCEPTION */
+
+ const char* label_str = NULL;
if ((index == RNA_NO_INDEX && is_array) &&
- ((!expand && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA, PROP_DIRECTION)) == 0))
+ ((!expand && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA, PROP_DIRECTION)) == 0))
{
+ #ifndef UI_PROP_ARRAY_SUBLABELS_EMBEDDED
char name_with_suffix[UI_MAX_DRAW_STR + 2];
char str[2] = {'\0'};
for (int a = 0; a < len; a++) {
@@ -1658,55 +1710,113 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
const bool use_prefix = (a == 0 && name && name[0]);
if (use_prefix) {
char *s = name_with_suffix;
- s += STRNCPY_RLEN(name_with_suffix, name);
- *s++ = ' ';
- *s++ = str[0];
- *s++ = '\0';
+ #if defined(UI_PROP_ALIGN_LEFT_TO_RIGHT) && defined(UI_PROP_TEXT_LEFT)
+ *s++ = str[0];
+ *s++ = ' ';
+ BLI_strncpy_rlen(s, name, ARRAY_SIZE(name_with_suffix));
+ #else
+ s += STRNCPY_RLEN(name_with_suffix, name);
+ *s++ = ' ';
+ *s++ = str[0];
+ *s++ = '\0';
+ #endif
}
- but = uiDefBut(
- block, UI_BTYPE_LABEL, 0, use_prefix ? name_with_suffix : str,
- 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
- but->drawflag |= UI_BUT_TEXT_RIGHT;
- but->drawflag &= ~UI_BUT_TEXT_LEFT;
+ label_str = use_prefix ? name_with_suffix : str;
}
+ # else
+ label_str = name;
+ #endif
}
else {
- if (name) {
- but = uiDefBut(
- block, UI_BTYPE_LABEL, 0, name,
- 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
+ label_str = name;
+
+ #ifdef UI_PROP_ARRAY_SUBLABELS_EMBEDDED
+ /* Hacky hack to test how "subproperties" that are technically separate props
+ would look is thy were an array. eg. clip_start and clip_end, resolution_x, etc. */
+ /* Assume it's a subprop based on alignment of layout (specified in python) */
+ if (layout->align && !is_array && (type == PROP_FLOAT || type == PROP_INT)/*type != PROP_ENUM && !checkbox*/) {
+ /* */
+ char* last_word = strrchr(name, ' ');
+ if (last_word) {
+ char name_without_last_word[sizeof(name)];
+ size_t label_str_size = strlen(name)-strlen(last_word)+1;
+ BLI_strncpy(name_without_last_word, name, label_str_size);
+ label_str = name_without_last_word;
+ } else {
+ /* single word - don't print a label, it goes embedded */
+ label_str = "";
+ }
+
+ /* @Pablo - uncomment to see all props that are in an aligned layout */
+ //char temp[5] = "!sub\0";
+ //label_str = temp;
+ }
+ #endif
+ }
+
+ if (label_str && label_str[0] != '\0')
+ {
+ but = uiDefBut(
+ block, UI_BTYPE_LABEL, 0, label_str,
+ 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
+ #ifdef UI_PROP_ALIGN_LEFT_TO_RIGHT
+ but->drawflag |= UI_BUT_TEXT_LEFT;
+ but->drawflag &= ~UI_BUT_TEXT_RIGHT;
+ #else
but->drawflag |= UI_BUT_TEXT_RIGHT;
but->drawflag &= ~UI_BUT_TEXT_LEFT;
- }
+ #endif
}
- /* Watch out! We can only write into the new column now. */
- layout = uiLayoutColumn(layout_split, true);
- layout->space = 0;
if ((type == PROP_ENUM) && (flag & UI_ITEM_R_EXPAND)) {
/* pass (expanded enums each have their own name) */
}
else {
- name = "";
+ #ifdef UI_PROP_ARRAY_SUBLABELS_EMBEDDED
+ /* Hacky hack continuation */
+ if (layout->align && !is_array && (type == PROP_FLOAT || type == PROP_INT)) {
+ char* last_word = strrchr(name, ' ');
+ if (last_word) {
+ name = ++last_word;
+ }
+ if (name)
+ name = ui_item_name_add_colon(name, namestr);
+ } else {
+ name = (is_array || (type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER))? "" : " ";
+ }
+ #else
+ name = " ";
+ #endif
}
}
-#ifdef UI_PROP_DECORATE
- if (ui_decorate.use_prop_decorate) {
- ui_decorate.layout = uiLayoutColumn(layout_row, true);
- ui_decorate.layout->space = 0;
- UI_block_layout_set_current(block, layout);
- ui_decorate.but = block->buttons.last;
- }
-#endif /* UI_PROP_DECORATE */
+ /* Set the layout for the value */
+ #ifdef UI_PROP_ARRAY_LABELS_ON_TOP
+ if (checkbox)
+ layout = uiLayoutColumn(layout_row, true);
+ else
+ layout = layout_row;
+ #else
+ #ifdef UI_PROP_TEXT_LEFT
+ layout = layout_sub_right;
+ #else
+ layout = layout_sub_left;
+ #endif
+ #endif
+
+ UI_block_layout_set_current(block, layout);
}
/* End split. */
/* array property */
if (index == RNA_NO_INDEX && is_array) {
+ bool show_text = !use_prop_sep;
+ #ifdef UI_PROP_ARRAY_SUBLABELS_EMBEDDED
+ show_text = true;
+ #endif
ui_item_array(
layout, block, name, icon, ptr, prop, len, 0, 0, w, h,
- expand, slider, toggle, icon_only, compact, !use_prop_sep);
+ expand, slider, toggle, icon_only, compact, show_text);
}
/* enum item */
else if (type == PROP_ENUM && index == RNA_ENUM_VALUE) {
@@ -1749,7 +1859,7 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
}
#ifdef UI_PROP_DECORATE
- if (ui_decorate.use_prop_decorate) {
+ if (ui_decorate.use_prop_decorate && ui_decorate.layout) {
const bool is_anim = RNA_property_animateable(ptr, prop);
uiBut *but_decorate = ui_decorate.but ? ui_decorate.but->next : block->buttons.first;
uiLayout *layout_col = uiLayoutColumn(ui_decorate.layout, false);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 2296c3bc39d..380c51ac3f6 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1930,7 +1930,12 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
drawstr_right = strchr(drawstr + but->ofs, ':');
if (drawstr_right) {
drawstr_right++;
+ #ifdef UI_PROP_ERRADICATE_COLONS
+ drawstr_left_len = (drawstr_right-1 - drawstr);
+ #else
drawstr_left_len = (drawstr_right - drawstr);
+ #endif
+
while (*drawstr_right == ' ') {
drawstr_right++;
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 38fac7cb37d..54a2f564b09 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -925,7 +925,9 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *split, *colsub;
- split = uiLayoutSplit(layout, 0.8f, false);
+ uiLayoutSetPropSep(layout, true);
+
+ split = layout;//uiLayoutSplit(layout, 0.8f, false);
if (ptr->type == &RNA_PoseBone) {
PointerRNA boneptr;
@@ -937,51 +939,52 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
}
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "location", 0, NULL, ICON_NONE);
- colsub = uiLayoutColumn(split, true);
+ /*colsub = uiLayoutColumn(split, true);
uiItemL(colsub, "", ICON_NONE);
- uiItemR(colsub, ptr, "lock_location", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ uiItemR(colsub, ptr, "lock_location", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY | UI_ITEM_R_NO_BG, "", ICON_NONE);*/
- split = uiLayoutSplit(layout, 0.8f, false);
+ //split = uiLayoutSplit(layout, 0.8f, false);
+ split = uiLayoutColumn(layout, true);
switch (RNA_enum_get(ptr, "rotation_mode")) {
case ROT_MODE_QUAT: /* quaternion */
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "rotation_quaternion", 0, IFACE_("Rotation"), ICON_NONE);
- colsub = uiLayoutColumn(split, true);
+ /*colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, IFACE_("4L"), ICON_NONE);
if (RNA_boolean_get(ptr, "lock_rotations_4d"))
uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE + UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
else
uiItemL(colsub, "", ICON_NONE);
- uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);*/
break;
case ROT_MODE_AXISANGLE: /* axis angle */
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "rotation_axis_angle", 0, IFACE_("Rotation"), ICON_NONE);
- colsub = uiLayoutColumn(split, true);
+ /*colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, IFACE_("4L"), ICON_NONE);
if (RNA_boolean_get(ptr, "lock_rotations_4d"))
uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
else
uiItemL(colsub, "", ICON_NONE);
- uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);*/
break;
default: /* euler rotations */
colsub = uiLayoutColumn(split, true);
uiItemR(colsub, ptr, "rotation_euler", 0, IFACE_("Rotation"), ICON_NONE);
- colsub = uiLayoutColumn(split, true);
+ /*colsub = uiLayoutColumn(split, true);
uiItemL(colsub, "", ICON_NONE);
- uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);*/
break;
}
uiItemR(layout, ptr, "rotation_mode", 0, "", ICON_NONE);
- split = uiLayoutSplit(layout, 0.8f, false);
- colsub = uiLayoutColumn(split, true);
+ //split = uiLayoutSplit(layout, 0.8f, false);
+ colsub = uiLayoutColumn(layout, true);
uiItemR(colsub, ptr, "scale", 0, NULL, ICON_NONE);
- colsub = uiLayoutColumn(split, true);
+ /*colsub = uiLayoutColumn(split, true);
uiItemL(colsub, "", ICON_NONE);
- uiItemR(colsub, ptr, "lock_scale", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ uiItemR(colsub, ptr, "lock_scale", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY | UI_ITEM_R_NO_BG, "", ICON_NONE);*/
if (ptr->type == &RNA_Object) {
Object *ob = ptr->data;

Event Timeline

Inês Almeida (brita_) updated the paste's language from autodetect to c.
Inês Almeida (brita_) updated the paste's language from c to diff.