2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2021-09-23 18:56:29 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup editorui
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-06-05 12:45:33 +02:00
|
|
|
#include <functional>
|
2021-09-23 18:56:29 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
2023-03-16 15:40:31 +01:00
|
|
|
#include "BLI_function_ref.hh"
|
2021-09-23 18:56:29 +02:00
|
|
|
#include "BLI_string_ref.hh"
|
2021-10-26 11:05:01 -05:00
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_resources.hh"
|
|
|
|
|
|
2025-01-07 12:39:13 +01:00
|
|
|
#include "UI_interface_c.hh" // IWYU pragma: export
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
namespace blender::nodes::geo_eval_log {
|
2021-10-21 13:54:48 -05:00
|
|
|
struct GeometryAttributeInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 18:45:35 +01:00
|
|
|
struct ARegion;
|
|
|
|
|
struct bContext;
|
2023-03-16 15:40:31 +01:00
|
|
|
struct PointerRNA;
|
2021-10-26 11:05:01 -05:00
|
|
|
struct StructRNA;
|
2022-01-24 21:16:06 +11:00
|
|
|
struct uiBlock;
|
2023-06-05 12:45:33 +02:00
|
|
|
struct uiBut;
|
2023-03-22 18:45:35 +01:00
|
|
|
struct uiLayout;
|
2023-03-16 15:40:31 +01:00
|
|
|
struct uiList;
|
2021-10-26 11:05:01 -05:00
|
|
|
struct uiSearchItems;
|
2023-03-22 18:45:35 +01:00
|
|
|
struct wmDrag;
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
struct wmEvent;
|
2024-03-08 09:16:00 -05:00
|
|
|
namespace blender::ui {
|
|
|
|
|
class AbstractView;
|
|
|
|
|
class AbstractViewItem;
|
|
|
|
|
} // namespace blender::ui
|
2021-10-26 11:05:01 -05:00
|
|
|
|
2023-06-26 16:39:51 +02:00
|
|
|
void UI_but_func_set(uiBut *but, std::function<void(bContext &)> func);
|
2023-06-06 09:42:09 +10:00
|
|
|
void UI_but_func_pushed_state_set(uiBut *but, std::function<bool(const uiBut &)> func);
|
|
|
|
|
|
2024-07-05 17:09:40 +02:00
|
|
|
/**
|
|
|
|
|
* Template generating a freeing callback matching the #uiButArgNFree signature, for data created
|
|
|
|
|
* with #MEM_new.
|
|
|
|
|
*/
|
|
|
|
|
template<typename T> void but_func_argN_free(void *argN)
|
|
|
|
|
{
|
|
|
|
|
MEM_delete(static_cast<T *>(argN));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Template generating a copying callback matching the #uiButArgNCopy signature, for data created
|
|
|
|
|
* with #MEM_new.
|
|
|
|
|
*/
|
|
|
|
|
template<typename T> void *but_func_argN_copy(const void *argN)
|
|
|
|
|
{
|
|
|
|
|
return MEM_new<T>(__func__, *static_cast<const T *>(argN));
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
namespace blender::ui {
|
2021-10-26 11:05:01 -05:00
|
|
|
|
2022-06-16 11:29:20 +02:00
|
|
|
class AbstractGridView;
|
2021-09-23 18:56:29 +02:00
|
|
|
class AbstractTreeView;
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
class DropTargetInterface;
|
2021-10-21 13:54:48 -05:00
|
|
|
|
2021-10-26 11:05:01 -05:00
|
|
|
/**
|
|
|
|
|
* An item in a breadcrumb-like context. Currently this struct is very simple, but more
|
|
|
|
|
* could be added to it in the future, to support interactivity or tooltips, for example.
|
|
|
|
|
*/
|
|
|
|
|
struct ContextPathItem {
|
|
|
|
|
/* Text to display in the UI. */
|
|
|
|
|
std::string name;
|
|
|
|
|
/* #BIFIconID */
|
|
|
|
|
int icon;
|
2022-10-20 16:37:07 +02:00
|
|
|
int icon_indicator_number;
|
2021-10-26 11:05:01 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void context_path_add_generic(Vector<ContextPathItem> &path,
|
|
|
|
|
StructRNA &rna_type,
|
|
|
|
|
void *ptr,
|
|
|
|
|
const BIFIconID icon_override = ICON_NONE);
|
|
|
|
|
|
|
|
|
|
void template_breadcrumbs(uiLayout &layout, Span<ContextPathItem> context_path);
|
|
|
|
|
|
2025-02-05 18:21:02 -05:00
|
|
|
void attribute_search_add_items(StringRef str,
|
2022-09-13 08:44:26 +02:00
|
|
|
bool can_create_attribute,
|
|
|
|
|
Span<const nodes::geo_eval_log::GeometryAttributeInfo *> infos,
|
|
|
|
|
uiSearchItems *items,
|
|
|
|
|
bool is_first);
|
2025-04-18 12:35:49 +02:00
|
|
|
void grease_pencil_layer_search_add_items(StringRef str,
|
|
|
|
|
Span<const std::string *> layer_names,
|
|
|
|
|
uiSearchItems &items,
|
|
|
|
|
bool is_first);
|
2021-10-21 13:54:48 -05:00
|
|
|
|
2024-07-07 20:00:35 +02:00
|
|
|
bool asset_shelf_popover_invoke(bContext &C,
|
|
|
|
|
blender::StringRef asset_shelf_idname,
|
|
|
|
|
ReportList &reports);
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
/**
|
|
|
|
|
* Some drop targets simply allow dropping onto/into them, others support dragging in-between them.
|
|
|
|
|
* Classes implementing the drop-target interface can use this type to control the behavior by
|
|
|
|
|
* letting it influence the result of #choose_drop_location().
|
|
|
|
|
*/
|
|
|
|
|
enum class DropBehavior {
|
|
|
|
|
/**
|
|
|
|
|
* Enable dropping before (#DropLocation::Before) and after (#DropLocation::After) the
|
|
|
|
|
* drop target. Typically used for reordering items.
|
|
|
|
|
*/
|
|
|
|
|
Reorder,
|
|
|
|
|
/** Only enable dropping onto/into the drop target (#DropLocation::Into). */
|
|
|
|
|
Insert,
|
|
|
|
|
/**
|
|
|
|
|
* Enable dropping onto/into (#DropLocation::Into), before (#DropLocation::Before) and after
|
|
|
|
|
* (#DropLocation::After) the drop target. Typically used for reordering items with nesting
|
|
|
|
|
* support. */
|
|
|
|
|
ReorderAndInsert,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Information on how dragged data should be inserted on drop, as determined through
|
|
|
|
|
* #DropTargetInterface::choose_drop_location(). Also see #DropBehavior.
|
|
|
|
|
*/
|
|
|
|
|
enum class DropLocation {
|
|
|
|
|
Into,
|
|
|
|
|
Before,
|
|
|
|
|
After,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Information passed to drop targets while dragging over them.
|
|
|
|
|
*/
|
|
|
|
|
struct DragInfo {
|
|
|
|
|
const wmDrag &drag_data;
|
|
|
|
|
const wmEvent &event;
|
|
|
|
|
const DropLocation drop_location;
|
|
|
|
|
|
|
|
|
|
DragInfo(const wmDrag &drag, const wmEvent &event, DropLocation drop_location);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-22 18:45:35 +01:00
|
|
|
/**
|
|
|
|
|
* This provides a common interface for UI elements that want to support dragging & dropping
|
|
|
|
|
* entities into/onto them. With it, the element can determine if the dragged entity can be dropped
|
|
|
|
|
* onto itself, provide feedback while dragging and run custom code for the dropping.
|
|
|
|
|
*
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
* By default the drop target behaves so that data can be dragged into or onto it.
|
|
|
|
|
* #choose_drop_location() can be overridden to change that.
|
|
|
|
|
*
|
|
|
|
|
* Note that this is just an interface (not in the strict sense of a Java/C# interface though). A
|
|
|
|
|
* #wmDropBox is needed to request instances of it from a UI element and call its functions. For
|
|
|
|
|
* example the drop box using "UI_OT_view_drop" implements dropping for views and view items via
|
|
|
|
|
* this interface. To support other kinds of UI elements, similar drop boxes would be necessary.
|
2023-03-22 18:45:35 +01:00
|
|
|
*/
|
|
|
|
|
class DropTargetInterface {
|
|
|
|
|
public:
|
|
|
|
|
DropTargetInterface() = default;
|
|
|
|
|
virtual ~DropTargetInterface() = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the data dragged with \a drag can be dropped on the element this drop target is for.
|
|
|
|
|
* \param r_disabled_hint: Return a static string to display to the user, explaining why dropping
|
|
|
|
|
* isn't possible on this UI element. Shouldn't be done too aggressively,
|
|
|
|
|
* e.g. don't set this if the drag-type can't be dropped here; only if it
|
|
|
|
|
* can but there's another reason it can't be dropped. Can assume this is
|
|
|
|
|
* a non-null pointer.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const = 0;
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Once the drop target validated that it can receive the dragged data using #can_drop(), this
|
|
|
|
|
* method can determine where/how the data should be dropped exactly: before, after or into the
|
|
|
|
|
* drop target. Additional feedback can be drawn then while dragging, and the #on_drop() function
|
|
|
|
|
* should operate accordingly. Implementations of this function may want to use #DropBehavior to
|
|
|
|
|
* control which locations may be returned here.
|
|
|
|
|
*
|
|
|
|
|
* If the returned optional is unset, dropping will be disabled. The default implementation
|
|
|
|
|
* returns #DropLocation::Into.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::optional<DropLocation> choose_drop_location(const ARegion ®ion,
|
|
|
|
|
const wmEvent &event) const;
|
2023-03-22 18:45:35 +01:00
|
|
|
/**
|
|
|
|
|
* Custom text to display when dragging over the element using this drop target. Should
|
|
|
|
|
* explain what happens when dropping the data onto this UI element. Will only be used if
|
|
|
|
|
* #DropTargetInterface::can_drop() returns true, so the implementing override doesn't have
|
|
|
|
|
* to check that again. The returned value must be a translated string.
|
|
|
|
|
*/
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
virtual std::string drop_tooltip(const DragInfo &drag) const = 0;
|
2023-03-22 18:45:35 +01:00
|
|
|
/**
|
|
|
|
|
* Execute the logic to apply a drop of the data dragged with \a drag onto/into the UI element
|
|
|
|
|
* this drop target is for.
|
|
|
|
|
*/
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
virtual bool on_drop(bContext *C, const DragInfo &drag) const = 0;
|
2023-03-22 18:45:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Let a drop target handle a drop event.
|
|
|
|
|
* \return True if the dropping was successful.
|
|
|
|
|
*/
|
|
|
|
|
bool drop_target_apply_drop(bContext &C,
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
const ARegion ®ion,
|
|
|
|
|
const wmEvent &event,
|
2023-03-22 18:45:35 +01:00
|
|
|
const DropTargetInterface &drop_target,
|
|
|
|
|
const ListBase &drags);
|
|
|
|
|
/**
|
|
|
|
|
* Call #DropTargetInterface::drop_tooltip() and return the result as newly allocated C string
|
|
|
|
|
* (unless the result is empty, returns null then). Needs freeing with MEM_freeN().
|
|
|
|
|
*/
|
2024-01-19 10:45:33 -05:00
|
|
|
std::string drop_target_tooltip(const ARegion ®ion,
|
|
|
|
|
const DropTargetInterface &drop_target,
|
|
|
|
|
const wmDrag &drag,
|
|
|
|
|
const wmEvent &event);
|
2023-03-22 18:45:35 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Try to find a view item with a drop target under the mouse cursor, or if not found, a view
|
|
|
|
|
* with a drop target.
|
|
|
|
|
* \param xy: Coordinate to find a drop target at, in window space.
|
|
|
|
|
*/
|
|
|
|
|
std::unique_ptr<DropTargetInterface> region_views_find_drop_target_at(const ARegion *region,
|
|
|
|
|
const int xy[2]);
|
|
|
|
|
|
2021-10-21 13:54:48 -05:00
|
|
|
} // namespace blender::ui
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2023-03-16 15:40:31 +01:00
|
|
|
enum eUIListFilterResult {
|
|
|
|
|
/** Never show this item, even when filter results are inverted (#UILST_FLT_EXCLUDE). */
|
|
|
|
|
UI_LIST_ITEM_NEVER_SHOW,
|
|
|
|
|
/** Show this item, unless filter results are inverted (#UILST_FLT_EXCLUDE). */
|
|
|
|
|
UI_LIST_ITEM_FILTER_MATCHES,
|
|
|
|
|
/** Don't show this item, unless filter results are inverted (#UILST_FLT_EXCLUDE). */
|
|
|
|
|
UI_LIST_ITEM_FILTER_MISMATCHES,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function object for UI list item filtering that does the default name comparison with '*'
|
|
|
|
|
* wildcards. Create an instance of this once and pass it to #UI_list_filter_and_sort_items(), do
|
|
|
|
|
* NOT create an instance for every item, this would be costly.
|
|
|
|
|
*/
|
|
|
|
|
class uiListNameFilter {
|
|
|
|
|
/* Storage with an inline buffer for smaller strings (small buffer optimization). */
|
|
|
|
|
struct {
|
|
|
|
|
char filter_buff[32];
|
|
|
|
|
char *filter_dyn = nullptr;
|
|
|
|
|
} storage_;
|
|
|
|
|
char *filter_ = nullptr;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
uiListNameFilter(uiList &list);
|
|
|
|
|
~uiListNameFilter();
|
|
|
|
|
|
|
|
|
|
eUIListFilterResult operator()(const PointerRNA &itemptr,
|
|
|
|
|
blender::StringRefNull name,
|
|
|
|
|
int index);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using uiListItemFilterFn = blender::FunctionRef<eUIListFilterResult(
|
|
|
|
|
const PointerRNA &itemptr, blender::StringRefNull name, int index)>;
|
|
|
|
|
using uiListItemGetNameFn =
|
|
|
|
|
blender::FunctionRef<std::string(const PointerRNA &itemptr, int index)>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filter list items using \a item_filter_fn and sort the result. This respects the normal UI list
|
|
|
|
|
* filter settings like alphabetical sorting (#UILST_FLT_SORT_ALPHA), and result inverting
|
|
|
|
|
* (#UILST_FLT_EXCLUDE).
|
|
|
|
|
*
|
|
|
|
|
* Call this from a #uiListType::filter_items callback with any #item_filter_fn. #uiListNameFilter
|
|
|
|
|
* can be used to apply the default name based filtering.
|
|
|
|
|
*
|
|
|
|
|
* \param get_name_fn: In some cases the name cannot be retrieved via RNA. This function can be set
|
|
|
|
|
* to provide the name still.
|
|
|
|
|
*/
|
|
|
|
|
void UI_list_filter_and_sort_items(uiList *ui_list,
|
2023-08-03 01:11:28 +02:00
|
|
|
const bContext *C,
|
2023-03-16 15:40:31 +01:00
|
|
|
uiListItemFilterFn item_filter_fn,
|
|
|
|
|
PointerRNA *dataptr,
|
|
|
|
|
const char *propname,
|
|
|
|
|
uiListItemGetNameFn get_name_fn = nullptr);
|
|
|
|
|
|
2021-12-09 00:55:11 +11:00
|
|
|
/**
|
2022-07-04 15:29:24 +02:00
|
|
|
* Override this for all available view types.
|
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
|
|
|
* \param idname: Used for restoring persistent state of this view, potentially written to files.
|
|
|
|
|
* Must not be longer than #BKE_ST_MAXNAME (including 0 terminator).
|
2021-12-09 00:55:11 +11:00
|
|
|
*/
|
2022-06-16 11:29:20 +02:00
|
|
|
blender::ui::AbstractGridView *UI_block_add_view(
|
|
|
|
|
uiBlock &block,
|
|
|
|
|
blender::StringRef idname,
|
2022-07-04 15:06:23 +10:00
|
|
|
std::unique_ptr<blender::ui::AbstractGridView> grid_view);
|
2021-09-23 18:56:29 +02:00
|
|
|
blender::ui::AbstractTreeView *UI_block_add_view(
|
|
|
|
|
uiBlock &block,
|
|
|
|
|
blender::StringRef idname,
|
|
|
|
|
std::unique_ptr<blender::ui::AbstractTreeView> tree_view);
|