UI: Generalize drop target API, support them for UI views #105963

Closed
Julian Eisel wants to merge 8 commits from JulianEisel:temp-ui-view-drop-controller into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Previously UI view items would support custom drop controllers (so they
could react to data being dragged over them and dropped). This is now
more generalized so the views themselves can do this as well.

3 main changes:

  • Support calculating a bounding box for the view, so this can be used for recognizing mouse hovering.
  • Generalize drop controllers. There is a new ui::DropControllerInterface now.
  • Add support for drop controllers in the ui::AbstractView base class, so custom views can use this.
Previously UI view items would support custom drop controllers (so they could react to data being dragged over them and dropped). This is now more generalized so the views themselves can do this as well. 3 main changes: - Support calculating a bounding box for the view, so this can be used for recognizing mouse hovering. - Generalize drop controllers. There is a new `ui::DropControllerInterface` now. - Add support for drop controllers in the `ui::AbstractView` base class, so custom views can use this.
Julian Eisel added 1 commit 2023-03-21 17:35:16 +01:00
71e0c6c043 UI: Generalize drop controllers, support them for UI views
Previously UI view items would support custom drop controllers (so they
could react to data being dragged over them and dropped). This is now
more generalized so the views themselves can do this as well.
Julian Eisel added this to the User Interface project 2023-03-21 17:35:34 +01:00
Hans Goudey reviewed 2023-03-21 18:35:13 +01:00
Hans Goudey left a comment
Member

First of all, good to generalize the idea of a drop target, I think that's helpful. However, with these interfaces, inheritance, etc. I'm a bit afraid that we're heading in the direction of having massive class hierarchies that will end up being overwhelming and hard to grasp.

Without a full understanding of the issue, it's hard for me to suggest alternatives, but I wonder if a few things would help:

  • Simplify naming: ControllerInterface, quite technically correct I guess, is pretty vague and theoretical. I think simply DropTarget would be a simpler name that gets the same things across. DropTarget can still have virtual methods and be inherited from, but at least it corresponds to a real thing that's more easily imaginable. DropHandler might work too.
  • Remove some of the UI_ wrapper functions
  • Actually that's it, I didn't think of anything else

Do you think that's reasonable. I know it's hard to move towards a proper design when the existing UI code is so hard to change.

First of all, good to generalize the idea of a drop target, I think that's helpful. However, with these interfaces, inheritance, etc. I'm a bit afraid that we're heading in the direction of having massive class hierarchies that will end up being overwhelming and hard to grasp. Without a full understanding of the issue, it's hard for me to suggest alternatives, but I wonder if a few things would help: - Simplify naming: `ControllerInterface`, quite technically correct I guess, is pretty vague and theoretical. I think simply `DropTarget` would be a simpler name that gets the same things across. `DropTarget` can still have virtual methods and be inherited from, but at least it corresponds to a real thing that's more easily imaginable. `DropHandler` might work too. - Remove some of the `UI_` wrapper functions - Actually that's it, I didn't think of anything else Do you think that's reasonable. I know it's hard to move towards a proper design when the existing UI code is so hard to change.
@ -56,1 +62,4 @@
/**
* Interface class to implement dropping for various kinds of UI elements. This isn't used widely,
* only UI views and view items use it. Would probably be nice to have more general support for
Member

This sort of "would probably be nice to use this more in the future" comment shouldn't be added to main I think. That makes sense in code documentation or design tasks, but the code should stand for itself generally, and this comment will just become out of date otherwise.

This sort of "would probably be nice to use this more in the future" comment shouldn't be added to main I think. That makes sense in code documentation or design tasks, but the code should stand for itself generally, and this comment will just become out of date otherwise.
JulianEisel marked this conversation as resolved
@ -113,0 +165,4 @@
* Call #DropControllerInterface::drop_tooltip() and return the result as newly allocated C string
* (unless the result is empty, returns null then). Needs freeing with MEM_freeN().
*/
char *UI_drop_controller_drop_tooltip(const blender::ui::DropControllerInterface &drop_controller,
Member

Ideally new functions added to this UI C++ header should be in the proper blender::ed::ui (looks like it's blender::ui right now, oops!) namespace, without the UI_ prefix. Might as well start that now IMO.

Ideally new functions added to this UI C++ header should be in the proper `blender::ed::ui` (looks like it's `blender::ui` right now, oops!) namespace, without the `UI_` prefix. Might as well start that now IMO.
Julian Eisel added 1 commit 2023-03-22 11:14:29 +01:00
Author
Member

However, with these interfaces, inheritance, etc. I'm a bit afraid that we're heading in the direction of having massive class hierarchies that will end up being overwhelming and hard to grasp.

I'm well aware of the short comings of inheritance and actually often try to avoid it. But for this kind of thing it just makes a lot of sense. For a while there was no common base class for views for example and I tried to share behavior differently. But this caused more trouble than it was helpful.

The views API is already becoming a bit too complex (or inelegant) for my taste although it's not too bad yet. We're still early in exploring this. Generalizing features like dropping out of the views already seems like an improvement in that regard.

  • Simplify naming: ControllerInterface, quite technically correct I guess, is pretty vague and theoretical. I think simply DropTarget would be a simpler name that gets the same things across. DropTarget can still have virtual methods and be inherited from, but at least it corresponds to a real thing that's more easily imaginable. DropHandler might work too.

I think I'd like to go with DropTargetInterface for now. Interface is just a good reminder that this is a base class, and may avoid accidental object slicing. No strong opinion though.

  • Remove some of the UI_ wrapper functions

Some of them I'm just keeping because I want to keep the reinterpret_casts from the C handle to the C++ type local to the implementation files. Hopefully we can get rid of the casting on the longer run.

> However, with these interfaces, inheritance, etc. I'm a bit afraid that we're heading in the direction of having massive class hierarchies that will end up being overwhelming and hard to grasp. I'm well aware of the short comings of inheritance and actually often try to avoid it. But for this kind of thing it just makes a lot of sense. For a while there was no common base class for views for example and I tried to share behavior differently. But this caused more trouble than it was helpful. The views API is already becoming a bit too complex (or inelegant) for my taste although it's not too bad yet. We're still early in exploring this. Generalizing features like dropping out of the views already seems like an improvement in that regard. > - Simplify naming: `ControllerInterface`, quite technically correct I guess, is pretty vague and theoretical. I think simply `DropTarget` would be a simpler name that gets the same things across. `DropTarget` can still have virtual methods and be inherited from, but at least it corresponds to a real thing that's more easily imaginable. `DropHandler` might work too. I think I'd like to go with `DropTargetInterface` for now. *Interface* is just a good reminder that this is a base class, and may avoid accidental object slicing. No strong opinion though. > - Remove some of the `UI_` wrapper functions Some of them I'm just keeping because I want to keep the `reinterpret_cast`s from the C handle to the C++ type local to the implementation files. Hopefully we can get rid of the casting on the longer run.
Author
Member

Briefly checking the code, I think we can get rid of uiViewHandle and uiViewItemHandle easily now, and call the member functions directly instead of requiring UI_ wrappers.

Briefly checking the code, I think we can get rid of `uiViewHandle` and `uiViewItemHandle` easily now, and call the member functions directly instead of requiring `UI_` wrappers.
Julian Eisel added 2 commits 2023-03-22 15:57:48 +01:00
Julian Eisel reviewed 2023-03-22 16:23:18 +01:00
@ -113,0 +165,4 @@
* Call #DropControllerInterface::drop_tooltip() and return the result as newly allocated C string
* (unless the result is empty, returns null then). Needs freeing with MEM_freeN().
*/
char *UI_drop_controller_drop_tooltip(const blender::ui::DropControllerInterface &drop_controller,
Author
Member

Hmmm, I just can't myself to like non-member API functions that don't start with a prefix like UI_. It just looks like local functions to me, not API functions.
Not sure if this is a reasonable concern, or just me having this too deeply embedded in my brain cells :)

Hmmm, I just can't myself to like non-member API functions that don't start with a prefix like `UI_`. It just looks like local functions to me, not API functions. Not sure if this is a reasonable concern, or just me having this too deeply embedded in my brain cells :)
Hans Goudey reviewed 2023-03-22 16:28:04 +01:00
@ -113,0 +165,4 @@
* (unless the result is empty, returns null then). Needs freeing with MEM_freeN().
*/
char *UI_drop_target_tooltip(const blender::ui::DropTargetInterface &drop_target,
const wmDrag &drag);
Member

TBH I'd guess it's just something you're used to. With namespaces, it will usually be something like ui::public_function_thing(...) anyway, so the information is there it just looks different. That way it elegantly replaces the need for the ui_ prefix too.

I think consistency is worth it here.

TBH I'd guess it's just something you're used to. With namespaces, it will usually be something like `ui::public_function_thing(...)` anyway, so the information is there it just looks different. That way it elegantly replaces the need for the `ui_` prefix too. I think consistency is worth it here.
Julian Eisel reviewed 2023-03-22 17:12:14 +01:00
@ -113,0 +165,4 @@
* (unless the result is empty, returns null then). Needs freeing with MEM_freeN().
*/
char *UI_drop_target_tooltip(const blender::ui::DropTargetInterface &drop_target,
const wmDrag &drag);
Author
Member

Still causes some itches to me, but that won't change unless I try hard enough ;/

Still causes some itches to me, but that won't change unless I try hard enough ;/
Julian Eisel added 1 commit 2023-03-22 17:14:33 +01:00
Julian Eisel changed title from UI: Generalize drop controllers, support them for UI views to UI: Generalize drop target API, support them for UI views 2023-03-22 17:15:25 +01:00
Julian Eisel added 1 commit 2023-03-22 17:47:36 +01:00
Julian Eisel added 1 commit 2023-03-22 18:37:32 +01:00
Julian Eisel added 1 commit 2023-03-22 18:40:34 +01:00
Author
Member

Committed as a2d0f7049a.

Committed as a2d0f7049a.
Julian Eisel closed this pull request 2023-03-23 12:25:32 +01:00
Julian Eisel deleted branch temp-ui-view-drop-controller 2023-03-23 12:25:42 +01:00

Pull request closed

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 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#105963
No description provided.