Commit Graph

118 Commits

Author SHA1 Message Date
Hans Goudey
638609752c Fix #134290: Multi-editing crash after recent refactor
Another case of C-style allocation of non-trivial objects hidden
with casting. To fix, give explicit member defaults to a few of
the UI interaction structs.
2025-02-11 12:41:18 -05:00
Julian Eisel
1f88645728 UI: Draw loading icon while previews load
Show a dimmed loading icon while previews are being loaded in a
background thread. The asset shelf and asset/file browsers do this
similarly already.

This is implemented in drawing code, so the loading icon will always
appear when an in-progress preview is being drawn. I experimented with
doing this in `ui_def_but_icon()`, but this won't update correctly with
popups that don't support full refreshing.

This also makes any normal icon that is drawn as preview use the normal
icon size. These icons are usually made for smaller sizes and look very
outblown when displayed at the size of a preview. Yet it's useful to
sometimes pass a normal icon. E.g. for the asset shelf we would already
draw the data-block type icon in place of the preview if there was no
preview to display, and we'd use the normal, smaller size already.
Larger can still be drawn differently.
I don't know of any current cases this would affect though.

Pull Request: https://projects.blender.org/blender/blender/pulls/133880
2025-02-03 16:03:06 +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
Julian Eisel
f5b1a4625d UI: Allow drawing icons as drag previews, use for dragging assets
Instead of requiring an image buffer to draw a bigger preview image
while dragging, allow passing an icon ID and draw that as preview. This
is also how we draw previews elsewhere. Use this for attaching the asset
previews to draggable buttons.

A small user visible change is that previews from the asset browser will
always draw at the default size (multiplied by the interface scale)
while dragging. Previously it used the same size as the asset browser
preview size, which I don't think was useful really. With small sizes
the preview while dragging got unnecessarily small too, with big sizes
it got in the way.

Needed for #131871.
2025-01-24 22:32:27 +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
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
Hans Goudey
3d0988a719 Cleanup: Move some math C-API usage to C++ API
Mostly part of an attempt to remove some of the lesser-used
parts of the C math API.
2024-12-20 21:46:59 +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
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
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
Lukas Tönne
5c57e24fea Cleanup: GPv3: Remove unused BKE functions from GPv2
Removes unused GPv2 functions in blenkernel.

Notes:
-  Functions for layer masks are still in use, but annotations never
  have layer masks in the first place. Would be good to remove the data
  structures so we can remove the functions too.
- Some multi-frame edit functions are also still nominally used, but
multi-frame editing is not an active feature for annotations. This
  should also be removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/128709
2024-10-09 10:27:45 +02:00
Christoph Lendenfeld
fae19d7c92 Anim: Eyedropper for bone properties
This adds an eyedropper button to properties where you can choose a bone.

Clicking it activates the modal operation and you can pick:
* Bones from the Outliner
* Bones from the 3D Viewport if the Armature is in Pose Mode or Edit Mode

## Limitation

Picking from the 3D viewport while in Object Mode doesn't work due to technical reasons.
The selection buffer is only filled with pose bones if the armature is in pose mode.
Using the picker while in object mode gives you the Armature object, not its bones.

So you cannot use the bone picker to constrain an object to a bone.
UNLESS you pin the panel with the object, go to pose mode and then pick.

There is a warning printed for those cases to tell the user why this hasn't worked.

Pull Request: https://projects.blender.org/blender/blender/pulls/121523
2024-09-26 10:05:09 +02:00
Campbell Barton
473bd60164 Cleanup: clarify arguments using const or r_ prefixed return args 2024-09-26 15:03:24 +10:00
Jonas Holzman
5cfe733f84 UI: Color Picker layout rework
Refactoring of the color picker popup. This simplifies code, removes
cruft, and adds new features. The Hex input is removed from its own
tab and placed at the bottom of the layout. The picker circle is made
just a bit smaller. "#" added to the hex values.

Pull Request: https://projects.blender.org/blender/blender/pulls/125675
2024-09-25 18:56:32 +02: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
Harley Acheson
fb651c1613 UI: Show Splash Version Text in White
The version text shown over the splash screen image needs to always be
white regardless of the theme. With "Blender Light" this text is black
and almost impossible to read. This PR adds the ability to set a
specific color for labels without icons and does so for the splash
screen.

Pull Request: https://projects.blender.org/blender/blender/pulls/126340
2024-08-30 20:52:17 +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
Casey Bianco-Davis
1a07c08718 GPv3: Eyedropper tool
This adds the Eyedropper tool to GPv3.

A few changes have been made:

- Added `Brush` mode.
- Set active color in palette.
- Show the palette in the UI.
- Add UI for setting material mode.
- Drag for color accumulation.

Pull Request: https://projects.blender.org/blender/blender/pulls/126211
2024-08-19 11:27:49 +02:00
Campbell Barton
34d12ab33a Cleanup: consistent naming for icon/icon_id 2024-08-10 11:32:40 +10:00
Harley Acheson
5fb140a36e UI: Status Bar Using SVG Icons
Refactor of how "event icons" are created, using custom SVG icons for
key outlines and some complex keys. Allows multiple key widths so that
"Ctrl", "Insert", etc can be readable. Strings are automatically sized
rather than hardcoded. Also allows these strings to be translated.
Supports the UI icon alpha preference.  Also supports local aspect in
case we ever want to allow 2D zooming there.

Pull Request: https://projects.blender.org/blender/blender/pulls/125591
2024-08-05 02:42:26 +02:00
Campbell Barton
111a40239a Cleanup: match argument names for function & declarations
Match function and declaration names, picking names based on
consistency with related code & clarity.

Also changes for old conventions, missed in previous cleanups:

- name -> filepath
- tname -> newname
- maxlen -> maxncpy
2024-07-27 13:32:51 +10:00
Campbell Barton
8fdb190278 Cleanup: typos in comments (duplicate words) 2024-07-14 18:55:43 +10:00
Julian Eisel
99fe6785d0 Fix issues with asset shelf context menu operators
Shortcut and quick favorite operators wouldn't show up in the regular asset
shelf. In the popup the shortcut operators would but they crashed with use
after frees.

Basic issue is that activating view-items by applying the button didn't work
well. That messes with button storage, but also the operator data (like
`uiBut.optype`) is unset after applying, in this case before the context menu
was built.

Instead, activate the view-item directly, and call the activate operator in its
`on_activate()` callback. The button shouldn't call this operator again, so
added a way to attach operators to buttons without calling them.

Seems generally useful to be able to attach an operator to buttons for
tooltips, "Assign Shortcut" and the like, without it being called on button
apply.

Pull Request: https://projects.blender.org/blender/blender/pulls/124466
2024-07-12 10:02:10 +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
Julian Eisel
4a9e8087a7 UI: Highlight first view item on type to search & activate on enter
In particular, this makes the asset shelf popup search highlight the
first asset when changing the search filter using text input. Pressing
Enter will activate this asset then. The feature is implemented
generally for grid and tree views, but only the asset shelf implements
filtering so far. Plus, it requires the
`UI_BUT2_FORCE_SEMI_MODAL_ACTIVE` behavior on the filter text button,
otherwise it captures all input. Only the popup version of the asset
shelf uses this currently. Moving the mouse makes the highlight jump
back to the brush under the cursor again. This is how search menus
behave too.

Part of the brush assets project, see blender/blender!123853. It's made
so it's possible to quickly spawn the brush asset shelf popup, input
text to search a brush and press Enter to activate it. Based on user
feedback this is an important workflow to support well.

More info about the changes in the pull request.

Pull Request: https://projects.blender.org/blender/blender/pulls/123853
2024-07-01 20:36:51 +02:00
Julian Eisel
717389887b Cleanup: Keep panel functions internal to UI code
These were added/exposed in aa03646a74.

There's no need to expose them in the public UI API, and they don't seem
like functions that should be used outside of the UI internals.
2024-05-24 20:29:37 +02:00
Julian Eisel
46f5079f11 Fix: Various crashes and issues with popups
Fixes #121902, #121865, #121905 and some other reports that were closed
as duplicates.

Reverts a change done as part of 7d80fde033.

Reverting this change breaks the yet-to-be-used asset shelf popup a bit,
in that refreshing it won't work propery anymore. Think that's fair
given that 1) the popup isn't in use yet, 2) its refreshing implementation
causes a bunch of high priority bugs, and 3) #122068 is in review with a
better solution to handle refreshing. Namely, it converts the popup to a
popover, which handles refreshing differently, and thus makes the change
being reverted here unnecessary anyway.
2024-05-23 13:22:39 +02:00
Julian Eisel
7d80fde033 UI: Popup version of the asset shelf
Developed as part of the brush assets project, see #106303. No user visible
changes at this point.

Makes it possible to display asset shelves as popups. These popup asset shelves
use static storage for their settings, mainly to remember the active catalog
and filter string, while keeping them separate from the permanent asset shelf
region. Further, the popup can be displayed in any editor, making asset
selectors possible to add anywhere in the UI. When an asset is chosen, an
operator passed to the asset shelf as bl_activate_operator is called, with an
asset weak-reference to refer to the activated asset stored in the operator
properties.

Adds UILayout.template_asset_shelf_popover() to insert asset shelf popup
buttons, taking an asset shelf idname and some normal UI parameters.
2024-05-16 00:11:47 +02:00
Campbell Barton
9ed5ed1a2b Fix #121686: Regression: Context Menu has many operations disabled
Resolve own regression in [0] which caused operators poll functions
in context menus to fail because the menus own region was set
causing the button clicked on not to be detected as the active button.

Resolve by passing "can_refresh" as an argument to ui_popup_block_create
which only sets the "region_popup" context item for popups that can
refresh. This is done because previously "region_popup" was only ever
set for temporary regions that refreshed (details in code-comments).

[0]: 38d11482f5
2024-05-14 14:08:28 +10:00
Harley Acheson
c4e5a70e07 UI: Optional Complex Layout for Workspace Status
Optionally allow complex layout instead of just plain text when using
ED_workspace_status_text.

Pull Request: https://projects.blender.org/blender/blender/pulls/120595
2024-05-06 23:52:37 +02:00
Campbell Barton
0fedcc2f3c Cleanup: correct invalid use of "r_" prefixed return arguments
These arguments are modified in-place and aren't output-only variables.
2024-05-06 11:58:44 +10:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Campbell Barton
f6b7464b4c Cleanup: spelling in comments 2024-05-02 16:44:10 +10:00
Campbell Barton
da4b81e980 Cleanup: move doc-strings into headers 2024-04-30 12:52:52 +10:00
Nathan Vegdahl
bd3518946e Anim: implement "Copy Driver to Selected" operator
This allows the user to copy the driver(s) of a property to other selected items (e.g. objects, nodes, etc.) via the right-click menu.  The implementation is based on the "Copy to Selected" operator, and generally behaves the same except for copying drivers instead of values.

Resolves #120518
2024-04-29 18:34:57 +02:00
Hans Goudey
f39c30dc60 Cleanup: Move eyedropper_colorband.cc to proper C++ namespace 2024-04-17 12:51:36 -04: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
Brecht Van Lommel
d99f2e8eb7 Refactor: Add ability for UI block to own operator
Instead of only referencing an existing one. This will be used for
collection exporter and presets, to make sure the operator instance
stays alive long enough for the preset to be able to be applied.

Pull Request: https://projects.blender.org/blender/blender/pulls/120034
2024-03-29 14:52:35 +01:00
Campbell Barton
4365d0496a Cleanup: use a const pointer for unit-settings 2024-03-29 16:37:36 +11:00
Hans Goudey
893130e6fe Refactor: Remove unnecessary C wrapper for GPUBatch class
Similar to fe76d8c946

Pull Request: https://projects.blender.org/blender/blender/pulls/119898
2024-03-26 03:06:25 +01:00
Hans Goudey
1050d6147f Cleanup: Remove unnecessary C wrappers for UI view classes 2024-03-08 09:16:07 -05:00
Hans Goudey
744f3b2823 Cleanup: Grammar in comments: Fix uses of "own"
"Own" (the adjective) cannot be used on its own. It should be combined
with something like "its own", "our own",  "her own", or "the object's own".
It also isn't used separately to mean something like "separate".

Also, "its own" is correct instead of "it's own" which is a misues of the verb.
2024-03-07 16:23:35 -05:00
Hans Goudey
d29ce3d531 UI: Remove uiBut a1 and a2 values
Over the last couple years (!) UI buttons have moved to derived classes,
meaning we don't need to use the same "a1" and "a2" variables to store
different information. At this point, that information is set specifically
by internal UI code, or functions like `UI_but_*_set`.

These values are only set to their default 0 values now (or -1 in some
non-meaningful cases). This commit removes the values from buttons
and removes the remaining a1 and a2 arguments from the UI API.
2024-03-01 14:27:57 -05:00
Hans Goudey
8c63889241 Cleanup: UI: Use derived struct for list scroll bars, remove a1, a2 usage 2024-03-01 14:27:57 -05:00
Hans Goudey
365966d51d Cleanup: UI: Use derived struct for label buttons, remove a1, a2 usage 2024-03-01 14:27:56 -05:00
Hans Goudey
7053aef448 Cleanup: Correct comments about uiBut a1 and a2 2024-03-01 14:27:56 -05:00
Hans Goudey
f4e670af2c Refactor: UI: Use regular button callbacks for curve, color ramp templates
Previously these used a special "menu func" that used an argument value
passed through each menu button's a2 value. This was more complex than
necessary given the existence of generic button callbacks.

So use std::function in these remaining cases, and remove the now-unused
`butm_func` and `butm_func_arg` values in the uiBlock.
2024-03-01 14:27:56 -05:00
Harley Acheson
5e669d99d7 Refactor: UI_BTYPE_SEPR_LINE Without Need for uiBut->a1
The line separator needs to know vertical or horizontal orientation
at draw time, and is independent of button rect. This PR removes the
use of uiBut->a1 for this in favor of a derived struct.

Pull Request: https://projects.blender.org/blender/blender/pulls/118969
2024-03-01 18:09:02 +01:00