Commit Graph

164 Commits

Author SHA1 Message Date
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
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