Commit Graph

289 Commits

Author SHA1 Message Date
Julian Eisel
4499fad40e UI: Horizontal list view for asset browser
Part of #134755 / #134766.

The asset browser currently lacks a compact view that leaves names
readable. Especially when managing asset libraries (e.g. to prepare it
for sharing or set up a production library), this is quite a usability
issue. A column view like the file browser has can solve this, allowing
a quick overview and fast browsing of libraries, while keeping names
readable.

Adds a new "Horizontal List" display mode to the asset browser that
distributes assets over multiple columns, with horizontal scrolling.
Asset previews are shown in this mode, plus an asset type icon if
there's enough space. The size of previews and the columns can be
configured next to the display mode, for optimizing the display.

Pull Request: https://projects.blender.org/blender/blender/pulls/135306
2025-03-14 16:43:12 +01:00
Sebastian Parborg
ec29eb6580 Refactor: Make it more obvious that wm_event_add is not a static function
By renaming it to WM_ follow the other public functions.
2025-03-11 14:39:18 +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
Harley Acheson
67ffad53aa Merge branch 'blender-v4.4-release' 2025-02-24 18:51:52 -08:00
Harley Acheson
130c074487 Fix #131779: Display "inf" / "-inf" for Correct Range of UI Values
Our UI code is currently showing the text "inf" when a numerical input
contains _exactly_ the value of FLT_MAX. But this is the max value for
doubles and we enforce a maximum float precision of 6 digits.  This
means that a property can start with "inf" by default but it is
impossible edit, or even keep the same value, by editing in the UI
and show as "inf".  This PR defines values that are the actual minimum
and maximums currently usable in the UI and values greater than or
equal to are shown as "inf" (equivalent for "-inf").

Pull Request: https://projects.blender.org/blender/blender/pulls/131876
2025-02-25 03:50:23 +01:00
Julian Eisel
73ff81db8a Merge branch 'blender-v4.4-release' 2025-02-18 16:09:55 +01:00
Julian Eisel
2e28865ece Fix (unreported): Mismatching MEM_new/MEM_freeN on button handling data
New version of b22670d927 (which was reverted with 9d33dd88d5).

I rather keep `uiHandleButtonData` private to the handling code. It
does the allocation as part of its implementation details, so it should
also handle freeing.
2025-02-18 15:57:38 +01:00
Bastien Montagne
6c1b231310 Merge branch 'blender-v4.4-release' 2025-02-18 15:47:27 +01:00
Bastien Montagne
9d33dd88d5 Revert "Fix (unreported) invalid mismatch MEM_new/MEM_freeN on but->active."
This reverts commit b22670d927.
2025-02-18 15:39:18 +01:00
Bastien Montagne
37ecf6d03f Merge branch 'blender-v4.4-release' 2025-02-18 15:12:45 +01:00
Bastien Montagne
b22670d927 Fix (unreported) invalid mismatch MEM_new/MEM_freeN on but->active.
Found by @brecht while reviewing !134463.
2025-02-18 15:10:39 +01:00
Harley Acheson
c3a2af00be Merge branch 'blender-v4.4-release' 2025-02-17 20:27:18 -08:00
Harley Acheson
9aeb97ccea Cleanup: Improved Comments in ui_def_but_rna__menu
Nothing but improvements to comments in this area of code to better
explain the complexity of Emum list row and column calculation. These
things change wrapping and column count to suit available space and
needs better explanation.

Pull Request: https://projects.blender.org/blender/blender/pulls/134719
2025-02-18 05:26:12 +01:00
Harley Acheson
f1514b45e3 Merge branch 'blender-v4.4-release' 2025-02-17 18:13:17 -08:00
Harley Acheson
b39bb42b3a Fix #134271: Reflow Non-Categorized Enum Lists Only If Necessary
For non-categorized lists, rather than always trying to find optimal
rows and columns, revert to prior behavior and only reflow if needed,
when the calculated rows are greater than maximum rows. This is less
disruptive, has less changes at small sizes where this doesn't matter.
Yet still does the job when things get too large to fit, or the list
is very long.

Pull Request: https://projects.blender.org/blender/blender/pulls/134713
2025-02-18 03:12:10 +01:00
Guillermo Venegas
f2b6b6c232 UI: Prevent button vector reallocations on redraws
A bunch of reallocations can be avoided this way, usually the amount of buttons
is quite similar over redraws.

Pull Request: https://projects.blender.org/blender/blender/pulls/134580
2025-02-17 16:03:45 +01:00
Campbell Barton
69e63d190d Cleanup: use "at_most" RNA array access functions for simplicity 2025-02-16 18:39:35 +11: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
Harley Acheson
c1866764b0 Merge branch 'blender-v4.4-release' 2025-02-14 09:42:48 -08:00
Harley Acheson
99d028cd7d Fix #134492: Do Not Assign Toggle Accelerators on First Pass
With ba9417470e we are assigning keyboard accelerator shortcuts to
menu items containing toggles. This PR makes the assignment to these
new items not occur on the first pass of doing so. This is less
disruptive in that first-letter shortcuts will remain the same from
prior versions, with only mid-word shortcuts possibly changing.

Pull Request: https://projects.blender.org/blender/blender/pulls/134526
2025-02-14 18:41:33 +01: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
Hans Goudey
4f833b0b5f Refactor: Add StringRef overloads to translation functions
Currently UI code always has to use char pointers when interacting with
the translation system. This makes benefiting from the use C++ strings
and StringRef more difficult. That means we're leaving some type safety
and performance on the table. This PR adds StringRef overloads to the
translation API functions and removes the few calls to `.c_str()` that
are now unnecessary.

Pull Request: https://projects.blender.org/blender/blender/pulls/133887
2025-02-06 17:47:52 +01:00
Hans Goudey
d216476458 Cleanup: Use StringRef for UI search menu code
Also use Vector to store menu search items instead of a linked
list. And extend the change into the autocomplete API slightly.
The main benefit is to avoid measuring the length of strings over
and over, but the code also gets simpler.
2025-02-05 18:27:44 -05:00
Campbell Barton
4ed5776990 Cleanup: avoid double precision loss when converting to/from floats 2025-02-05 14:38:56 +11: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
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
Harley Acheson
ba9417470e Fix #126409: Allow Menu Accelerators for Toggles
When menus (that are not type-to-search) open we add underlines to
most items so they can be selected quickly. We currently don't do this
for items that are toggles.  This PR adds accelerators to toggles.

Pull Request: https://projects.blender.org/blender/blender/pulls/132309
2025-01-13 19:14:12 +01:00
Harley Acheson
fe071cd076 Fix #124814: Correctly Collapse Long Non-Categorized Lists
Multi-column lists are supposed to collapse to single-column when they
are estimated to be wider than the available window width. However,
current code has two errors. First the calculation of the maximum
number of possible rows is based on entire screen height when the most
available is a bit less than half. This too-large value was used in
the calculation of widths, yet the maximum rows is actually clamped
to about 24 for uncategorized lists. Whenever the former is greater
than the latter this could cause collapsing to not occur. This issue is
only really noticeable for lists in Nodes as these can be shown much
smaller than regular size.  This PR fixes the max-row calculation and
uses this correctly when breaking lists without categories.

Pull Request: https://projects.blender.org/blender/blender/pulls/132881
2025-01-10 00:56:33 +01:00
Campbell Barton
7e8dcf77db Cleanup: pass UnitSettings as a const reference 2025-01-08 21:22:45 +11:00
Campbell Barton
361e98b09e Cleanup: move BKE_scene_unit_scale to BKE_unit_value_scale
This doesn't use any scene types, move to BKE_unit.hh
2025-01-08 21:03:50 +11:00
Julian Eisel
11b006e01a UI: Don't spawn asset shelf popup by hovering button
Papercut reported in #132293.

Allow explicitly disabling this behavior for a button, and do so for the
big preview asset shelf popup button. It gets more in the way than it's
useful in this case.
2025-01-06 17:42:29 +01:00
Harley Acheson
9ed7b03e35 Fix #100652: Correct Shortcut Hovering Editor Type Button
When hovering over the "Editor Type" button it always shows Shift-F1 as
the shortcut no matter what the current Editor Type is. We already have
specific code for "SCREEN_OT_space_type_set_or_cycle" for the items on
the popup menu, but it doesn't handle the case of hovering the menu
itself. This adds just adds a line to handle this.

Pull Request: https://projects.blender.org/blender/blender/pulls/132612
2025-01-04 00:58:20 +01:00
Jacques Lucke
0e28920bd8 BLI: change default hash-table clear behavior
Previously, calling `clear()` on `Map`, `Set` or `VectorSet` would remove all
elements but did not free the already allocated capacity. This is fine in most
cases, but has very bad and non-obvious worst-case behavior as can be seen in
#131793. The issue is that having a huge hash table with only very few elements
is inefficient when having to iterate over it (e.g. when clearing).

There used to be a `clear_and_shrink()` method to avoid this worst-case
behavior. However, it's not obvious that this should be used to improve
performance.

This patch changes the behavior of `clear` to what `clear_and_shrink` did before
to avoid accidentally running in worst-case behavior. The old behavior is still
available with the name `clear_and_keep_capacity`. This is more efficient if
it's known that the hash-table is filled with approximately the same number of
elements or more again.

The main annoying aspect from an API perspective is that for `Vector`, the
default behavior of `clear` is and should stay to not free the memory. `Vector`
does not have the same worst-case behavior when there is a lot of unused
capacity (besides taking up memory), because the extra memory is never looked
at. `std::vector::clear` also does not free the memory, so that's the expected
behavior. While this patch introduces an inconsistency between `Vector` and
`Map/Set/VectorSet` with regards to freeing memory, it makes them more
consistent in that `clear` is the better default when reusing the data-structure
repeatedly.

I went over existing uses of `clear` to see if any of them should be changed to
`clear_and_keep_capacity`. None of them seemed to really benefit from that or
showed that it was impossible to get into the worst-case scenario. Therefore,
this patch slightly changes the behavior of these calls (only performance wise,
semantics are exactly the same).

Pull Request: https://projects.blender.org/blender/blender/pulls/131852
2024-12-17 13:35:07 +01:00
Pratik Borhade
3dfb7830a6 Fix #131705: Crash when ui created with prop_with_menu
button created from python (`ui_def_but_rna`) does not seem to assign
free/copy callbacks to the menu with rnaprop. So instead of an assert
check, assign callback functions in `ui_but_rna_menu_convert_to_menu_type`.

Pull Request: https://projects.blender.org/blender/blender/pulls/131719
2024-12-13 11:19:13 +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
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
Harley Acheson
7c3db55b29 Refactor: Simplify Block Re-centering
PR #129125 allowed the movement of centered dialogs, like About and
Splash, without them snapping back to their original positions. But
that change was more complex than necessary. This returns
interface_region_popup.cc to exactly as it was before any of this, and
interface.cc gets simpler too. In a nutshell recentering these dialogs
is a lot easier that seemed at first.

Pull Request: https://projects.blender.org/blender/blender/pulls/131464
2024-12-06 00:57:32 +01:00
Harley Acheson
154ab16ee2 Fix #128419: Allow the Positioning of Centered Dialogs
Some popups are positioned centered in the window, like "Splash",
"About", and the large confirmations. But when you drag these to
a different location they will snap back when there is any window
interaction.  This PR allows you to move these popups and they will
stay in the new location.

Pull Request: https://projects.blender.org/blender/blender/pulls/129125
2024-12-02 22:01:05 +01:00
Hans Goudey
2b20871216 Cleanup: Move region UI block name map from GHash to Map 2024-11-21 14:04:34 -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
Julian Eisel
f0db870822 UI: Support persistent view state, write tree-view height to files
Adds support for saving some view state persistently and uses this to keep the
height of a tree-view, even as the region containing it is hidden, or the file
re-loaded.

Fixes #129058.

Basically the design is to have state stored in the region, so it can be saved
to files. Views types (tree-view, grid-view, etc) can decide themselves if they
have state to be preserved, and what state that is. If a view wants to preserve
state, it's stored in a list inside the region, identified by the view's idname.

Limitation is that multiple instances of the same view would share these bits of
state, in practice I don't think that's ever an issue.

More state can be added to be preserved as needed. Since different kinds of
views may require different state, I was thinking we could add ID properties to
`uiViewState` even, making it much more dynamic.

Pull Request: https://projects.blender.org/blender/blender/pulls/130292
2024-11-18 18:19:48 +01:00
Hans Goudey
091c175c5c Refactor: Move region runtime to separate C++ runtime struct
This allows using C++ types in the region runtime data, which will
make it easier to move the remaining runtime data out of the
`ARegion` DNA type and improve code readability in these areas.

Pull Request: https://projects.blender.org/blender/blender/pulls/130196
2024-11-15 02:00:11 +01:00
Hans Goudey
6c3ac28eb3 Nodes: Slightly improve editor drawing performance with large node trees
Avoid retrieving context data for every single node which can be
expensive when there are thousands of nodes. In the "Mouse House"
test file I observed a 13% improvement in drawing timings.

Pull Request: https://projects.blender.org/blender/blender/pulls/130239
2024-11-14 16:04:33 +01:00
Julian Eisel
68a74c4095 Merge branch 'blender-v4.3-release' 2024-11-01 15:34:39 +01:00
Julian Eisel
a641001207 Fix: UI previews don't refresh outside of properties editor
The preview template (`UILayout.template_preview()`) to display previews
for materials, textures or similar would only work correctly in the
Properties editor. This had explicit logic to trigger rerendering on
changes. When displaying such previews elsewhere (e.g. in the 3D View
sidebar), the only way to have changes reflected would be by resizing
the preview.

This fix makes sure such previews are tagged as dirty and refreshed on
changes to the underlying ID. We do this the same way as tagging the ID
previews as dirty, through a function called by the dependency graph for
such updates.

Pull Request: https://projects.blender.org/blender/blender/pulls/129641
2024-11-01 15:25:24 +01:00
Campbell Barton
64027cd178 Merge branch 'blender-v4.3-release' 2024-10-21 22:00:40 +11:00
Campbell Barton
c836c0a20e Fix #129151: Crash showing tool-tips from dynamic enums
Duplicate descriptions for dynamic enum menu items to resolve
use-after-free error.
based on !129008.

Ref !129164

Co-authored-by: Julian Eisel <julian@blender.org>
2024-10-21 21:59:13 +11:00
Pratik Borhade
9e6c884394 Fix #122206: Int soft limits changed to 10000
When soft limits set to extreme int values, the softmin/max of custom
property changes to -10k/10k. Instead use extreme values.

Pull Request: https://projects.blender.org/blender/blender/pulls/123223
2024-10-09 14:05:36 +02:00
Campbell Barton
4fa3dc0dd4 Cleanup: spelling in comments, use uppercase tags 2024-10-03 12:11:52 +10:00