Commit Graph

88 Commits

Author SHA1 Message Date
Harley Acheson
755336b17f Fix #138832: Panel Category Background Out By One Pixel
The drawing of the background of panel categories is out by one pixel,
but was covered by the area borders until recently. This PR just draws
one pixel more to the edge.

Pull Request: https://projects.blender.org/blender/blender/pulls/138956
2025-05-15 22:42:23 +02:00
Hans Goudey
153abc372e GPU: Replace U32/I32 combination with GPU_FETCH_INT_TO_FLOAT in UI code
The conversion from int to float is not supported natively
so it ends up happening beforehand on the CPU or as a
step before the vertex buffer can be used. It's better to just
upload floats in the first place.

Related to:
- 1e1ac2bb9b
- 617858e453

Pull Request: https://projects.blender.org/blender/blender/pulls/138855
2025-05-14 15:15:21 +02:00
Hans Goudey
20b471e851 Cleanup: Resolve missing declaration warning 2025-05-01 16:05:00 -04:00
Guillermo Venegas
5e2a856566 UI: Add shortcut to show active sidebar tab
Add a keyboard shortcut  (numpad period) to show the active sidebar
tab, so users can locate the tab without scrolling.

Pull Request: https://projects.blender.org/blender/blender/pulls/107752
2025-05-01 17:32:51 +02:00
Brecht Van Lommel
fb2ba20b67 Refactor: Use more typed MEM_calloc<> and MEM_malloc<>
Pull Request: https://projects.blender.org/blender/blender/pulls/137822
2025-04-22 11:22:18 +02:00
Harley Acheson
68198e09f2 UI: Use Icon for Panel Header Grip
On panel headers, use SVG Icon for the drag gripper.

Pull Request: https://projects.blender.org/blender/blender/pulls/134471
2025-04-04 22:34:42 +02:00
Campbell Barton
bcdcc3dbde Refactor: use enum types for event modifiers & types
Use enum types for event modifier and types,
`wmEventModifierFlag` & `wmEventType` respectively.

This helps with readability and avoids unintended mixing with other
types. To quiet GCC's `-Wswitch` warnings many `default` cases needed
to be added to switch statements on event types.

Ref !136759
2025-03-31 23:48:29 +00:00
Campbell Barton
486bd6dd60 Cleanup: simplify wmEvent::modifier checks
Check on the modifier flag were explicitly masking all modifiers
which isn't needed as this flag is ensured to only have the four
expected modifier flags set.

Simplify logic by removing masking for "all" modifiers.
2025-03-25 13:03:24 +11:00
Guillermo Venegas
4245f1320e Fix #135742: Avoid unespecified font style for side panel categories text draw
Apply widget style to avoid drawing with the incorrect text size or
weight for side panel categories.

Pull Request: https://projects.blender.org/blender/blender/pulls/135824
2025-03-13 21:44:23 +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
Hans Goudey
d0a6189b50 Refactor: DRW: Centralize and clean up packed normals conversion
Move the code dealing with converting float3 to GPU normals
out of the vertex format header into a separate header. Use a
proper C++ namespace and remove duplication by only using
the more recently added C++ templated conversions.

Most of the diff comes from the removal of the indirect includes
from GPU_vertex_format.hh. A lot of files ended up mistakenly
depending on that.

Pull Request: https://projects.blender.org/blender/blender/pulls/134873
2025-02-24 16:08:30 +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
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +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
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
de95daaadf Fix #130171: Stop Panel Animation When Removing Regions
When removing areas ensure that none of its panels are currently
running open/close animations. If so turn them off.

Pull Request: https://projects.blender.org/blender/blender/pulls/131998
2025-01-14 19:43:42 +01: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
2e4da3bf60 Cleanup: Reduce indentation in UI panel function 2024-11-01 20:14:56 +01:00
Jacques Lucke
c0179a1b78 Nodes: show panel description when hovering over panel headers
We already have the `description` property on panels but are currently not
displaying it when hovering over a panel header. With this patch, the
descriptions will be shown in group nodes as well as the geometry nodes
modifier.

I had to do two lower level changes for layout panels because it didn't work
with tooltips properly.
* Tooltips make the label in the panel header interactive, but clicking to
  open/close the panel should still work.
* The tooltip should disappear when clicking on the header. This is consistent
  with tooltips in other places.

Pull Request: https://projects.blender.org/blender/blender/pulls/127852
2024-09-20 16:24:09 +02:00
Julian Eisel
42b390fe3d Fix #127510: Crash when registering panel as instanced
Generally the instanced option shouldn't be necessary, and it's not used as
intended in the report. However, crashes should be avoided.
2024-09-18 19:17:33 +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
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
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
Bastien Montagne
adfe688046 Fix another batch of mismatches MEM_new/MEM_freeN cases in UI/Assets code. 2024-06-27 15:01:37 +02:00
Julian Eisel
fef0b18a72 Cleanup: Remove unused argument 2024-06-12 21:36:02 +02:00
Harley Acheson
f5131cdee0 Fix #122411: Sub-panels Not Clickable When Popover is Scaled
When a popover includes panels, the calculation of whether the mouse
is over the panel header does not take into consideration local 2D
scaling. Therefore the hit area is in the wrong location if scaled.

Pull Request: https://projects.blender.org/blender/blender/pulls/122696
2024-06-04 20:28:12 +02:00
Hans Goudey
7ee189416c UI: Show modifier pinning with icon, adjust name
User feedback has been that the pinned modifier looks broken because
there is no feedback in the UI showing that it's pinned (related to the
recently reported #121620). It's also inconvenient to disable the pinning
if it's required to move the modifier up (before another modifier that
controls normals for example). Now the "Pin" icon is displayed here,
and clicking on it turns off the pinning.

Also, change the property name from "Stick to Last" to "Pin to Last".
"Stick" is a weird word in the UI, it sounds uncommon and strangely
physical. "Pin" is more associated with this concept.

---

![Screenshot from 2024-05-29 11-41-06](/attachments/4581d362-e2fb-4edf-83dd-7f1e1b71ec4d)

Pull Request: https://projects.blender.org/blender/blender/pulls/122444
2024-05-30 13:56:42 +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
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
Jacques Lucke
2f289857af Object: add Shade Auto Smooth operator
Based on the design in #120230.
* Replaces the `Shade Smooth by Angle` operator with `Shade Auto Smooth`
  in the object context menu menu.
* The new operator automatically adds and removes the modifier instead
  of being a destructive operation.
* The `Shade Smooth` and `Shade Flat` operators now remove the
  `Smooth by Angle` modifier automatically.
* Add a pin option to modifiers, which limits dragging and keeps the
  modifier after newly added modifiers in the list.

Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/121494
2024-05-08 20:24:10 +02:00
Guillermo Venegas
3a640a4707 Fix #121280: clamp layout panel sub-background color to block region
Pull Request: https://projects.blender.org/blender/blender/pulls/121534
2024-05-08 12:32:51 +02: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
8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Guillermo Venegas
aa03646a74 UI: support layout panels in popups
Enables operators that uses `WM_operator_props_dialog_popup`
or `redo` popup to use layout panels.

Other popups would likely also support layout panels, only
they need to set its dummy panel with `UI_popup_dummy_panel_set`.
Popups don't normally use `Panel`, but that's the type that stores the
layout panel states. Therefore, to use layout panels in a popup, one
currently needs to create a dummy panel whose purpose is to store the
layout panel states for as long as the popup is open.

Alternatively, we could potentially also store the layout panel states
somewhere else in the future for popups, but that might be a more involved
change for now.

See #119519 for an example script that uses layout panels in a popup.

Pull Request: https://projects.blender.org/blender/blender/pulls/119519
2024-03-21 10:31:05 +01:00
Harley Acheson
196cd48aad UI: Positioning of 3DView Sidebar Tab Titles
Improve the positioning of the tab titles in the 3D Viewport sidebar
by taking the Text Style size into consideration.

Pull Request: https://projects.blender.org/blender/blender/pulls/119231
2024-03-09 01:34:42 +01:00
Jesse Yurkovich
8dce17e2be Merge branch 'blender-v4.1-release' 2024-02-15 23:42:19 -08:00
Jesse Yurkovich
c8f2a5cc42 UI: Fix FILE_PT_operator drawing when using UI layout panels
The `FILE_PT_operator` panel used in the file browser does not correctly
allow the new UI layout panels to be drawn correctly.

The layout panels depend on drawing the background so that different
colors can denote each panel section. In the case of `FILE_PT_operator`,
this background drawing is skipped entirely leading to a situation where
there's no panel delineation at all.

Forcing the background to be drawn leads to a second problem where
the "typical" panel colors are not used in this part of the file
browser. We need to match the surrounding area otherwise a much
lighter shade of gray will be used and look out of place.

The fix is to extend the processing for PANEL_TYPE_NO_HEADER to account
for both of the above situations.

Pull Request: https://projects.blender.org/blender/blender/pulls/118231
2024-02-16 08:40:32 +01:00
Campbell Barton
5c87dfd269 Cleanup: use BLI_time_ prefix for time functions
Also use the term "now" instead of "check" for clarity.
2024-02-15 13:15:56 +11:00
Bastien Montagne
45e7827898 Clenup: Move BLT headers to Cpp.
Noisy but fairly straight forward.
2024-02-09 18:59:42 +01:00
Hans Goudey
7fa5fc02b7 Cleanup: Move BLF headers to C++ 2024-01-31 14:04:56 -05:00
Harley Acheson
6cc80f1213 UI: Panel Chevron Positioning
Interface_panel chevron was too low. Bumping it up a bit, but also
leaving a bit lower when open (down).

Pull Request: https://projects.blender.org/blender/blender/pulls/117680
2024-01-31 00:30:05 +01:00
Harley Acheson
8d48770418 UI: Consistent Use of Chevron Disclosure Icons
For icons that represent collapsible and collapsed content we use a
variety of icons: chevrons and closed triangles of varying
proportions. This PR makes everything use a chevron for consistency.

Pull Request: https://projects.blender.org/blender/blender/pulls/116240
2024-01-30 22:35:15 +01:00
Campbell Barton
5b59be81ba Cleanup: spelling in comments 2024-01-22 12:44:56 +11:00
Jacques Lucke
4b47b46f9c Cleanup: rename PIL to BLI
The term `PIL` stands for "platform independent library." It exists since the `Initial Revision`
commit from 2002. Nowadays, we generally just use the `BLI` (blenlib) prefix for such code
and the `PIL` prefix feels more confusing then useful. Therefore, this patch renames the
`PIL` to `BLI`.

Pull Request: https://projects.blender.org/blender/blender/pulls/117325
2024-01-19 14:32:28 +01:00
Jacques Lucke
796aa0be59 Fix #117077: layout panels don't work in panels with no header
Previously, panels without headers were always skipped in the code
that opens and closes panels because they could not be closed.
Now they can contain layout panels that can be closed even if the root
panel can not be closed.
2024-01-19 10:59:54 +01:00
Jacques Lucke
8896446f7e Python: add Python API for layout panels
This adds a Python API for layout panels that have been introduced in #113584.
Two new methods on `UILayout` are added:
* `.panel(idname, text="...", default_closed=False) -> Optional[UILayout]`
* `.panel_prop(owner, prop_name, text="...") -> Optional[UILayout]`

Both create a panel and return `None` if the panel is collapsed. The difference lies
in how the open-close-state is stored. The first method internally manages the
open-close-state based on the provided identifier. The second one allows for
providing a boolean property that stores whether the panel is open. This is useful
when creating a dynamic of panels and when it is difficult to create a unique idname.

For the `.panel(...)` method, a new internal map on `Panel` is created which keeps
track of all the panel states based on the idname. Currently, there is no mechanism
for freeing any elements once they have been added to the map. This is unlikely to
cause a problem anytime soon, but we might need some kind of garbage collection
in the future.

```python
import bpy
from bpy.props import BoolProperty

class LayoutDemoPanel(bpy.types.Panel):
    bl_label = "Layout Panel Demo"
    bl_idname = "SCENE_PT_layout_panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        layout.label(text="Before")

        if panel := layout.panel("my_panel_id", text="Hello World", default_closed=False):
            panel.label(text="Success")

        if panel := layout.panel_prop(scene, "show_demo_panel", text="My Panel"):
            panel.prop(scene, "frame_start")
            panel.prop(scene, "frame_end")

        layout.label(text="After")

bpy.utils.register_class(LayoutDemoPanel)
bpy.types.Scene.show_demo_panel = BoolProperty(default=False)
```

Pull Request: https://projects.blender.org/blender/blender/pulls/116949
2024-01-11 19:08:45 +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
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