Commit Graph

174 Commits

Author SHA1 Message Date
Philipp Oeser
711772de88 Merge branch 'blender-v4.4-release' 2025-03-07 17:59:33 +01:00
Philipp Oeser
a568890515 Fix #135601: prop_tabs_enum No Longer Displays Text of Enum
Caused by 21aef81714

Now, pass along `uiname` as `std::optional<StringRef>` early on (and use
`std::nullopt`).

Without this, the `(!uiname || !uiname->is_empty())` condition in
`ui_item_enum_expand_elem_exec` wont be true, resulting in the empty
label.

Pull Request: https://projects.blender.org/blender/blender/pulls/135621
2025-03-07 17:53:54 +01:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
Hans Goudey
c560cdc8cc Cleanup: Use StringRef for layout panel API functions 2025-03-04 14:29:15 -05:00
Jacques Lucke
53d8390c1b Cleanup: remove redundant layout panel function
While using the other function is a little more verbose, it's also more
explicit and having two functions this similar is confusing.
2025-02-28 19:33:07 +01:00
Falk David
2822777f13 Nodes: support boolean inputs as toggles in panel headers
Adds the option to create a boolean socket that can be used as a panel toggle.
This allows creating simpler and more compact node group UIs when a panel
can be "disabled".

The toggle input is a normal input socket that is just drawn a bit differently in
the UI. Whether a boolean is a toggle input or not does not affect evaluation.

Also see #133936 for guides on how to add and remove panel toggles.

Pull Request: https://projects.blender.org/blender/blender/pulls/133936
2025-02-28 19:07:02 +01:00
Campbell Barton
69e63d190d Cleanup: use "at_most" RNA array access functions for simplicity 2025-02-16 18:39:35 +11:00
Harley Acheson
beaaa428e9 UI: Tightened Status Bar Spacing
Slight adjustments to the spacing of items on the Status Bar. Mainly
to reduce the distance between adjoining icons. Small decrease in space
between icon and text. Slight decrease in text size inside the event
icons. Proportionally wider gap between items.

Pull Request: https://projects.blender.org/blender/blender/pulls/134534
2025-02-15 00:57:49 +01:00
Hans Goudey
568c791e22 Cleanup: Use StringRef for uiBut tooltips
And replace nullptr arguments for tooltips in UI button
creation functions with std::nullopt. Though the distinction
between "no tooltip" and "empty tooltip" doesn't seem to exist,
it seems safer to keep the distinction since it existed with null before.
2025-02-14 15:12:48 -05:00
Guillermo Venegas
7682258ff9 Refactor: UI: Use a Vector to store buttons in UI blocks
This changes the ui-blocks buttons storage from Listbase to Vector.

Major changes that might cause a performance considerations are
in `ui_but_update_from_old_block` that requires to track buttons when restoring
button state between block redraws or in  `uiItemFullR` that may needs to insert
uiButs in the middle of the vector to add decorators. This might not be as fast as
removing or inserting elements in the middle of a listbase container. Also buttons currently
don't know its position in the container, so to get the previous and next
button its required to make a lookup of the button in the container.

`UI_block_update_from_old> ui_but_update_from_old_block` restores the state
of buttons between frames, this is done by sequentially testing if a button is the
same as an old button, however since UI can be created procedurally some old buttons
may not be drawn while editing other button data, this requires an extra track of what
buttons may not match to a new button while comparing for restoring state, but still
this buttons may be candidates to match to an new button.

Not functional changes expected.
Ref: #117604

Co-authored-by: Julian Eisel <julian@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/127128
2025-02-14 15:29:26 +01:00
Harley Acheson
497f2884e8 UI: Decrease Alert Dialog Icon Size
Decrease the size of the icons shown on the large dialogs and
confirmations from 64 pixels (at 1X resolution scale) to 40.

Pull Request: https://projects.blender.org/blender/blender/pulls/134302
2025-02-12 18:30:52 +01:00
Hans Goudey
73b25ba12e Cleanup: Use StringRef for some WM and UI APIs
Instead of const char * or StringRefNull.

Pull Request: https://projects.blender.org/blender/blender/pulls/134004
2025-02-04 13:53:30 +01:00
Brecht Van Lommel
3725fad82f Cleanup: Various clang-tidy warnings in editors
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Hans Goudey
ca64f2f7e7 Cleanup: Use StringRef instead of StringRefNull 2025-01-29 12:49:41 -05:00
Jacques Lucke
e1753900b7 BLI: improve UTF-8 safety when copying StringRef to char buffers
Previously, there was a `StringRef.copy` method which would copy the string into
the given buffer. However, it was not defined for the case when the buffer was
too small. It moved the responsibility of making sure the buffer is large enough
to the caller.

Unfortunately, in practice that easily hides bugs in builds without asserts
which don't come up in testing much. Now, the method is replaced with
`StringRef.copy_utf8_truncated` which has much more well defined semantics and
also makes sure that the string remains valid utf-8.

This also renames `unsafe_copy` to `copy_unsafe` to make the naming more similar
to `copy_utf8_truncated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133677
2025-01-29 12:12:27 +01:00
Bastien Montagne
9c237af041 Refactor: RNA: add discrete suffix to RNA_pointer_create.
This is a noisy preliminary step to the 'RNA ancestors' change. The
rename helps clearly tell what each `pointer_create` function does.

Pull Request: https://projects.blender.org/blender/blender/pulls/133475
2025-01-24 16:45:32 +01:00
Hans Goudey
c6f5c44350 Cleanup: Remove unused includes in editors modules
Pull Request: https://projects.blender.org/blender/blender/pulls/133166
2025-01-16 23:17:51 +01:00
Pratik Borhade
eb57878bec Grease Pencil: Support Boolean property in modifier panel header
A separate function is declared/defined `uiLayoutPanelPropWithBoolHeader`,
it will add a boolean property to the panel.header.
Clear decorate and separator flag, otherwise they will offset the panel
header horizontally and also adds animate decorator on the right side.

Resolves #131623.

Pull Request: https://projects.blender.org/blender/blender/pulls/132726
2025-01-10 14:51:19 +01:00
Julian Eisel
f6a4d01703 UI: Allow passing named integers via context
Similar to 2fbf206491, but for integers (not strings). Essentially this
allows passing named integer values through UI abstractions in a clean
way.

I used 64 bit integers here, since space isn't an issue here, and it
fits common integer types (so we don't have to add APIs for multiple
integer types).

Planned to be used to fix #111463 (following commit).
2024-12-11 13:39:24 +01:00
Campbell Barton
083b690fb5 Cleanup: spelling in comments 2024-12-09 09:14:44 +11:00
Hans Goudey
7a8a58e7e5 Cleanup: Remove unused UI layout function 2024-12-06 14:48:28 -05:00
Hans Goudey
b7a056b839 Cleanup: Use StringRefNull instead of const char * in one case 2024-12-06 14:44:40 -05:00
Hans Goudey
4d3664fc43 Cleanup: Remove accidentally included debug print 2024-12-06 08:16:14 -05:00
Hans Goudey
21aef81714 Cleanup: Use StringRef and std::optional for UI string arguments
- Gives O(1) access to string length in more cases
- Convenient string manipulation functions
- Clarify difference between "no string" and "empty string"
- Avoid the need for raw pointers in the API
- Shows which API string arguments are optional

Pull Request: https://projects.blender.org/blender/blender/pulls/131473
2024-12-06 14:08:10 +01:00
Hans Goudey
efb808bffd Cleanup: Remove unused function
Missing change from f7089519e0.
2024-12-05 21:47:28 -05:00
Hans Goudey
129a2aa0f4 Refactor: Move region runtime data out of DNA
Pull Request: https://projects.blender.org/blender/blender/pulls/130303
2024-11-21 19:34:53 +01:00
Bastien Montagne
406e93525f Fix #130535: Name of Object not updated in viewport when name clashes.
Now that another ID can be renamed (again), it also needs to be properly
tagged as needing resync in the depsgraph too.

This commit:
* Moves/add depsgraph tagging to `BKE_id_rename`.
* Moves the WM notifier creation to `ED_id_rename`.

Pull Request: https://projects.blender.org/blender/blender/pulls/130596
2024-11-20 15:24:46 +01:00
Bastien Montagne
39d4d06f4f Refactor: Move PointerRNA and related users to C++-style new/free. 2024-10-08 12:14:03 +02:00
Campbell Barton
0d8149d4ff Cleanup: various non-functional changes
- Use const pointers.
- Avoid shadowing variables.
- Remove redundant check.
2024-09-21 23:01:59 +10:00
Bastien Montagne
3e03576b09 Add more control over ID renaming behavior.
This commit adds low-level logic in BKE to support three behaviors in
case of name conflict when renaming an ID:
1. Always tweak new name of the renamed ID (never modify the other ID
  name).
2. Always set requested name in renamed ID, modifying as needed the
  other ID name.
3. Only modify the other ID name if it shares the same root name with the
  current renamed ID's name.

It also adds quite some changes to IDTemplate, Outliner code, and
RNA-defined UILayout code, and the lower-level UI button API, to allow
for the new behavior defined in the design (i.e. option three from above list).

When renaming from the UI either 'fails' (falls back to adjusted name) or forces
renaming another ID, an INFO report is displayed.

This commit also fixes several issues in existing code, especially
regarding undo handling in rename operations (which could lead to saving
the wrong name in undo step, and/or over-generating undo steps).

API wise, the bahavior when directly assigning a name to the `ID.name`
property remains unchanged (option one from the list above). But a new
API call `ID.rename` has been added, which offers all three behaviors.

Unittests were added to cover the new implemented behaviors (both at
BKE level, and the RNA/Py API).

This commit implements #119139 design.

Pull Request: https://projects.blender.org/blender/blender/pulls/126996
2024-09-20 13:36:50 +02:00
Julian Eisel
439d4dfc3c Fix: UI: Small layout glitch with search template and decorators
Button layout wouldn't be entirely correct with split layout was
enabled, but decorators disabled (`uiLayout.use_property_split = True`,
`uiLayout.use_property_decorate = False`).

See https://projects.blender.org/blender/blender/pulls/127751#issuecomment-1298468.
2024-09-20 13:06:21 +02:00
Julian Eisel
7d97f99dfc Refactor: UI: Avoid confusing layout property split return value
The function would return two very different layouts in different code
paths, making it not clear to the caller what to expect. For one code
path the return value was rather useless, and in fact unused, so I was
able to just remove this. Also clarified behavior and return values in
the function API comment.
2024-09-20 12:33:56 +02:00
Bastien Montagne
810f6a1b5c Refactor: Various remaining changes to PointerRNA usages to use C++ code.
This commit mainly replaces a lot of `memset(0)` by empty value
initialization of `PointerRNA` and related data.

It also moves a few remaining areas from C alloc/free to C++ new/delete
memory hanlding.

Part of the effort to make PointerRNA non-trivial (#122431).
2024-09-02 17:40:03 +02:00
Bastien Montagne
0ade063f33 Refactor: Move KeyMaps and Operators PointerRNA storage to C++ allocations.
This commit essentially moves allocation of KeyMaps and Operators
PointerRNA data storage to use C++ new/delet, instead of C alloc/free.

Part of the effort to make PointerRNA non-trivial (#122431).

Pull Request: https://projects.blender.org/blender/blender/pulls/126935
2024-08-30 20:44:00 +02:00
Bastien Montagne
733ed5dc83 Refactor: Move some UI-related allocations to use C++ new/delete.
Mainly changes some UI-internal structs allocation, and the Panel
runtime custom data storage.

These changes from C-style alloc/free to C++ new/delete are a step
towards making PointerRNA non-trivial (part of #122431).

Pull Request: https://projects.blender.org/blender/blender/pulls/126698
2024-08-27 15:35:18 +02:00
Leon Schittek
d30d8b4bfa UI: Add padding to items in ui lists and tree views
Add a utility function to add horizontal padding to the left and right
of items in UI lists and tree views to make them more consistent with
other buttons like menu entries.

Pull Request: https://projects.blender.org/blender/blender/pulls/125498
2024-07-29 23:52:38 +02:00
Campbell Barton
62afbbef9b Cleanup: use const variables & args, pass args by reference 2024-07-25 10:17:40 +10:00
Harley Acheson
108b71047a UI: Remove "Widget Label" Text Style
This PR removes the "Widget Label" text style, found in Preferences /
Themes / Text Style. This results in both labels and the text found in
input boxes sharing settings. This results in a slight loss of
customization but it isn't that useful to have these things separate
and results in code complication and errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/122898
2024-07-19 21:57:49 +02:00
Bastien Montagne
c607ead4b7 Refactor: Makesrna: move generated code further in C++.
This commit moves generated `RNA_blender.h`, `RNA_prototype.h` and
`RNA_blender_cpp.h` headers to become C++ header files.

It also removes the now useless `RNA_EXTERN_C` defines, and just
directly use the `extern` keyword. We do not need anymore `extern "C"`
declarations here.

Pull Request: https://projects.blender.org/blender/blender/pulls/124469
2024-07-15 16:39:45 +02:00
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