UI: Support layout panels in dialog popups #119519

Merged
Jacques Lucke merged 22 commits from guishe/blender:dialog-layout-panels into main 2024-03-21 10:31:15 +01:00
Contributor

Enables operators that uses WM_operator_props_dialog_popup
or redo popup to use layout panels.

Other popups would likely also support layout panels, only
they need to set its dummy panel with UI_popup_dummy_panel_set


4.1 patch (redo region\redo popup\ dialog popup) (changes to operator draw not included).
image image

Python test example

import bpy
from bpy.props import StringProperty, BoolProperty, EnumProperty


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    
    mesh: BoolProperty(name="Mesh")
    light: BoolProperty(name="Light")
    panel_open_state: BoolProperty(name="panel_open_state")
    
    @classmethod
    def poll(cls, context):
        return True

    def execute(self, context):
        return {'FINISHED'}

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        header, panel = layout.panel("import", default_closed=False)
        header.label(text="Import")
        layout.use_property_split=True
        if panel:
            panel.prop(self,"mesh")
            panel.prop(self,"light")
        layout.prop(self,"panel_open_state")
        header, panel = layout.panel_prop(self,"panel_open_state")
        header.label(text="Panel from prop")
        if panel:
            panel.prop(self,"mesh")
            panel.prop(self,"light")
            sub_header, sub_panel = panel.panel("sub_panel", default_closed=False)
            sub_header.label(text="Sub Panel")
            if sub_panel:
                sub_panel.prop(self,"mesh")
                sub_panel.prop(self,"light")
            
            
    def invoke(self, context ,event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)



def menu_func(self, context):
    self.layout.operator(SimpleOperator.bl_idname, text=SimpleOperator.bl_label)

def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.types.TOPBAR_MT_file.append(menu_func)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    bpy.types.TOPBAR_MT_file.remove(menu_func)
    
register()




Enables operators that uses `WM_operator_props_dialog_popup` or `redo` popup to use layout panels. Other popups would likely also support layout panels, only they need to set its dummy panel with `UI_popup_dummy_panel_set` <hr> | 4.1 | patch (redo region\redo popup\ dialog popup) (changes to operator draw not included). | | -------- | -------- | |![image](/attachments/e8081a00-791d-4cc1-ae76-e8c78f3cbc11)| ![image](/attachments/8a0990ee-bce1-4daf-be66-b7be93369f8c) | Python test example ``` python import bpy from bpy.props import StringProperty, BoolProperty, EnumProperty class SimpleOperator(bpy.types.Operator): """Tooltip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" bl_options = {'REGISTER', 'UNDO'} mesh: BoolProperty(name="Mesh") light: BoolProperty(name="Light") panel_open_state: BoolProperty(name="panel_open_state") @classmethod def poll(cls, context): return True def execute(self, context): return {'FINISHED'} def draw(self, context): layout = self.layout layout.use_property_split = True header, panel = layout.panel("import", default_closed=False) header.label(text="Import") layout.use_property_split=True if panel: panel.prop(self,"mesh") panel.prop(self,"light") layout.prop(self,"panel_open_state") header, panel = layout.panel_prop(self,"panel_open_state") header.label(text="Panel from prop") if panel: panel.prop(self,"mesh") panel.prop(self,"light") sub_header, sub_panel = panel.panel("sub_panel", default_closed=False) sub_header.label(text="Sub Panel") if sub_panel: sub_panel.prop(self,"mesh") sub_panel.prop(self,"light") def invoke(self, context ,event): wm = context.window_manager return wm.invoke_props_dialog(self) def menu_func(self, context): self.layout.operator(SimpleOperator.bl_idname, text=SimpleOperator.bl_label) def register(): bpy.utils.register_class(SimpleOperator) bpy.types.TOPBAR_MT_file.append(menu_func) def unregister(): bpy.utils.unregister_class(SimpleOperator) bpy.types.TOPBAR_MT_file.remove(menu_func) register() ``` <video src="https://projects.blender.org/attachments/c19aae23-be50-4aee-90aa-74e6f8eade9c" title="2024-03-15 08-08-49.mp4" controls></video>
Guillermo Venegas added 1 commit 2024-03-15 15:15:29 +01:00
Guillermo Venegas added 1 commit 2024-03-16 03:04:53 +01:00
Guillermo Venegas added 1 commit 2024-03-16 11:36:30 +01:00
Guillermo Venegas added 1 commit 2024-03-16 11:38:10 +01:00
Guillermo Venegas added 1 commit 2024-03-16 17:56:44 +01:00
Guillermo Venegas added 1 commit 2024-03-16 18:01:02 +01:00
Guillermo Venegas added 2 commits 2024-03-17 19:48:48 +01:00
Guillermo Venegas added 3 commits 2024-03-17 20:15:19 +01:00
Guillermo Venegas added 1 commit 2024-03-17 20:16:44 +01:00
Guillermo Venegas added 1 commit 2024-03-17 20:35:11 +01:00
Guillermo Venegas changed title from WIP: UI: Support layout panels in dialog popups to UI: Support layout panels in dialog popups 2024-03-17 21:14:30 +01:00
Guillermo Venegas added 1 commit 2024-03-17 22:55:40 +01:00
Iliya Katushenock added this to the User Interface project 2024-03-17 23:01:55 +01:00
Guillermo Venegas added 1 commit 2024-03-17 23:59:51 +01:00
Author
Contributor

There is a odd alignment in sub panel backdrops, but i would prefer to solve that in a different patch that also add the sub panel color as user pref

image

There is a odd alignment in sub panel backdrops, but i would prefer to solve that in a different patch that also add the sub panel color as user pref ![image](/attachments/1b0b3ab7-def7-4fd1-94b1-418c9bb334f2)
Guillermo Venegas requested review from Jacques Lucke 2024-03-18 15:41:59 +01:00
Guillermo Venegas requested review from Jesse Yurkovich 2024-03-18 15:41:59 +01:00
Member

Does clicking and dragging to open/close multiple panels work for you?

Does clicking and dragging to open/close multiple panels work for you?
Guillermo Venegas added 2 commits 2024-03-18 20:41:31 +01:00
Author
Contributor

Fixed now, i noticed this other issue that happens with layout panels in general #119639

Fixed now, i noticed this other issue that happens with layout panels in general https://projects.blender.org/blender/blender/issues/119639
Jacques Lucke requested changes 2024-03-19 13:22:36 +01:00
Jacques Lucke left a comment
Member

The code generally seems fine, I only have one major comment: Do we really need two kinds of function pointers for creating popup blocks (uiBlockCreateFunc and uiBlockCreateWithPanelFunc)?

Having two methods to do this creates potentially unnecessary complexity.

I can think of the following alternatives for now:

  1. Pass panel to all block-create-functions.
  2. Don't pass the panel as function parameter but indirectly through e.g. region->runtime.popup_block_panel. Maybe we could also get rid of UI_block_set_root_panel in this case.
  3. Try to use UI_panel_begin in the popup which also initializes block->panel.
The code generally seems fine, I only have one major comment: Do we really need two kinds of function pointers for creating popup blocks (`uiBlockCreateFunc` and `uiBlockCreateWithPanelFunc`)? Having two methods to do this creates potentially unnecessary complexity. I can think of the following alternatives for now: 1. Pass panel to all block-create-functions. 2. Don't pass the panel as function parameter but indirectly through e.g. `region->runtime.popup_block_panel`. Maybe we could also get rid of `UI_block_set_root_panel` in this case. 3. Try to use `UI_panel_begin` in the popup which also initializes `block->panel`.
@ -765,13 +776,26 @@ uiLayout *UI_pie_menu_layout(uiPieMenu *pie);
* Functions used to create popup blocks. These are like popup menus
* but allow using all button types and creating their own layout. */
using uiBlockCreateFunc = uiBlock *(*)(bContext *C, ARegion *region, void *arg1);
/** Function used to create popup blocks, with a given dummy `panel` so popups can support creating
Member

Comment style (newline after /**).

Comment style (newline after `/**`).
guishe marked this conversation as resolved
@ -2096,6 +2096,15 @@ void UI_block_draw(const bContext *C, uiBlock *block)
UI_panel_should_show_background(region, block->panel->type),
region->flag & RGN_FLAG_SEARCH_FILTER_ACTIVE);
}
/** Shared layout panel backdrop style between redo region and popups. */
Member

Comment style, same below.

Comment style, same below.
guishe marked this conversation as resolved
@ -834,2 +834,4 @@
struct uiPopupBlockCreate {
uiBlockCreateFunc create_func;
uiBlockCreateWithPanelFunc create_with_panel_func;
/** Dummy panel used in popups created with #create_with_panel_func so they can support layout
Member

Comment style.

Comment style.
guishe marked this conversation as resolved
@ -753,7 +773,14 @@ uiBlock *ui_popup_block_refresh(bContext *C,
region->winrct.ymax = block->rect.ymax + UI_POPUP_MENU_TOP;
UI_block_translate(block, -region->winrct.xmin, -region->winrct.ymin);
/** Popups can change size, fix scroll ofsset if a panel was closed. */
Member

typo and comment style (use /* ... */ for comments that are not for functions/data members)

typo and comment style (use `/* ... */` for comments that are not for functions/data members)
guishe marked this conversation as resolved
@ -821,0 +851,4 @@
handle->popup_create_vars.panel = nullptr;
if (std::holds_alternative<uiBlockCreateWithPanelFunc>(create_func) &&
std::get<uiBlockCreateWithPanelFunc>(create_func))
Member

Looks like you're checking the same thing twice here.

Looks like you're checking the same thing twice here.
guishe marked this conversation as resolved
Guillermo Venegas added 1 commit 2024-03-19 17:04:05 +01:00
Guillermo Venegas added 1 commit 2024-03-19 17:09:11 +01:00
Guillermo Venegas requested review from Jacques Lucke 2024-03-19 17:12:56 +01:00
Jacques Lucke reviewed 2024-03-19 18:45:11 +01:00
@ -1376,0 +1385,4 @@
return type;
}();
bool open;
panel = UI_panel_begin(region, &region->panels, block, &panel_type, panel, &open);
Member

Hm, seems tricky to call UI_panel_begin without ever calling UI_panel_end. I think, given the approach used now, UI_panel_begin shouldn't be called and what you did before to create the dummy panel was better.

Hm, seems tricky to call `UI_panel_begin` without ever calling `UI_panel_end`. I think, given the approach used now, `UI_panel_begin` shouldn't be called and what you did before to create the dummy panel was better.
guishe marked this conversation as resolved
Guillermo Venegas added 1 commit 2024-03-19 20:19:45 +01:00
Jacques Lucke requested changes 2024-03-20 11:24:13 +01:00
@ -712,6 +712,17 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) A
* E.g. WM might need to do this for exiting files correctly.
*/
void UI_popup_menu_retval_set(const uiBlock *block, int retval, bool enable);
void UI_popup_dummy_panel_set(ARegion *region, uiBlock *block);
Member

Add comment to this function.

Add comment to this function.
guishe marked this conversation as resolved
@ -579,0 +605,4 @@
}
panel->runtime->layout_panels.clear();
block->panel = panel;
panel->runtime->block=block;
Member

Use make format (even better, configure clang format to run on every save)

Use `make format` (even better, configure [clang format](https://developer.blender.org/docs/handbook/tooling/clangformat/) to run on every save)
guishe marked this conversation as resolved
@ -878,2 +919,4 @@
ui_popup_block_remove(C, handle);
if (handle->region->runtime.popup_block_panel) {
BKE_panel_free(handle->region->runtime.popup_block_panel);
Member

I get a crash when closing the splash screen here.
This code might have to come before ui_popup_block_remove above.

I get a crash when closing the splash screen here. This code might have to come before `ui_popup_block_remove` above.
guishe marked this conversation as resolved
Guillermo Venegas added 1 commit 2024-03-20 14:31:49 +01:00
Jacques Lucke approved these changes 2024-03-20 18:15:59 +01:00
@ -2098,1 +2098,4 @@
}
/* Shared layout panel backdrop style between redo region and popups. */
if (block->panel && ELEM(region->regiontype, RGN_TYPE_HUD, RGN_TYPE_TEMPORARY)) {
/** TODO: Add as theme color. */
Member

Comment style.

Comment style.
guishe marked this conversation as resolved
Guillermo Venegas added 1 commit 2024-03-20 19:18:28 +01:00
Jacques Lucke merged commit aa03646a74 into main 2024-03-21 10:31:15 +01:00
Member

Can you update the release notes?

Can you update the release notes?
Author
Contributor

i will check

i will check
Guillermo Venegas deleted branch dialog-layout-panels 2024-03-21 14:14:29 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119519
No description provided.