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
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
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).
- 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
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
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
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.
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).
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
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
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
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
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
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
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
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
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.
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
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
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
`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
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
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
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.
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