UI: support cycling callback for non RNA menus
This commit is contained in:
		@@ -361,6 +361,13 @@ typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
 | 
			
		||||
 | 
			
		||||
typedef void (*uiMenuCreateFunc)(struct bContext *C, struct uiLayout *layout, void *arg1);
 | 
			
		||||
typedef void (*uiMenuHandleFunc)(struct bContext *C, void *arg, int event);
 | 
			
		||||
/**
 | 
			
		||||
 * Used for cycling menu values without opening the menu (Ctrl-Wheel).
 | 
			
		||||
 * \param direction: forward or backwards [1 / -1].
 | 
			
		||||
 * \param arg1: uiBut.poin (as with #uiMenuCreateFunc).
 | 
			
		||||
 * \return true when the button was changed.
 | 
			
		||||
 */
 | 
			
		||||
typedef bool (*uiMenuStepFunc)(struct bContext *C, int direction, void *arg1);
 | 
			
		||||
 | 
			
		||||
/* Popup Menus
 | 
			
		||||
 *
 | 
			
		||||
@@ -693,6 +700,8 @@ void    UI_but_func_drawextra_set(
 | 
			
		||||
        void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect),
 | 
			
		||||
        void *arg1, void *arg2);
 | 
			
		||||
 | 
			
		||||
void    UI_but_func_menu_step_set(uiBut *but, uiMenuStepFunc func);
 | 
			
		||||
 | 
			
		||||
void    UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *argN);
 | 
			
		||||
void    UI_but_tooltip_timer_remove(struct bContext *C, uiBut *but);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1804,7 +1804,8 @@ bool ui_but_supports_cycling(const uiBut *but)
 | 
			
		||||
{
 | 
			
		||||
	return ((ELEM(but->type, UI_BTYPE_ROW, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_LISTBOX)) ||
 | 
			
		||||
	        (but->type == UI_BTYPE_MENU && ui_but_menu_step_poll(but)) ||
 | 
			
		||||
	        (but->type == UI_BTYPE_COLOR && but->a1 != -1));
 | 
			
		||||
	        (but->type == UI_BTYPE_COLOR && but->a1 != -1) ||
 | 
			
		||||
	        (but->menu_step_func != NULL));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double ui_but_value_get(uiBut *but)
 | 
			
		||||
@@ -4130,6 +4131,11 @@ void UI_but_func_complete_set(uiBut *but, uiButCompleteFunc func, void *arg)
 | 
			
		||||
	but->autofunc_arg = arg;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UI_but_func_menu_step_set(uiBut *but, uiMenuStepFunc func)
 | 
			
		||||
{
 | 
			
		||||
	but->menu_step_func = func;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *argN)
 | 
			
		||||
{
 | 
			
		||||
	but->tip_func = func;
 | 
			
		||||
 
 | 
			
		||||
@@ -281,6 +281,8 @@ struct uiBut {
 | 
			
		||||
	/* UI_BTYPE_PULLDOWN/UI_BTYPE_MENU data */
 | 
			
		||||
	uiMenuCreateFunc menu_create_func;
 | 
			
		||||
 | 
			
		||||
	uiMenuStepFunc menu_step_func;
 | 
			
		||||
 | 
			
		||||
	/* RNA data */
 | 
			
		||||
	struct PointerRNA rnapoin;
 | 
			
		||||
	struct PropertyRNA *rnaprop;
 | 
			
		||||
 
 | 
			
		||||
@@ -111,13 +111,19 @@ bool ui_but_menu_step_poll(const uiBut *but)
 | 
			
		||||
	BLI_assert(but->type == UI_BTYPE_MENU);
 | 
			
		||||
 | 
			
		||||
	/* currenly only RNA buttons */
 | 
			
		||||
	return (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM);
 | 
			
		||||
	return ((but->menu_step_func != NULL) ||
 | 
			
		||||
	        (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ui_but_menu_step(uiBut *but, int direction)
 | 
			
		||||
{
 | 
			
		||||
	if (ui_but_menu_step_poll(but)) {
 | 
			
		||||
		return rna_property_enum_step(but->block->evil_C, &but->rnapoin, but->rnaprop, direction);
 | 
			
		||||
		if (but->menu_step_func) {
 | 
			
		||||
			return but->menu_step_func(but->block->evil_C, direction, but->poin);
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			return rna_property_enum_step(but->block->evil_C, &but->rnapoin, but->rnaprop, direction);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	printf("%s: cannot cycle button '%s'\n", __func__, but->str);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user