Commit Graph

167 Commits

Author SHA1 Message Date
Harley Acheson
b503a37808 Merge branch 'blender-v4.1-release' 2024-02-07 12:20:48 -08:00
Harley Acheson
b6091f134c Fix #117956: Revert Last Chance Placeholder Default
As #117956 shows, guessing default placeholder text based on the
property UI name can have bad consequence. Best to leave this out and
just set custom placeholder when needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/117962
2024-02-07 21:19:28 +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
266230dd88 Refactor: UI: Pass StringRef to more button definition functions
Similar to 9c3aa8b824. This time there is one null argument
that has to be changed. It was simple to just move the logic to that one
caller.
2024-02-01 14:40:40 -05:00
Hans Goudey
5155feeeb8 Cleanup: UI: Remove a1 and a2 unused arguments from uiDefButF function
These were removed in previous commits like e6f0b60c2e.
2024-02-01 13:09:09 -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
Hans Goudey
9c3aa8b824 Cleanup: Use StringRef arguments for some UI button functions
The benefits are O(1) access to the string size, clearer ownership,
and easily accessible utility functions. For now, only change functions
where the string is clearly non-null. It's not clear in what cases some
other functions recieve null strings.
2024-01-31 17:16:25 -05:00
Hans Goudey
7fa5fc02b7 Cleanup: Move BLF headers to C++ 2024-01-31 14:04:56 -05:00
Hans Goudey
e89b4927e4 Cleanup: UI: Remove unused button creation functions 2024-01-31 13:45:26 -05:00
Hans Goudey
2571bb18be Cleanup: UI: Remove unnecessary function for setting button string 2024-01-31 13:42:57 -05:00
Harley Acheson
8f6ee910ba UI: Remove Blender Logo Alert Icon
As discussed in the UI Module Meeting we don't have an acceptable use
case for dialogs that use the Blender logo. Removing this image from
the project since this is now exposed through dialog customization.

Pull Request: https://projects.blender.org/blender/blender/pulls/117676
2024-01-30 20:22:38 +01:00
Campbell Barton
a360bd3f31 Cleanup: use std::optional instead of empty strings for return values
When a string shouldn't be used or is invalid, use std::nullopt to
make it clear it's value shouldn't be used.

Without this it's possible to accidentally use an empty string
which will silently fail.
2024-01-30 15:56:08 +11: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
606723b3e2 UI: More Defaults for Search Placeholders
When looking for automatic placeholder string For UI_BTYPE_SEARCH_MENU,
use property UI Name as last resort.

Pull Request: https://projects.blender.org/blender/blender/pulls/113792
2024-01-23 17:15:50 +01:00
Hans Goudey
8dd30838e9 Fix #117423: Broken UI button float display after cleanup
Caused by 089c389b5c. Previously the draw string was created
by appending text inside the buffer multiple times. Now it's formatted
in one step. Part of that change was missing for factor display.
2024-01-22 15:46:52 -05:00
Hans Goudey
089c389b5c Cleanup: Store UI button drawstr with std::string
Similar to bff51ae66c
2024-01-22 14:54:44 -05:00
Aras Pranckevicius
a705259b4b Cleanup: move imbuf .h files to .hh 2024-01-19 20:29:38 +01:00
Hans Goudey
90c4e2e6ec Cleanup: Replace UI button "string info" function
Instead of a single function with variadic arguments, a special enum
type containing which string to request, and a special struct to
contain the request and the result, just use separate functions for
each request, and return a std::string by value. Also change the enum
item string access to just give access to the enum item itself and add
const in a few places as necessary.

The callers of the API function get much clearer this way, and it's
much easier to see which information is used to create certain tooltip
strings.
2024-01-19 09:27:56 -05:00
Hans Goudey
f929fb5d77 Cleanup: Store uiBlock name as std::string
And change some adjacent code to benefit from the simplicity
and constant time access to the length of the string.
2024-01-18 16:13:00 -05:00
Hans Goudey
821b077149 Fix #117272: Color property with popover causes Blender freeze
Caused by 29f3af9527, exposed by bff51ae66c.

The problem was that a `uiBut` pointer was being passed to a function
and then dereferenced as a `PanelType`. In the past, the button used to
just have zeros where the pointer was then read from, but after the
changes in the second commit, this was no longer the case.

Fix by being more explicit about the argument type, and changing the
argument from a button to the panel type for one callback. It's a bit
complex because the panel type and panel type idname are stored in
different places depending on the button type.
2024-01-18 13:57:30 -05:00
Campbell Barton
b8a340e630 UI: always return shortcuts from UI_but_string_info_get on request
Change the behavior of UI_but_string_info_get to fill in shortcuts
when requested.

Previously shortcuts were ignored for menus, because showing shortcuts
in tool-tips which are already displayed in the menu isn't needed.

Move this logic to tool-tip creation so other the shortcuts may be
accessed in other contexts.
2024-01-18 10:52:58 +11:00
Hans Goudey
a2032a9aa5 Fix: Tooltip contains bogus text after recent button string cleanup
The code still needs to differentiate a null string from an empty
string in one cast I missed earlier.
2024-01-16 19:32:05 -05:00
Hans Goudey
35028d9480 Fix: Memory leaks after recent button string cleanup 2024-01-16 19:18:37 -05:00
Hans Goudey
bff51ae66c Cleanup: Use std::string to store UI button string
This simplifies memory management and button string manipulation in
general. Just change one of the few strings stored in `uiBut` for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/117183
2024-01-16 21:04:17 +01:00
Campbell Barton
a294a9083e UI: don't show property shortcuts in menus
Operator shortcuts aren't shown in this case,
use the same logic for properties.
2024-01-16 14:09:37 +11:00
Campbell Barton
1fd2573b53 Fix #92478: Shortcuts not shown in pie menu tooltips 2024-01-15 14:35:20 +11:00
Campbell Barton
c00cd902ce Cleanup: use usernames in code-comments
Also remove my name in a few cases where it doesn't seem necessary.
2024-01-14 11:50:02 +11:00
Damien Picard
3bd41cf9bc I18n: Go over TIP_ and IFACE_ usages, change to RPT_ when relevant
The previous commit introduced a new `RPT_()` macro to translate
strings which are not tooltips or regular interface elements, but
longer reports or statuses.

This commit uses the new macro to translate many strings all over the
UI.

Most of it is a simple replace from `TIP_()` or `IFACE_()` to
`RPT_()`, but there are some additional changes:
- A few translations inside `BKE_report()` are removed altogether
  because they are already handled by the translation system.
- Messages inside `UI_but_disable()` are no longer translated
  manually, but they are handled by a new regex in the translation
  system.

Pull Request: https://projects.blender.org/blender/blender/pulls/116804

Pull Request: https://projects.blender.org/blender/blender/pulls/116804
2024-01-12 13:37:32 +01:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Brecht Van Lommel
ec01ee0196 Fix #116471: some menus incorrectly display vertical on macOS
Take into account retina pixel size for estimating window width when
checking if the menu fits.
2023-12-22 18:23:32 +01:00
Jacques Lucke
f824476bd5 UI: add support for uiLayout based panels
This adds support for so called "layout panels" which are panels that are created as part
of `uiLayout`. The goal is to make it easier to have expandable sections as part of a UI.

The initial use case for this are panels in the geometry nodes modifier. This patch provides
a better solution compared to what was attempted in #108565.

### Problems with Existing Approaches

Currently, there are two ways to create these expandable sections:
* One can define a new `Panel` type for each expandable section and use the `parent_id`
  to make this a subpanel of another panel. This has a few problems:
  * `uiLayout` drawing code is more scattered, because one can't just use a single function
    that creates the layout for an entire panel including its subpanels.
  * It does not work so well for dynamic amounts of panels (e.g. like what we need for
    the geometry nodes modifier to organize the inputs).
  * Typically, Blender uses a immediate-ui approach, but subpanels break that currently
    and need extra handling.
  * The order of panels is not very explicit.
  * One can't interleave subpanels and other ui elements, subpanels always come at the
    end of the parent panel.
* Custom solution using existing `uiLayout`. This is done in the material properties. It
  also has a few problems:
  * Custom solutions tend to work slightly different in different places. So the UI is less unified.
  * Can't drag open/close multiple panels.
  * The background color for subpanels does not change.

### Solution

A possible solution to all of these problems is to add support for panels to `uiLayout` directly:
```cpp
/* Add elements before subpanel. */
if (uiLayout *panel_layout = uiLayoutPanel(layout, ...)) {
  /* Add elements in subpanel, but only of the panel is open. */
}
/* Add elements after subpanel. */
```

Integrating subpanels with `uiLayout` has some benefits:
* Subpanels are treated like any other sub-layout and don't have unnecessary boilerplate.
* It becomes trivial to have a dynamic number of potentially nested subpanels.
* Resolves all mentioned problems of custom subpanel solutions.

### Open/Close State

The most tricky thing is to decide where to store the open/close state. Ideally, it should
be stored in the `region` because then the same layout panel can be opened and closed
in every region independently. Unfortunately, storing the state in the region is fairly
complex in some cases.

For example, for modifier subpanels the region would have to store an open/close state
for each panel in each modifier in each object. So a map with
`object pointer + modifier id + panel id` as key would be required. Obviously, this map
could become quite big. Also storing that many ID pointers in UI data is not great and
we don't even have stable modifier ids yet. There also isn't an obvious way for how to
clear unused elements from the map which could become necessary when it becomes big.

In practice, it's rare that the same modifier list is shown in two editors. So the benefit of
storing the open/close state in the region is negligible. Therefor, a much simpler solution
is possible: the open/close state can be stored in the modifier directly. This is actually
how it was implemented before already (see `ui_expand_flag`).

The implementation of layout panels in this patch is *agnostic* to how the open/close
state is stored exactly, as long as it can be referenced as a boolean rna property. This
allows us to store the state in the modifier directly but also allows us to store the state
in the region for other layout panels in the future. We could consider adding an API that
makes it easy to store the state in the region for cases where the key is simpler.
For example: `uiLayoutPanel(layout, TIP_("Mesh Settings"), PanelRegionKey("mesh_settings"))`.

### Python API (not included)

Adding a Python API is fairly straight forward. However, it is **not** included in this patch
so that we can mature the internal API a bit more if necessary, before addon developers
start to depend on it. It would probably work like so:

```python
if panel := layout.panel("Mesh Settings", ...):
    # Add layout elements in the panel if it's open.
```

Pull Request: https://projects.blender.org/blender/blender/pulls/113584
2023-12-22 17:57:57 +01:00
Harley Acheson
548b45d13b Revert #116228: Check Interactivity in button comparisons
Revert of 5741f7b8a9 as this has caused issues as reported in #116384
and #116426.

Pull Request: https://projects.blender.org/blender/blender/pulls/116437
2023-12-21 17:08:47 +01:00
Harley Acheson
5741f7b8a9 Fix #114461: Check Interactivity in button comparisons
Implementation of Julian Eisel's idea of including interactivity in
button comparisons to avoid bad label matches.

Pull Request: https://projects.blender.org/blender/blender/pulls/116228
2023-12-20 01:14:10 +01:00
Brecht Van Lommel
e06561a27a Build: replace Blender specific DEBUG by standard NDEBUG
NDEBUG is part of the C standard and disables asserts. Only this will
now be used to decide if asserts are enabled.

DEBUG was a Blender specific define, that has now been removed.

_DEBUG is a Visual Studio define for builds in Debug configuration.
Blender defines this for all platforms. This is still used in a few
places in the draw code, and in external libraries Bullet and Mantaflow.

Pull Request: https://projects.blender.org/blender/blender/pulls/115774
2023-12-06 16:05:14 +01:00
Harley Acheson
27992034f2 Fix #115815: Include Category name in Enum Row Calculation
Report #115815 shows a time where our calculation of rows and columns
should also include the category name lines. The code was calculating
where to break not including these and is too short if it has a
category.

Pull Request: https://projects.blender.org/blender/blender/pulls/115822
2023-12-06 01:37:04 +01:00
Campbell Barton
86f1fd5d8b BLI_idprop: simplify string creation logic, support unterminated strings
- Support passing in unterminated C-strings when clamped by the size
  argument.
- Pair string and it's size arguments together in IDP_NewStringMaxSize.
- Remove redundant size check which made it seem as if the string
  might not be null terminated.
- Replace clamping the result of strlen(..) with BLI_strnlen,
  to avoid calculating the length past the size checked.
- Add doc-string for unclamped string creation.
2023-12-05 17:11:03 +11:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Campbell Barton
c7593cc99f Cleanup: replace MAX2 with std::max 2023-11-29 17:11:09 +11:00
Hans Goudey
7e3ba529ea Cleanup: Move four blenkernel headers to C++ 2023-11-28 16:05:12 -05:00
Campbell Barton
4e10a4f635 Cleanup: various C++ updates from C 2023-11-27 10:59:54 +11:00
Harley Acheson
c5164e513f Fix #115275: Allow Wrapping of Single Column Enum Menus
Enum menus that do not have categories should be able to wrap to
multiple columns is there is enough horizontal space.

Pull Request: https://projects.blender.org/blender/blender/pulls/115283
2023-11-22 21:15:00 +01:00
Harley Acheson
2793b37f17 Fix #115085: Multicolumn Menus without Category Names
Handle menus that are meant to be multicolumn, with section dividers,
but not all sections have category names, just separators.

Pull Request: https://projects.blender.org/blender/blender/pulls/115102
2023-11-18 17:21:42 +01:00
Harley Acheson
be97ed2828 Fix #115023: Error Measuring Null Menu Item Name
Do not attempt to measure the length of a null string.

Pull Request: https://projects.blender.org/blender/blender/pulls/115027
2023-11-17 06:00:28 +01:00
Harley Acheson
83ce3ef0db Fix #72093: Collapse Wide Enum Lists to One Column
If a multi-column Enum menu gets too wide for the available space,
collapse it to a single column.

Pull Request: https://projects.blender.org/blender/blender/pulls/105386
2023-11-16 21:14:35 +01:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Julian Eisel
ecbb77c558 UI: Support dragging over node panel headers to batch (un)collapse
Makes it possible to swipe over panel header to batch open/collapse all
panels the mouse draged over. Normal panels and sub-panels support this
too.

Two changes were needed:
- Support "drag toggle" feature for `UI_BTYPE_BUT_TOGGLE` - all toggle
  buttons should/can support this.
- Allow querying the pushed state from the button used for the
  collapsing. Multiple ways to do this, in this case simply using the
  pushed state query callback seemed simplest.

Pull Request: https://projects.blender.org/blender/blender/pulls/114560
2023-11-07 10:59:33 +01:00
Campbell Barton
611930e5a8 Cleanup: use std::min/max instead of MIN2/MAX2 macros 2023-11-07 16:33:19 +11:00
Julian Eisel
480dceab12 Asset shelf: Drag over checkboxes to enable/disable catalogs in selector
Makes it possible to swipe over the checkboxes used to enable or disable
catalogs in the asset catalog selector popup, to batch enable or disable
the ones dragged over.

Might also enable this feature for other cases where checkboxes are
displayed.
2023-11-06 22:22:54 +01:00