Commit Graph

135 Commits

Author SHA1 Message Date
Bastien Montagne
131d61b534 Fix crash after uiLayout refactor.
Fact that `vector.last()` is undefined when the container is empty is a
bit annoying, forces to check for emptyness everywhere :|
2024-07-10 16:03:48 +02:00
Bastien Montagne
a3f0d81a5e Refactor: UI: Make uiItem layout hierarchy use C++ inheritance.
This commit turns the base struct `uiItem` and all of its descendants
(including `uiButtonItem`, uiLayout`, etc.) into a C++ polymorphic
hierarchy of types.

This allows to use C++ type of memory management, and use non-trivial
types (which will be required to make `PointerRNA` non-trivial).

It also moves the storage of these `uiItems` from `BLI_listbase` to
`blender::Vector`, as our C-based listbase implementation is
incompatible with C++ polymorphism.

This also lead to making `uiItem` parameters of a few utils functions
`const`, to allow passing around `blender::Span` instead of vectors to
some internal helpers.

Pull Request: https://projects.blender.org/blender/blender/pulls/124405
2024-07-10 14:46:06 +02:00
Julian Eisel
721dbfccfd UI: Turn asset shelf popup into a popover, add operator to call from shortcut
Turns the asset shelf into a popover which reduces some of the special
handling. An operator `WM_OT_call_asset_shelf_popover()` (similar to
`WM_OT_call_panel()`) is added to be able to call the popover from shortcuts.
Exactly this was an important aspect for the brush assets project, to allow
quick searching for brushes from the popup.

A custom shortcut can be added to asset shelf popovers using "Assign Shortcut"
in the context menu of buttons invoking it.

The popover is spawned with the mouse hovering the first asset and the search
button active using "semi modal" handling. That means while the popover is
open, any text input is captured by the search button, while the rest of the
popover stays interactive. So for example navigating through asset catalogs is
possible, a single click activates an asset and closes the popover.

Reviewed as part of the asset shelf project, see:
- https://projects.blender.org/blender/blender/issues/116337
- https://projects.blender.org/blender/blender/pulls/106303
2024-07-08 17:50:24 +02:00
Julian Eisel
5f6586526c UI: Support semi-modal text input while other UI stays interactive
Adds support for text buttons that capture text input, while the rest of the
UI stays interactive. This is useful for example for filter buttons in popups
that are used for searching. Current search popups are an ad-hoc implementation
that doesn't use the normal widget system (and thus are quite limited).

For the brush assets project this is important to allow quickly popping up the
brush asset shelf popup, immediately typing to search a brush, and activating
a brush with a single click (rather than having to confirm text input first).
All UI elements stay interactive with hover feedback, changing asset library
and catalogs is possible, tooltips and context menus can be opened, and any
text input is still sent to the search button.

Normal search popups already keep their search results interactive like this
during text input, but are too limited because they don't use our widget
system. For example custom layouts are not possible with them. With this
feature implemented, we could consider rewriting them to use the widget
system, removing the ad-hoc implementation.

Part of the brush assets project, see:
- https://projects.blender.org/blender/blender/issues/116337
- https://projects.blender.org/blender/blender/pulls/106303

Initially reviewed in:
https://projects.blender.org/blender/blender/pulls/122871
2024-07-08 17:50:24 +02:00
Bastien Montagne
9f90594db7 UI: Support non-C-allocated data for buttons and blocks func_argN data.
This change allows to pass optional freeing and copy callbacks to
functions setting the `func_argN` member of the `uiBut` and `uiBlock`
structs. These callbacks are used to free or duplicate the data stored
in these void pointers.

Defaults are set respectively to `MEM_freeN` and `MEM_dupallocN`, to
match previous hard-coded behavior.

Utils template functions are added to easily generate callbacks to
types that are managed with the `MEM_new`/`MEM_delete` C++-style
allocation, as long as they provide a copy constructor.

Note that this change should be considered as a temporary, transitional
solution. A more robust and future-proof solution is to move towards
more usage of `std::function` for these callbacks, which can then own
and manage their custom data themselves.
2024-07-08 13:54:15 +02:00
Campbell Barton
ebe5860027 Merge branch 'blender-v4.2-release' 2024-07-02 13:34:38 +10:00
Guillermo Venegas
262c68512f Fix #123807: layout panels can't be collapsed on scaled regions
In `ui_popup_block_position` popup blocks are scaled with the owner
button region scale which wasn't being done for layout panel bounds.

This applies the scale applied to the popup block to layout panels
bodies and headers.

Also when calculating layout-panels headers and bodies the offset
`layout_panel_y_offset` is applied in place, this because this value
can also be affected by this scale.

This solves the original issue described in #122411 and reverts the
regression #123807.

Ref !123980
2024-07-02 13:32:18 +10:00
Julian Eisel
e425faf696 Cleanup: Replace term "radial" with "pie menu" in UI code
Code was often referring to pie menus using the term "radial" which just
obfuscates that it relates to pie menus. Just call it what it is
directly.

Doesn't replace usages of the term for names that are not strictly tied
to pie menus. Also doesn't change instances of the term in the Python
API to keep compatibility, noted in #110461.

Pull Request: https://projects.blender.org/blender/blender/pulls/122825
2024-06-06 14:55:23 +02:00
Julian Eisel
2fbf206491 UI: Allow passing named strings via context
Sometimes it is necessary to pass additional data through generic UI entities,
to specific implementations. For example to pass additional options to panel
polling & drawing when instantiating a panel through its panel type. Or storing
additional data in a button, without hardcoding it in the button struct/class.

Passing data via context is a simple solution to this, however so far this only
works using hardcoded context queries or RNA pointers. For passing arbitrary
strings we've used workarounds like creating an RNA type to wrap it already.
For example `RNA_AssetCatalogPath`, which is used to dynamically populate menu
items based on an asset catalog path, via a generic menu type.
type instantiation. This makes it possible to invoke specific asset shelves as
popover panels.

Idea is simply to let `bContextStore` entries hold copies of the string (as
`std::string`), avoiding lifetime issues. Context APIs are extended to support
setting/querying strings via a context member name.

Pull Request: https://projects.blender.org/blender/blender/pulls/122113
2024-05-27 18:46:19 +02:00
Jeroen Bakker
eb20f30e15 Fix: Crash in interface layout when using custom nodes
`node_socket_add_tooltip_in_node_editor` doesn't set a free function.
but uiLayoutSetTooltipFunc didn't check on it. Documentation states
that the free_arg parameter is optional.

Pull Request: https://projects.blender.org/blender/blender/pulls/122115
2024-05-23 08:22:48 +02:00
Harley Acheson
bef05382a0 Fix #121765: Default Separator for Pie Menu Should be UI_BTYPE_SEPR
As described in the report, pie menus can show horizontal lines if they
use separators without explicit type. This just makes them use blank
space by default instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/121839
2024-05-15 20:55:08 +02:00
Campbell Barton
bc5b77b390 Cleanup: rename Context::wm::menu to popup_region
The term "menu" was misleading as this is used for all temporary popups.
2024-05-10 11:27:03 +10:00
Campbell Barton
08b3db500f Cleanup: correct asserts
Also remove redundant assert.
2024-04-25 12:02:14 +10:00
Campbell Barton
01101dcaf9 Cleanup: use const references instead of copy-by-value 2024-04-17 11:36:44 +10:00
Jacques Lucke
d1634b2a4a UI: support adding a search weight to menu entries for menu-search
The goal is to support better search experience in the cases where we want to
explicitly influence the ordering instead of relying only on general heuristics.
We used to support this already at some point I think, but not anymore since we
started using menu-search.

The implementation is fairly straight forward. It mainly just forwards the
search weight from the menu definition to the search code through various
required steps. The main annoying thing is that changing the signature of e.g.
`uiItemFullO_ptr` is fairly involved. Even using default parameters for these
functions is a bit annoying and becomes fairly unreadable and error-prone on the
call-site. For now, I worked around this by storing the search weight on the
`uiLayout` and to copy it to the `uiBut` from there. That seems preferable until
we have a better solution for adding parameters to all the `uiItem*` functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/120572
2024-04-16 12:18:45 +02:00
Campbell Barton
7e5a712e58 Cleanup: remove redundant null pointer checks
Based on the surrounding context these checks aren't needed.
2024-04-01 22:20:09 +11:00
Hans Goudey
0cdd429b44 Cleanup: Use newer API for creating IDProperties in most places
There are still a few places that are more complicated where the replacement
to `IDP_New` isn't obvious, but this commit replaces most uses of the ugly
`IDPropertyTemplate` usage.
2024-03-26 15:39:39 -04:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Campbell Barton
155dae94d7 Cleanup: code-comments, use doxygen formatting & spelling corrections
Also move some function doc-strings from the implementation
to their declarations.
2024-03-26 17:55:20 +11:00
Guillermo Venegas
7fabf0d896 Fix #119778: Crash in popovers that do not support refreshing
When creating popover with `UI_popover_begin` the popover block
is created just once without a region and since `UI_popover_begin` blocks
are not support refreshing, layout panels may not be compatible
in this kind of popover since open/close state cannot be refreshed either.

Only `UILayout.popover(...)` popovers are supported to have layout panels.

Pull Request: https://projects.blender.org/blender/blender/pulls/119796
2024-03-22 17:09:02 +01:00
Campbell Barton
1d9ed41560 Cleanup: minor edits to code-comments 2024-03-22 19:12:27 +11:00
Campbell Barton
02681bd44d UI: support layout panels in popovers
Make use of UI_popup_dummy_panel_set so layout panels can be used.
2024-03-22 17:36:45 +11:00
Campbell Barton
cb4351665a Cleanup: format, trailing space 2024-03-08 11:31:01 +11:00
Hans Goudey
744f3b2823 Cleanup: Grammar in comments: Fix uses of "own"
"Own" (the adjective) cannot be used on its own. It should be combined
with something like "its own", "our own",  "her own", or "the object's own".
It also isn't used separately to mean something like "separate".

Also, "its own" is correct instead of "it's own" which is a misues of the verb.
2024-03-07 16:23:35 -05:00
Harley Acheson
7e8baea394 Revert #119181: Popover Button Padding for Arrow
Reverting aa328e898e as this causes unintended changes elsewhere. Even
if made more conservative with just allowing UI_LAYOUT_PANEL and
force_menu.  Will need further investigation for a better solution.

Pull Request: https://projects.blender.org/blender/blender/pulls/119187
2024-03-07 22:22:31 +01:00
Harley Acheson
aa328e898e UI: Popover Button Padding for Arrow
Currently UI_BTYPE_POPOVER with icon and without text will get enough
extra padding to fit a downward arrow, only if in a header region. This
PR allows it to get the same padding in other areas when "force_menu"
is true.

Pull Request: https://projects.blender.org/blender/blender/pulls/119181
2024-03-07 22:01:56 +01:00
Hans Goudey
ce80cc1526 Cleanup: Remove unused UI button creation function
Last used over 11 years ago apparently.
2024-03-04 12:22:50 -05:00
Hans Goudey
aab9ecc396 Cleanup: Remove very old hack to fix linking in interface module
Pull Request: https://projects.blender.org/blender/blender/pulls/118988
2024-03-01 23:47:18 +01:00
Hans Goudey
d29ce3d531 UI: Remove uiBut a1 and a2 values
Over the last couple years (!) UI buttons have moved to derived classes,
meaning we don't need to use the same "a1" and "a2" variables to store
different information. At this point, that information is set specifically
by internal UI code, or functions like `UI_but_*_set`.

These values are only set to their default 0 values now (or -1 in some
non-meaningful cases). This commit removes the values from buttons
and removes the remaining a1 and a2 arguments from the UI API.
2024-03-01 14:27:57 -05:00
Harley Acheson
5e669d99d7 Refactor: UI_BTYPE_SEPR_LINE Without Need for uiBut->a1
The line separator needs to know vertical or horizontal orientation
at draw time, and is independent of button rect. This PR removes the
use of uiBut->a1 for this in favor of a derived struct.

Pull Request: https://projects.blender.org/blender/blender/pulls/118969
2024-03-01 18:09:02 +01:00
Hans Goudey
121ded625f Cleanup: Remove unnecessary a1 and a2 arguments for some UI functions 2024-02-29 22:39:37 -05:00
Campbell Barton
c32747319b UI: support UI_ITEM_R_IMMEDIATE all RNA buttons
This was only being checked for key-map entry buttons however this is
useful to enable immediate editing of text fields.
2024-02-23 14:58:08 +11:00
Campbell Barton
b372ebae68 Cleanup: unused headers for source/blender/editors
Remove 1317 includes from editors.
2024-02-13 10:02:53 +11:00
Harley Acheson
3ac9babe35 Fix #118087: Remove Bad Spacing Introduced With #117310
This reverts to the exact prior spacing values for layout separator
item, so only difference is vertical spacing if vertical bar.

Pull Request: https://projects.blender.org/blender/blender/pulls/118151
2024-02-12 19:10:48 +01:00
Bastien Montagne
54618dbae3 Cleanup: Make BKE_global.h a Cpp header. 2024-02-10 18:25:14 +01:00
Bastien Montagne
45e7827898 Clenup: Move BLT headers to Cpp.
Noisy but fairly straight forward.
2024-02-09 18:59:42 +01:00
Harley Acheson
4c50e6992f UI: Configurable Layout Separators
Ability to create vertical bar separators in horizontal layouts,
horizontal lines in popovers, and vertical (non-line) spacers in menus.

Pull Request: https://projects.blender.org/blender/blender/pulls/117310
2024-02-09 17:38:36 +01:00
Hans Goudey
fbf47b9a12 Refactor: Use std::string for keymap string return values
The main simplification is using return values rather than return
arguments, and the additional semantic clarity from std::optional.
Also use `fmt` for formatting and use lambdas instead of macros
as helpers in a few modal keymap formatting functions.

Similar commits:
- a1792e98a4
- f04bc75f8c
- 6abf43cef5
- 7ca4dcac5a

Pull Request: https://projects.blender.org/blender/blender/pulls/117785
2024-02-07 14:22:54 +01:00
Hans Goudey
df8c85d3f9 Cleanup: UI Remove more unnecessary a1 and a2 parameters
Similar to 5155feeeb8. These had values without any meeting,
almost completely just 0 or -1 (which meant "find good values if possible"
anyway).
2024-02-05 14:38:11 -05:00
Hans Goudey
cfc68a1247 Fix #117813: Precision ignored for some slider buttons 2024-02-05 12:26:00 -05:00
Hans Goudey
945dc7c863 Cleanup: Use references and const in interface_layout.cc 2024-02-05 12:26:00 -05:00
Hans Goudey
809499a3d0 Refactor: UI: Use derived struct for number slider buttons
Similar to d204830107. This is the last real use of
the a1 and a2 arguments for many button definition functions.
2024-02-01 13:08:50 -05:00
Philipp Oeser
33fc594da1 Fix #117679: operator_menu_enum crashes for an unfound property
Caused by d6a6c3e1fc.

Code from d6a6c3e1fc was trying to get enum items for a property even if
the property itself was not found.

Now return early here (same as to how an early return happens if the
operator was not found).

Pull Request: https://projects.blender.org/blender/blender/pulls/117691
2024-02-01 01:50:55 +01:00
Jacques Lucke
f358843108 UI: simplify layout panels C++ API
This simplifies the C++ API for making layout panels. Now it is also more similar to the Python API.
`uiLayoutPanel` is like `layout.panel` and `uiLayoutPanelProp` is like `layout.panel_prop`.

Both, `uiLayoutPanel` and `uiLayoutPanelProp`, now exist in two variants. One that takes a label
parameter and one that does not. If the label is passed in, only the panel body layout is returned.
Otherwise, the header and body are returned for more customization.

Pull Request: https://projects.blender.org/blender/blender/pulls/117670
2024-01-30 17:44:56 +01:00
Hans Goudey
61fb2b17c8 Cleanup: Use std::string for WM API function return values 2024-01-29 16:33:49 -05:00
Hans Goudey
13d280b8d8 Cleanup: Rename function to ensure button operator properties
For some reason the "get" function actually allocates the button's
operator properties container. This may or may not make sense to
do, but while it happens, the function name might as well make
that clear.
2024-01-29 16:33:12 -05:00
Harley Acheson
28366f624f UI: Operator Confirm Dialog Changes
Removal of "confirm" operator callback for confirmation customization,
in favor of new method that shares existing operator dialog code and
allows python configuration.

Pull Request: https://projects.blender.org/blender/blender/pulls/117564
2024-01-29 18:52:18 +01:00
Jesse Yurkovich
ddd06eeb8f UI: Add ability to configure the header row of layout panels
There are many instances where customizing the header row is desired so
return both the header row layout and the main body layout.

For consistency and correctness, the arrow symbol and the is_open check
are always performed so callers only need to perform layout tasks.

The C++ side now receives a `PanelLayout` structure containing both:
```cpp
PanelLayout panel_layout = uiLayoutPanelWithHeader( ... );
uiItemL(panel_layout.header, ... );
if (panel_layout.body) {
    ...
}
```

And the Python side receives a tuple:
```python
header, body = layout.panel( ... )
header.label(...)
if body:
    ...
```

```python
import bpy
from bpy.props import BoolProperty

class LayoutDemoPanel(bpy.types.Panel):
    bl_label = "Layout Panel Demo"
    bl_idname = "SCENE_PT_layout_panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        layout.label(text="Basic Panels")

        header, panel = layout.panel("my_panel_id", default_closed=True)
        header.label(text="Hello World")
        if panel:
            panel.label(text="Success")

        header, panel = layout.panel_prop(scene, "show_demo_panel")
        header.label(text="My Panel")
        if panel:
            panel.prop(scene, "frame_start")
            panel.prop(scene, "frame_end")

        layout.label(text="Customized headers")

        # Add a checkbox to the Panel header. text must be None for this panel
        header, panel = layout.panel("my_panel_id-2", default_closed=True)
        header.prop(scene, "use_checkmark", text="") # text must be empty for the checkbox
        header.label(text="Checkmark at beginning")
        if panel:
            panel.label(text="Success")

        header, panel = layout.panel("my_panel_id-3", default_closed=True)
        header.label(text="Buttons at the end")
        header.operator("mesh.primitive_cube_add", text="", icon='EXPORT')
        header.operator("mesh.primitive_cube_add", text="", icon='X')
        if panel:
            panel.label(text="Success")

        header, panel = layout.panel("my_panel_id-4", default_closed=True)
        header.prop(scene, "use_checkmark2", text="")
        header.label(text="Both")
        header.operator("mesh.primitive_cube_add", text="", icon='EXPORT')
        header.operator("mesh.primitive_cube_add", text="", icon='X')
        if panel:
            panel.label(text="Success")

bpy.utils.register_class(LayoutDemoPanel)
bpy.types.Scene.show_demo_panel = BoolProperty(default=False)
bpy.types.Scene.use_checkmark = BoolProperty(default=False)
bpy.types.Scene.use_checkmark2 = BoolProperty(default=False)
```

Pull Request: https://projects.blender.org/blender/blender/pulls/117248
2024-01-26 10:11:22 +01:00
Bastien Montagne
03e0de14c5 Fix (unreported) wrong logic in reports about unknown operators.
This (likely copy-pasted) check to report either an unknown operator
type, or a known operator type missing its RNA struct definition, had a
reversed logic. It would report a 'missing srna' for unknown operator,
and vice-versa.
2024-01-24 21:02:27 +01:00
Hans Goudey
089c389b5c Cleanup: Store UI button drawstr with std::string
Similar to bff51ae66c
2024-01-22 14:54:44 -05:00