diff options
author | Joshua Leung <aligorith@gmail.com> | 2018-05-11 21:43:44 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2018-05-11 21:43:44 +0300 |
commit | 9637e4e65f1dba914eee80fa3b1fbe7b9c30f569 (patch) | |
tree | f96653fd5cd7086fb4d9c5381ff804499a50a16e | |
parent | f998bad211aee61fe5131d7b8b56cd24969f29cc (diff) |
WIP: Quick hack to get Timeline header buttons to show up where we want them totmp-TimelineHeaderButtonsStretching
WARNING: Prototype code to test that the UI design idea works.
This is a nasty hack, as it uses hardcoded button sizes (extracted by hand from
a screenshot and tweaked), and used to adjust the scale_x of layout items used
to house the spacers-layouts.
(The non-hacky part of this the new "uiItemSpacer" widget. Eventually the layout
manager should be identifying these widgets and setting the sizes on them in using
a method similar to what we're doing here).
-rw-r--r-- | release/scripts/startup/bl_ui/space_time.py | 69 | ||||
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 16 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui_api.c | 3 |
4 files changed, 61 insertions, 28 deletions
diff --git a/release/scripts/startup/bl_ui/space_time.py b/release/scripts/startup/bl_ui/space_time.py index 3a6fa40aebd..4b7d51ea049 100644 --- a/release/scripts/startup/bl_ui/space_time.py +++ b/release/scripts/startup/bl_ui/space_time.py @@ -35,16 +35,31 @@ class TIME_HT_editor_buttons(Header): scene = context.scene toolsettings = context.tool_settings screen = context.screen + + # XXX: Nasty layout hacks ------------------------------ + MAX_WIDTH = context.area.width + UI_UNIT_X = 20.0 + UI_DPI_FAC = context.user_preferences.system.ui_scale + + # 7 for playback, 17 for frame nums (4 per control + 1 + 1), + menus + total_content_width = (18 + 8 + 16) * UI_UNIT_X * UI_DPI_FAC + + free_space = MAX_WIDTH - total_content_width + if free_space < 0: + spacer_scale = 0.1 + else: + spacer_scale = (free_space / 2) / (UI_UNIT_X * UI_DPI_FAC) + #print("area width = %s, total_content = %s, spacer_scale = %s" % (MAX_WIDTH, total_content_width, spacer_scale)) + + # XXX: Nasty layout hacks end --------------------------- - layout.separator() # XXX: This should be dynamic (e.g. layout.separator(stretch=1.0)) - layout.separator() - layout.separator() - layout.separator() - layout.separator() - layout.separator() - layout.separator() + row = layout.row() + row.alignment = 'EXPAND' + row.scale_x = spacer_scale + row.spacer() row = layout.row(align=True) + row.alignment = 'CENTER' row.prop(toolsettings, "use_keyframe_insert_auto", text="", toggle=True) row.operator("screen.frame_jump", text="", icon='REW').end = False @@ -67,34 +82,34 @@ class TIME_HT_editor_buttons(Header): row.operator("screen.keyframe_jump", text="", icon='NEXT_KEYFRAME').next = True row.operator("screen.frame_jump", text="", icon='FF').end = True - layout.separator() # XXX: This should be dynamic (e.g. layout.separator(stretch=1.0)) - layout.separator() - layout.separator() - layout.separator() - layout.separator() - layout.separator() - layout.separator() + row = layout.row() + row.alignment = 'EXPAND' + row.scale_x = spacer_scale + row.spacer() row = layout.row() - row.scale_x = 0.95 + row.alignment = 'RIGHT' + + subrow = row.row() + subrow.scale_x = 0.95 if scene.show_subframe: - row.prop(scene, "frame_float", text="") + subrow.prop(scene, "frame_float", text="") else: - row.prop(scene, "frame_current", text="") + subrow.prop(scene, "frame_current", text="") - layout.separator() - layout.separator() + row.separator() + row.separator() - row = layout.row(align=True) - row.prop(scene, "use_preview_range", text="", toggle=True) - sub = row.row(align=True) - sub.scale_x = 0.8 + subrow = row.row(align=True) + subrow.prop(scene, "use_preview_range", text="", toggle=True) + subsub = subrow.row(align=True) + subsub.scale_x = 0.8 if not scene.use_preview_range: - sub.prop(scene, "frame_start", text="Start") - sub.prop(scene, "frame_end", text="End") + subsub.prop(scene, "frame_start", text="Start") + subsub.prop(scene, "frame_end", text="End") else: - sub.prop(scene, "frame_preview_start", text="Start") - sub.prop(scene, "frame_preview_end", text="End") + subsub.prop(scene, "frame_preview_start", text="Start") + subsub.prop(scene, "frame_preview_end", text="End") class TIME_MT_editor_menus(Menu): diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 89c75e955ce..bafe727220b 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -1105,6 +1105,7 @@ void uiItemLDrag(uiLayout *layout, struct PointerRNA *ptr, const char *name, int void uiItemM(uiLayout *layout, struct bContext *C, const char *menuname, const char *name, int icon); /* menu */ void uiItemV(uiLayout *layout, const char *name, int icon, int argval); /* value */ void uiItemS(uiLayout *layout); /* separator */ +void uiItemSpacer(uiLayout *layout); /* separator that stretches */ void uiItemPopoverPanel_ptr( uiLayout *layout, struct bContext *C, diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 3a8e53d3e90..bc669021f7c 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2113,6 +2113,18 @@ void uiItemS(uiLayout *layout) uiDefBut(block, (is_menu) ? UI_BTYPE_SEPR_LINE : UI_BTYPE_SEPR, 0, "", 0, 0, space, space, NULL, 0.0, 0.0, 0, 0, ""); } +/* spacer item - a separator that stretches out by default */ +void uiItemSpacer(uiLayout *layout) +{ + uiBlock *block = layout->root->block; + uiBut *but; + int space = UI_UNIT_X; + + UI_block_layout_set_current(block, layout); + but = uiDefBut(block, UI_BTYPE_SEPR, 0, "", 0, 0, space, space, NULL, 0.0, 0.0, 0, 0, ""); + //printf(" spacer: s = %p -> L = %p\n", but, layout); +} + /* level items */ void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg) { @@ -2331,6 +2343,7 @@ static void ui_litem_layout_row(uiLayout *litem) { min_flag = false; } + if ((neww < minw || min_flag) && w != 0) { /* fixed size */ @@ -2360,7 +2373,8 @@ static void ui_litem_layout_row(uiLayout *litem) for (item = litem->items.first; item; item = item->next) { ui_item_size(item, &itemw, &itemh); - minw = ui_litem_min_width(itemw); + //minw = ui_litem_min_width(itemw); + minw = itemw; if (item->flag & UI_ITEM_FIXED) { /* fixed minimum size items */ diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index d61f6166889..bb8a45d8827 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -718,6 +718,9 @@ void RNA_api_ui_layout(StructRNA *srna) func = RNA_def_function(srna, "separator", "uiItemS"); RNA_def_function_ui_description(func, "Item. Inserts empty space into the layout between items"); + + func = RNA_def_function(srna, "spacer", "uiItemSpacer"); + RNA_def_function_ui_description(func, "Item. Inserts empty space into layout between items that can grow and shrink as needed"); /* context */ func = RNA_def_function(srna, "context_pointer_set", "uiLayoutSetContextPointer"); |