Cleanup: Nodes: Simplify drawing function #112860

Merged
Lukas Tönne merged 5 commits from LukasTonne/blender:recursive-panel-drawing into main 2023-09-27 11:48:48 +02:00
Member

The node drawing function currently uses a stack-based traversal of
interface items. This is hard to read and for this purpose a recursive
function is easier to understand.

The node drawing function currently uses a stack-based traversal of interface items. This is hard to read and for this purpose a recursive function is easier to understand.
Lukas Tönne added 2 commits 2023-09-25 16:52:01 +02:00
Author
Member

This is in preparation for solving #112588 which would add some more complexity to the drawing code.

This is in preparation for solving #112588 which would add some more complexity to the drawing code.
Lukas Tönne requested review from Jacques Lucke 2023-09-25 16:53:00 +02:00
Lukas Tönne added this to the Nodes & Physics project 2023-09-25 16:53:05 +02:00
Lukas Tönne changed title from Nodes: Simplified drawing function. to WIP: Nodes: Simplified drawing function. 2023-09-25 17:51:17 +02:00
Lukas Tönne added 2 commits 2023-09-25 18:01:30 +02:00
Lukas Tönne changed title from WIP: Nodes: Simplified drawing function. to Nodes: Simplified drawing function. 2023-09-25 18:01:46 +02:00
Hans Goudey changed title from Nodes: Simplified drawing function. to Nodes: Simplify drawing function 2023-09-25 19:14:51 +02:00
Hans Goudey changed title from Nodes: Simplify drawing function to Cleanup: Nodes: Simplify drawing function 2023-09-25 19:14:59 +02:00
Hans Goudey reviewed 2023-09-25 19:17:08 +02:00
@ -672,0 +641,4 @@
/* Recursive function that adds the expected number of items in a panel and advances the
* iterator. */
std::function<void(int, bool, const char *, bke::bNodePanelRuntime *)> add_panel_items_recursive;
Member

Could this be a lambda rather than std::function?

const auto add_panel_items_recursive = [&](...) { }

Could this be a lambda rather than `std::function`? `const auto add_panel_items_recursive = [&](...) { }`

This is recursion lambda...

This is recursion lambda...
Member

Huh, I see, it can't call itself. Seems like it should just be a separate function maybe?

Huh, I see, it can't call itself. Seems like it should just be a separate function maybe?
Author
Member

Reason it's a std::function:

  1. Needs a "forward declaration" to be able to do recursion.
  2. Accesses a bunch of state variables that need to be carried along, either as a function argument or as functor members.

I wanted to avoid sweeping changes, the std::function was the smallest change that would work.

Reason it's a std::function: 1. Needs a "forward declaration" to be able to do recursion. 2. Accesses a bunch of state variables that need to be carried along, either as a function argument or as functor members. I wanted to avoid sweeping changes, the std::function was the smallest change that would work.
Author
Member

Changed it to free functions with a state argument that contains all the iterator variables. Not necessarily less code but maybe slightly easier to understand?

Changed it to free functions with a state argument that contains all the iterator variables. Not necessarily less code but maybe slightly easier to understand?
Lukas Tönne added 1 commit 2023-09-26 14:35:38 +02:00
Jacques Lucke approved these changes 2023-09-27 11:44:33 +02:00
Jacques Lucke left a comment
Member

LGTM, using recursion here instead of stack seems to be easier indeed.

LGTM, using recursion here instead of stack seems to be easier indeed.
Lukas Tönne merged commit 2f1b8f59e3 into main 2023-09-27 11:48:48 +02:00
Lukas Tönne deleted branch recursive-panel-drawing 2023-09-27 11:48:49 +02:00
Sign in to join this conversation.
No reviewers
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 Assignees
4 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#112860
No description provided.