diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2018-04-20 18:14:03 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2018-04-20 18:14:52 +0300 |
commit | 5f6c45498c92b91a710a1317f6d41f73fbe83477 (patch) | |
tree | 93b136fb49c656c2c2a5463c91e8a6a38d518354 /source/blender/editors/interface/interface.c | |
parent | 4bfb6d21df96688187f6f1a5d95dd62bcbf85116 (diff) |
UI: New Global Top-Bar (WIP)
== Main Features/Changes for Users
* Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars.
* Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector.
* Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here.
* Individual sections of the topbar are individually scrollable.
* Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting.
* Top-bar should scale nicely with DPI.
* The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes).
* Info editors at the top of the window and using the full window width with be replaced by the top-bar.
* In fullscreen modes, no more info editor is added on top, the top-bar replaces it.
== Technical Features/Changes
* Adds initial support for global areas
A global area is part of the window, not part of the regular screen-layout.
I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas.
* Adds a TOPBAR editor type
The editor type is hidden in the UI editor type menu.
* Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY)
* Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar.
* Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds.
The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved.
* Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code.
Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being.
NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility.
== ToDo's
It's a bit hard to predict all the ToDo's here are the known main ones:
* Add options for the new active-tool system and for operator redo to the topbar.
* Automatically hide the top-bar in fullscreen modes.
* General visual polish.
* Top-bar drag & drop support (WIP in temp-tab_drag_drop).
* Improve dynamic regions (should also fix some layout glitches).
* Make internal terminology consistent.
* Enable topbar file writing once design is more advanced.
* Address TODO's and XXX's in code :)
Thanks @brecht for the review! And @sergey for the complaining ;)
Differential Revision: D2758
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 82 |
1 files changed, 63 insertions, 19 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 20eb0ce50e5..a9fdd1678e2 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1193,7 +1193,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x if (block->layouts.first) { UI_block_layout_resolve(block, NULL, NULL); } - ui_block_align_calc(block); + ui_block_align_calc(block, CTX_wm_region(C)); if ((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) { ui_menu_block_set_keyaccels(block); /* could use a different flag to check */ } @@ -1420,7 +1420,6 @@ int ui_but_is_pushed_ex(uiBut *but, double *value) break; case UI_BTYPE_ROW: case UI_BTYPE_LISTROW: - case UI_BTYPE_TAB: UI_GET_BUT_VALUE_INIT(but, *value); /* support for rna enum buts */ if (but->rnaprop && (RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG)) { @@ -1430,6 +1429,18 @@ int ui_but_is_pushed_ex(uiBut *but, double *value) if (*value == (double)but->hardmax) is_push = true; } break; + case UI_BTYPE_TAB: + if (but->rnaprop && but->custom_data) { + /* uiBut.custom_data points to data this tab represents (e.g. workspace). + * uiBut.rnapoin/prop store an active value (e.g. active workspace). */ + if (RNA_property_type(but->rnaprop) == PROP_POINTER) { + PointerRNA active_ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop); + if (active_ptr.data == but->custom_data) { + is_push = true; + } + } + } + break; default: is_push = -1; break; @@ -1915,7 +1926,7 @@ static bool ui_but_icon_extra_is_visible_text_clear(const uiBut *but) static bool ui_but_icon_extra_is_visible_search_unlink(const uiBut *but) { - BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); + BLI_assert(ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)); return ((but->editstr == NULL) && (but->drawstr[0] != '\0') && (but->flag & UI_BUT_VALUE_CLEAR)); @@ -1958,6 +1969,11 @@ uiButExtraIconType ui_but_icon_extra_get(uiBut *but) return UI_BUT_ICONEXTRA_EYEDROPPER; } break; + case UI_BTYPE_TAB: + if (ui_but_icon_extra_is_visible_search_unlink(but)) { + return UI_BUT_ICONEXTRA_CLEAR; + } + break; default: break; } @@ -2071,14 +2087,23 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int *r_use_exp_float = false; } - if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { + if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) { PropertyType type; const char *buf = NULL; int buf_len; type = RNA_property_type(but->rnaprop); - if (type == PROP_STRING) { + if ((but->type == UI_BTYPE_TAB) && (but->custom_data)) { + StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); + PointerRNA ptr; + + /* uiBut.custom_data points to data this tab represents (e.g. workspace). + * uiBut.rnapoin/prop store an active value (e.g. active workspace). */ + RNA_pointer_create(but->rnapoin.id.data, ptr_type, but->custom_data, &ptr); + buf = RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len); + } + else if (type == PROP_STRING) { /* RNA string */ buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen, &buf_len); } @@ -2114,12 +2139,7 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int MEM_freeN((void *)buf); } } - else if (but->type == UI_BTYPE_TEXT) { - /* string */ - BLI_strncpy(str, but->poin, maxlen); - return; - } - else if (but->type == UI_BTYPE_SEARCH_MENU) { + else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { /* string */ BLI_strncpy(str, but->poin, maxlen); return; @@ -2329,18 +2349,16 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) return true; } else if (type == PROP_POINTER) { - /* RNA pointer */ - PointerRNA ptr, rptr; - PropertyRNA *prop; - if (str[0] == '\0') { RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL); return true; } else { - ptr = but->rnasearchpoin; - prop = but->rnasearchprop; - + /* RNA pointer */ + PointerRNA rptr; + PointerRNA ptr = but->rnasearchpoin; + PropertyRNA *prop = but->rnasearchprop; + if (prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr)) RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr); @@ -2362,6 +2380,21 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) } } } + else if (but->type == UI_BTYPE_TAB) { + if (but->rnaprop && but->custom_data) { + StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); + PointerRNA ptr; + PropertyRNA *prop; + + /* uiBut.custom_data points to data this tab represents (e.g. workspace). + * uiBut.rnapoin/prop store an active value (e.g. active workspace). */ + RNA_pointer_create(but->rnapoin.id.data, ptr_type, but->custom_data, &ptr); + prop = RNA_struct_name_property(ptr_type); + if (RNA_property_editable(&ptr, prop)) { + RNA_property_string_set(&ptr, prop, str); + } + } + } else if (but->type == UI_BTYPE_TEXT) { /* string */ if (!but->poin || (str[0] == '\0')) { @@ -2907,6 +2940,7 @@ void ui_but_update_ex(uiBut *but, const bool validate) case UI_BTYPE_TEXT: case UI_BTYPE_SEARCH_MENU: + case UI_BTYPE_TAB: if (!but->editstr) { char str[UI_MAX_DRAW_STR]; @@ -3030,6 +3064,16 @@ void ui_block_cm_to_display_space_range(uiBlock *block, float *min, float *max) *max = max_fff(UNPACK3(pixel)); } +static uiBut *ui_but_alloc(const eButType type) +{ + switch (type) { + case UI_BTYPE_TAB: + return MEM_callocN(sizeof(uiButTab), "uiButTab"); + default: + return MEM_callocN(sizeof(uiBut), "uiBut"); + } +} + /** * \brief ui_def_but is the function that draws many button types * @@ -3063,7 +3107,7 @@ static uiBut *ui_def_but( } } - but = MEM_callocN(sizeof(uiBut), "uiBut"); + but = ui_but_alloc(type & BUTTYPE); but->type = type & BUTTYPE; but->pointype = type & UI_BUT_POIN_TYPES; |