From ed870f87b94224c195cbe2df14445e4808b7b5f3 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 20 Jul 2020 19:46:08 +0200 Subject: Fix weird placement of "Motion Tracking" in 3D View overlay popup There was a weird looking gap between the checkbox and the "Motion Tracking" label. Plus, the label could not be clicked to change the value, unlike usually. Issue is that the row is actually a sub-panel header. The checkbox being drawn with the draw_header() callback, and the label being added as separate item by the popover panel code. This adds a hack so the checkbox can add the panel label itself (the popup drawing skips adding the label then). That addresses mentioned issues. --- release/scripts/startup/bl_ui/space_view3d.py | 2 +- .../blender/editors/interface/interface_layout.c | 28 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index b3ca6f1c3fe..3a5efc30f50 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -6153,7 +6153,7 @@ class VIEW3D_PT_overlay_motion_tracking(Panel): def draw_header(self, context): view = context.space_data - self.layout.prop(view, "show_reconstruction", text="") + self.layout.prop(view, "show_reconstruction", text=self.bl_label) def draw(self, context): layout = self.layout diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index f027a62cbfd..b707aaa0ee9 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -5540,6 +5540,26 @@ void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout) } } +static bool ui_layout_has_panel_label(const uiLayout *layout, const PanelType *pt) +{ + LISTBASE_FOREACH (uiItem *, subitem, &layout->items) { + if (subitem->type == ITEM_BUTTON) { + uiButtonItem *bitem = (uiButtonItem *)subitem; + if (!(bitem->but->flag & UI_HIDDEN) && STREQ(bitem->but->str, pt->label)) { + return true; + } + } + else { + uiLayout *litem = (uiLayout *)subitem; + if (ui_layout_has_panel_label(litem, pt)) { + return true; + } + } + } + + return false; +} + static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout, bool show_header) { Panel *panel = MEM_callocN(sizeof(Panel), "popover panel"); @@ -5556,7 +5576,13 @@ static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout, pt->draw_header(C, panel); panel->layout = NULL; } - uiItemL(row, CTX_IFACE_(pt->translation_context, pt->label), ICON_NONE); + + /* draw_header() is often used to add a checkbox to the header. If we add the label like below + * the label is disconnected from the checkbox, adding a weird looking gap. As workaround, let + * the checkbox add the label instead. */ + if (!ui_layout_has_panel_label(row, pt)) { + uiItemL(row, CTX_IFACE_(pt->translation_context, pt->label), ICON_NONE); + } } panel->layout = layout; -- cgit v1.2.3