[Bf-committers] [Bf-blender-cvs] [f842ce8] master: UI List: ctrl click on names in list can be used for renaming.

Bastien Montagne montagne29 at wanadoo.fr
Sat Nov 23 18:53:54 CET 2013


Eeeek… Didn’t thought arc land would even push the changes onto 
origin/master! Next time will land it myself with git commands… :/

So, additional info: Most uiList classes still need to be updated (I 
intended to do this in a separated commit). For now, only VGroup and 
those using default UI_UL_List class have this feature.

PY API: To enable this feature for your uiList classes, you have to 
either not define any draw_item function (hence using default C one), or 
to use `layout.prop(item, "name_of_prop_to_rename", text="", 
emboss=False, icon_value=icon)` instead of 
`layout.label(item.name_of_prop_to_rename, icon_vaue=icon)`...

Code notes: This commit mostly make non-embossed text fields behave as a 
label, as long as ctrl is not pressed. This is true for any text field, 
not only those inside an uiList.

And a big thanks to Brecht for all the reviews and advices, we indeed 
got to a much better solution than the initial one! :)

On 23/11/2013 18:42, Bastien Montagne wrote:
> Commit: f842ce82e6c92b156c0036cbefb4e4d97cd1d498
> Author: Bastien Montagne
> Date:   Sat Nov 23 18:43:23 2013 +0100
> http://developer.blender.org/rBf842ce82e6c92b156c0036cbefb4e4d97cd1d498
>
> UI List: ctrl click on names in list can be used for renaming.
>
> Summary:
> More information here:
> http://lists.blender.org/pipermail/bf-committers/2013-November/042113.html
>
> Reviewers: brecht
>
> Reviewed By: brecht
>
> CC: mont29
>
> Differential Revision: http://developer.blender.org/D8
>
> ===================================================================
>
> M	release/scripts/startup/bl_ui/properties_data_mesh.py
> M	source/blender/editors/include/UI_interface.h
> M	source/blender/editors/interface/interface_handlers.c
> M	source/blender/editors/interface/interface_intern.h
> M	source/blender/editors/interface/interface_layout.c
> M	source/blender/editors/interface/interface_templates.c
> M	source/blender/editors/interface/interface_widgets.c
> M	source/blender/makesrna/intern/rna_ui_api.c
> M	source/blenderplayer/bad_level_call_stubs/stubs.c
>
> ===================================================================
>
> diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
> index f59d479..0ec2232 100644
> --- a/release/scripts/startup/bl_ui/properties_data_mesh.py
> +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
> @@ -64,7 +64,7 @@ class MESH_UL_vgroups(UIList):
>           # assert(isinstance(item, bpy.types.VertexGroup)
>           vgroup = item
>           if self.layout_type in {'DEFAULT', 'COMPACT'}:
> -            layout.label(text=vgroup.name, translate=False, icon_value=icon)
> +            layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
>               icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
>               layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
>           elif self.layout_type in {'GRID'}:
> diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
> index 0c37d35..0786f26 100644
> --- a/source/blender/editors/include/UI_interface.h
> +++ b/source/blender/editors/include/UI_interface.h
> @@ -432,7 +432,6 @@ void    uiButSetDragValue(uiBut *but);
>   void    uiButSetDragImage(uiBut *but, const char *path, int icon, struct ImBuf *ima, float scale);
>   
>   int     UI_but_active_drop_name(struct bContext *C);
> -struct uiBut  *ui_but_find_mouse_over(struct ARegion *ar, int x, int y);
>   
>   void    uiButSetFlag(uiBut *but, int flag);
>   void    uiButClearFlag(uiBut *but, int flag);
> diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
> index db53809..c871fdc 100644
> --- a/source/blender/editors/interface/interface_handlers.c
> +++ b/source/blender/editors/interface/interface_handlers.c
> @@ -235,8 +235,10 @@ typedef struct uiAfterFunc {
>   
>   
>   
> +static bool ui_is_but_interactive(uiBut *but, const bool ctrl);
>   static bool ui_but_contains_pt(uiBut *but, int mx, int my);
>   static bool ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y);
> +static uiBut *ui_but_find_mouse_over(ARegion *ar, const wmEvent *event, int x, int y);
>   static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state);
>   static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *userdata);
>   static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type);
> @@ -728,7 +730,9 @@ static bool ui_drag_toggle_set_xy_xy(bContext *C, ARegion *ar, const bool is_set
>   		ui_window_to_block_fl(ar, block, &xy_b_block[0], &xy_b_block[1]);
>   
>   		for (but = block->buttons.first; but; but = but->next) {
> -			if (ui_is_but_interactive(but)) {
> +			/* Note: ctrl is always true here because (at least for now) we always want to consider text control
> +			 *       in this case, even when not embossed. */
> +			if (ui_is_but_interactive(but, true)) {
>   				if (BLI_rctf_isect_segment(&but->rect, xy_a_block, xy_b_block)) {
>   
>   					/* execute the button */
> @@ -754,7 +758,7 @@ static bool ui_drag_toggle_set_xy_xy(bContext *C, ARegion *ar, const bool is_set
>   	return change;
>   }
>   
> -static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const int xy_input[2])
> +static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const wmEvent *event)
>   {
>   	ARegion *ar = CTX_wm_region(C);
>   	bool do_draw = false;
> @@ -768,7 +772,7 @@ static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const
>   	 */
>   	if (drag_info->is_init == false) {
>   		/* first store the buttons original coords */
> -		uiBut *but = ui_but_find_mouse_over(ar, xy_input[0], xy_input[1]);
> +		uiBut *but = ui_but_find_mouse_over(ar, event, 0, 0);
>   
>   		if (but) {
>   			if (but->flag & UI_BUT_DRAG_LOCK) {
> @@ -796,8 +800,8 @@ static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const
>   	/* done with axis locking */
>   
>   
> -	xy[0] = (drag_info->xy_lock[0] == false) ? xy_input[0] : drag_info->xy_last[0];
> -	xy[1] = (drag_info->xy_lock[1] == false) ? xy_input[1] : drag_info->xy_last[1];
> +	xy[0] = (drag_info->xy_lock[0] == false) ? event->x : drag_info->xy_last[0];
> +	xy[1] = (drag_info->xy_lock[1] == false) ? event->y : drag_info->xy_last[1];
>   
>   
>   	/* touch all buttons between last mouse coord and this one */
> @@ -831,7 +835,7 @@ static int ui_handler_region_drag_toggle(bContext *C, const wmEvent *event, void
>   		}
>   		case MOUSEMOVE:
>   		{
> -			ui_drag_toggle_set(C, drag_info, &event->x);
> +			ui_drag_toggle_set(C, drag_info, event);
>   			break;
>   		}
>   	}
> @@ -839,7 +843,7 @@ static int ui_handler_region_drag_toggle(bContext *C, const wmEvent *event, void
>   	if (done) {
>   		wmWindow *win = CTX_wm_window(C);
>   		ARegion *ar = CTX_wm_region(C);
> -		uiBut *but = ui_but_find_mouse_over(ar, drag_info->xy_init[0], drag_info->xy_init[1]);
> +		uiBut *but = ui_but_find_mouse_over(ar, NULL, drag_info->xy_init[0], drag_info->xy_init[1]);
>   
>   		if (but) {
>   			ui_apply_undo(but);
> @@ -5883,8 +5887,9 @@ static bool ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y)
>   
>   /**
>    * Can we mouse over the button or is it hidden/disabled/layout.
> + * Note: ctrl is kind of a hack currently, so that non-embossed TEX button behaves as a label when ctrl is not pressed.
>    */
> -bool ui_is_but_interactive(uiBut *but)
> +static bool ui_is_but_interactive(uiBut *but, const bool ctrl)
>   {
>   	/* note, LABEL is included for highlights, this allows drags */
>   	if ((but->type == LABEL) && but->dragpoin == NULL)
> @@ -5895,6 +5900,8 @@ bool ui_is_but_interactive(uiBut *but)
>   		return false;
>   	if (but->flag & UI_SCROLLED)
>   		return false;
> +	if ((but->type == TEX) && (but->dt & UI_EMBOSSN) && !ctrl)
> +		return false;
>   
>   	return true;
>   }
> @@ -5906,11 +5913,19 @@ bool ui_is_but_search_unlink_visible(uiBut *but)
>   	        (but->drawstr[0] != '\0'));
>   }
>   
> -uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
> +/* x and y are only used in case event is NULL... */
> +static uiBut *ui_but_find_mouse_over(ARegion *ar, const wmEvent *event, int x, int y)
>   {
>   	uiBlock *block;
>   	uiBut *but, *butover = NULL;
>   	int mx, my;
> +	bool ctrl = true;
> +
> +	if (event) {
> +		x = event->x;
> +		y = event->y;
> +		ctrl = event->ctrl;
> +	}
>   
>   //	if (!win->active)
>   //		return NULL;
> @@ -5923,7 +5938,7 @@ uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
>   		ui_window_to_block(ar, block, &mx, &my);
>   
>   		for (but = block->buttons.first; but; but = but->next) {
> -			if (ui_is_but_interactive(but)) {
> +			if (ui_is_but_interactive(but, ctrl)) {
>   				if (ui_but_contains_pt(but, mx, my)) {
>   					butover = but;
>   				}
> @@ -6493,7 +6508,7 @@ static int ui_handle_button_over(bContext *C, const wmEvent *event, ARegion *ar)
>   	uiBut *but;
>   
>   	if (event->type == MOUSEMOVE) {
> -		but = ui_but_find_mouse_over(ar, event->x, event->y);
> +		but = ui_but_find_mouse_over(ar, event, 0, 0);
>   		if (but) {
>   			button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER);
>   		}
> @@ -6585,7 +6600,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
>   					data->cancel = TRUE;
>   					button_activate_state(C, but, BUTTON_STATE_EXIT);
>   				}
> -				else if (ui_but_find_mouse_over(ar, event->x, event->y) != but) {
> +				else if (ui_but_find_mouse_over(ar, event, 0, 0) != but) {
>   					data->cancel = TRUE;
>   					button_activate_state(C, but, BUTTON_STATE_EXIT);
>   				}
> @@ -6697,7 +6712,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
>   					}
>   				}
>   
> -				bt = ui_but_find_mouse_over(ar, event->x, event->y);
> +				bt = ui_but_find_mouse_over(ar, event, 0, 0);
>   				
>   				if (bt && bt->active != data) {
>   					if (but->type != COLOR) {  /* exception */
> @@ -6737,7 +6752,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
>   			 * it stays active while the mouse is over it.
>   			 * This avoids adding mousemoves, see: [#33466] */
>   			if (ELEM(state_orig, BUTTON_STATE_INIT, BUTTON_STATE_HIGHLIGHT)) {
> -				if (ui_but_find_mouse_over(ar, event->x, event->y) == but) {
> +				if (ui_but_find_mouse_over(ar, event, 0, 0) == but) {
>   					button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER);
>   				}
>   			}
> @@ -6778,7 +6793,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *ar)
>   			break;
>   		}
>   	}
> -	if (dragbut && dragbut == ui_but_find_mouse_over(ar, event->x, event->y)) {
> +	if (dragbut && dragbut == ui_but_find_mouse_over(ar, event, 0, 0)) {
>   		is_over_dragbut = true;
>   	}
>   
> diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
> index 30d8535..9287385 100644
> --- a/source/blender/editors/interface/interface_intern.h
> +++ b/source/blender/editors/interface/interface_intern.h
> @@ -54,6 +54,9 @@ struct ImBuf;
>   
>   /* ****************** general defines ************** */
>   
> +#define RNA_NO_INDEX    -1
> +#define RNA_ENUM_VALUE  -2
> +
>   /* visual types for drawing */
>   /* for time being separated from functional types */
>   typedef enum {
> @@ -403,7 +406,6 @@ extern bool ui_is_but_bool(uiBut *but);
>   extern bool ui_is_but_unit(uiBut *but);
>   extern bool ui_is_but_rna_valid(uiBut *but);
>   extern bool ui_is_but_utf8(uiBut *but);
> -extern bool ui_is_but_interactive(uiBut *but);
>   extern bool ui_is_but_search_unlink_visible(uiBut *but);
>   
>   extern int  ui_is_but_push_ex(uiBut *but, double *value);
> diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
> index b85c30b..346a54c 100644
> --- a/source/blender/editors/interface/interface_layout.c
> +++ b/source/blender/editors/interface/interface_layout.c
> @@ -64,10 +64,6 @@
>   
>   /************************ Structs and Defines *************************/
>   
> -#define RNA_NO_INDEX    -1
> -#define RNA_ENUM_VALUE  -2
> -
> -
>   // #define USE_OP_RESET_BUT  // we may want to make this optional, disable for now.
>   
>   #define UI_OPERATOR_ERROR_RET(_ot, _opname, return_statement)                 \
> @@ -632,13 +628,11 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n
>   
>   	if (subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) {
>   		uiBlockSetCurLayout(block, uiLayoutRow(sub, TRUE));
> -		uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w - UI_UNIT_X, h);
> +		but = uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w - UI_UNIT_X, h);
>   
>   		/* BUTTONS_OT_file_browse calls uiFileBrowseContextProperty */
> -		but = u
>
> @@ Diff output truncated at 10240 characters. @@
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>



More information about the Bf-committers mailing list