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 edinterface
|
|
|
|
|
*
|
2022-07-19 18:00:56 +02:00
|
|
|
* Code to manage views as part of the regular screen hierarchy. E.g. managing ownership of views
|
|
|
|
|
* inside blocks (#uiBlock.views), looking up items in the region, passing WM notifiers to views,
|
|
|
|
|
* etc.
|
|
|
|
|
*
|
|
|
|
|
* Blocks and their contained views are reconstructed on every redraw. This file also contains
|
|
|
|
|
* functions related to this recreation of views inside blocks. For example to query state
|
|
|
|
|
* information before the view is done reconstructing (#AbstractView.is_reconstructed() returns
|
|
|
|
|
* false), it may be enough to query the previous version of the block/view/view-item. Since such
|
|
|
|
|
* queries rely on the details of the UI reconstruction process, they should remain internal to
|
|
|
|
|
* `interface/` code.
|
2021-09-23 18:56:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2022-06-16 11:29:20 +02:00
|
|
|
#include <type_traits>
|
2021-09-23 18:56:29 +02:00
|
|
|
#include <variant>
|
|
|
|
|
|
2021-09-30 16:26:56 +02:00
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2022-06-16 11:29:20 +02:00
|
|
|
|
2021-09-23 18:56:29 +02:00
|
|
|
#include "BLI_listbase.h"
|
2023-03-22 18:45:35 +01:00
|
|
|
#include "BLI_map.hh"
|
2021-09-23 18:56:29 +02:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2022-06-16 11:29:20 +02:00
|
|
|
|
2022-11-26 00:21:17 -06:00
|
|
|
#include "interface_intern.hh"
|
2021-09-23 18:56:29 +02:00
|
|
|
|
|
|
|
|
#include "UI_interface.hh"
|
2022-06-16 11:29:20 +02:00
|
|
|
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
#include "UI_abstract_view.hh"
|
2022-06-16 11:29:20 +02:00
|
|
|
#include "UI_grid_view.hh"
|
2021-09-23 18:56:29 +02:00
|
|
|
#include "UI_tree_view.hh"
|
|
|
|
|
|
|
|
|
|
using namespace blender;
|
|
|
|
|
using namespace blender::ui;
|
|
|
|
|
|
|
|
|
|
/**
|
2022-07-04 15:29:24 +02:00
|
|
|
* Wrapper to store views in a #ListBase, addressable via an identifier.
|
2021-09-23 18:56:29 +02:00
|
|
|
*/
|
|
|
|
|
struct ViewLink : public Link {
|
|
|
|
|
std::string idname;
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
std::unique_ptr<AbstractView> view;
|
2023-03-22 18:45:35 +01:00
|
|
|
|
|
|
|
|
static void views_bounds_calc(const uiBlock &block);
|
2021-09-23 18:56:29 +02:00
|
|
|
};
|
|
|
|
|
|
2022-06-16 11:29:20 +02:00
|
|
|
template<class T>
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
static T *ui_block_add_view_impl(uiBlock &block,
|
|
|
|
|
StringRef idname,
|
|
|
|
|
std::unique_ptr<AbstractView> view)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
2021-12-17 15:38:15 +01:00
|
|
|
ViewLink *view_link = MEM_new<ViewLink>(__func__);
|
2021-09-23 18:56:29 +02:00
|
|
|
BLI_addtail(&block.views, view_link);
|
|
|
|
|
|
2022-06-16 11:29:20 +02:00
|
|
|
view_link->view = std::move(view);
|
2021-09-23 18:56:29 +02:00
|
|
|
view_link->idname = idname;
|
|
|
|
|
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
return dynamic_cast<T *>(view_link->view.get());
|
2022-06-16 11:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractGridView *UI_block_add_view(uiBlock &block,
|
|
|
|
|
StringRef idname,
|
2022-07-04 15:06:23 +10:00
|
|
|
std::unique_ptr<AbstractGridView> grid_view)
|
2022-06-16 11:29:20 +02:00
|
|
|
{
|
2022-07-04 15:06:23 +10:00
|
|
|
return ui_block_add_view_impl<AbstractGridView>(block, idname, std::move(grid_view));
|
2022-06-16 11:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractTreeView *UI_block_add_view(uiBlock &block,
|
|
|
|
|
StringRef idname,
|
|
|
|
|
std::unique_ptr<AbstractTreeView> tree_view)
|
|
|
|
|
{
|
|
|
|
|
return ui_block_add_view_impl<AbstractTreeView>(block, idname, std::move(tree_view));
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ui_block_free_views(uiBlock *block)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH_MUTABLE (ViewLink *, link, &block->views) {
|
2021-12-17 15:38:15 +01:00
|
|
|
MEM_delete(link);
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 18:45:35 +01:00
|
|
|
void ViewLink::views_bounds_calc(const uiBlock &block)
|
|
|
|
|
{
|
|
|
|
|
Map<AbstractView *, rcti> views_bounds;
|
|
|
|
|
|
|
|
|
|
rcti minmax;
|
|
|
|
|
BLI_rcti_init_minmax(&minmax);
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, link, &block.views) {
|
|
|
|
|
views_bounds.add(link->view.get(), minmax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (uiBut *, but, &block.buttons) {
|
|
|
|
|
if (but->type != UI_BTYPE_VIEW_ITEM) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
uiButViewItem *view_item_but = static_cast<uiButViewItem *>(but);
|
|
|
|
|
if (!view_item_but->view_item) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the view from the button. */
|
|
|
|
|
AbstractViewItem &view_item = reinterpret_cast<AbstractViewItem &>(*view_item_but->view_item);
|
|
|
|
|
AbstractView &view = view_item.get_view();
|
|
|
|
|
|
|
|
|
|
rcti &bounds = views_bounds.lookup(&view);
|
|
|
|
|
rcti but_rcti{};
|
|
|
|
|
BLI_rcti_rctf_copy_round(&but_rcti, &view_item_but->rect);
|
|
|
|
|
BLI_rcti_do_minmax_rcti(&bounds, &but_rcti);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto item : views_bounds.items()) {
|
|
|
|
|
const rcti &bounds = item.value;
|
|
|
|
|
if (BLI_rcti_is_empty(&bounds)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractView &view = *item.key;
|
|
|
|
|
view.bounds_ = bounds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ui_block_views_bounds_calc(const uiBlock *block)
|
|
|
|
|
{
|
|
|
|
|
ViewLink::views_bounds_calc(*block);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 17:36:36 +01:00
|
|
|
void ui_block_views_listen(const uiBlock *block, const wmRegionListenerParams *listener_params)
|
2022-06-16 11:29:20 +02:00
|
|
|
{
|
|
|
|
|
ARegion *region = listener_params->region;
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, view_link, &block->views) {
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
if (view_link->view->listen(*listener_params->notifier)) {
|
|
|
|
|
ED_region_tag_redraw(region);
|
2022-06-16 11:29:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 17:00:44 +02:00
|
|
|
void ui_block_views_draw_overlays(const ARegion *region, const uiBlock *block)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, view_link, &block->views) {
|
2024-10-02 11:19:49 +02:00
|
|
|
view_link->view->draw_overlays(*region, *block);
|
2023-07-06 17:00:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:00 -05:00
|
|
|
blender::ui::AbstractView *UI_region_view_find_at(const ARegion *region,
|
|
|
|
|
const int xy[2],
|
|
|
|
|
const int pad)
|
2023-03-22 18:45:35 +01:00
|
|
|
{
|
2023-03-29 14:16:31 +11:00
|
|
|
/* NOTE: Similar to #ui_but_find_mouse_over_ex(). */
|
|
|
|
|
|
2023-03-22 18:45:35 +01:00
|
|
|
if (!ui_region_contains_point_px(region, xy)) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) {
|
|
|
|
|
float mx = xy[0], my = xy[1];
|
|
|
|
|
ui_window_to_block_fl(region, block, &mx, &my);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, view_link, &block->views) {
|
|
|
|
|
std::optional<rcti> bounds = view_link->view->get_bounds();
|
|
|
|
|
if (!bounds) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rcti padded_bounds = *bounds;
|
|
|
|
|
if (pad) {
|
|
|
|
|
BLI_rcti_pad(&padded_bounds, pad, pad);
|
|
|
|
|
}
|
|
|
|
|
if (BLI_rcti_isect_pt(&padded_bounds, mx, my)) {
|
2024-03-08 09:16:00 -05:00
|
|
|
return view_link->view.get();
|
2023-03-22 18:45:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:00 -05:00
|
|
|
ui::AbstractViewItem *UI_region_views_find_item_at(const ARegion ®ion, const int xy[2])
|
2021-09-30 16:26:56 +02:00
|
|
|
{
|
2024-03-08 09:16:00 -05:00
|
|
|
uiButViewItem *item_but = (uiButViewItem *)ui_view_item_find_mouse_over(®ion, xy);
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
if (!item_but) {
|
2021-09-30 16:26:56 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
return item_but->view_item;
|
2021-09-30 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:00 -05:00
|
|
|
ui::AbstractViewItem *UI_region_views_find_active_item(const ARegion *region)
|
2021-10-08 19:56:24 +02:00
|
|
|
{
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
uiButViewItem *item_but = (uiButViewItem *)ui_view_item_find_active(region);
|
|
|
|
|
if (!item_but) {
|
2021-10-08 19:56:24 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
return item_but->view_item;
|
2021-10-08 19:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-07 17:27:45 +02:00
|
|
|
uiBut *UI_region_views_find_active_item_but(const ARegion *region)
|
2023-08-03 16:54:39 +02:00
|
|
|
{
|
2024-05-07 17:27:45 +02:00
|
|
|
return ui_view_item_find_active(region);
|
2023-08-03 16:54:39 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-01 20:21:25 +02:00
|
|
|
void UI_region_views_clear_search_highlight(const ARegion *region)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) {
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, view_link, &block->views) {
|
|
|
|
|
view_link->view->clear_search_highlight();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 18:45:35 +01:00
|
|
|
namespace blender::ui {
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<DropTargetInterface> region_views_find_drop_target_at(const ARegion *region,
|
|
|
|
|
const int xy[2])
|
|
|
|
|
{
|
2024-03-08 09:16:00 -05:00
|
|
|
if (ui::AbstractViewItem *item = UI_region_views_find_item_at(*region, xy)) {
|
|
|
|
|
if (std::unique_ptr<DropTargetInterface> target = item->create_item_drop_target()) {
|
|
|
|
|
return target;
|
2023-03-22 18:45:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get style for some sensible padding around the view items. */
|
|
|
|
|
const uiStyle *style = UI_style_get_dpi();
|
2024-03-08 09:16:00 -05:00
|
|
|
if (AbstractView *view = UI_region_view_find_at(region, xy, style->buttonspacex)) {
|
|
|
|
|
if (std::unique_ptr<DropTargetInterface> target = view->create_drop_target()) {
|
|
|
|
|
return target;
|
2023-03-22 18:45:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::ui
|
|
|
|
|
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
static StringRef ui_block_view_find_idname(const uiBlock &block, const AbstractView &view)
|
2021-09-23 18:56:29 +02:00
|
|
|
{
|
|
|
|
|
/* First get the idname the of the view we're looking for. */
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, view_link, &block.views) {
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
if (view_link->view.get() == &view) {
|
2021-09-23 18:56:29 +02:00
|
|
|
return view_link->idname;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 11:29:20 +02:00
|
|
|
template<class T>
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
static T *ui_block_view_find_matching_in_old_block_impl(const uiBlock &new_block,
|
|
|
|
|
const T &new_view)
|
2021-10-06 16:29:10 +02:00
|
|
|
{
|
|
|
|
|
uiBlock *old_block = new_block.oldblock;
|
|
|
|
|
if (!old_block) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringRef idname = ui_block_view_find_idname(new_block, new_view);
|
|
|
|
|
if (idname.is_empty()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ViewLink *, old_view_link, &old_block->views) {
|
|
|
|
|
if (old_view_link->idname == idname) {
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
return dynamic_cast<T *>(old_view_link->view.get());
|
2021-10-06 16:29:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:00 -05:00
|
|
|
blender::ui::AbstractView *ui_block_view_find_matching_in_old_block(
|
|
|
|
|
const uiBlock &new_block, const blender::ui::AbstractView &new_view)
|
2022-06-16 11:29:20 +02:00
|
|
|
{
|
2024-03-08 09:16:00 -05:00
|
|
|
return ui_block_view_find_matching_in_old_block_impl(new_block, new_view);
|
2022-06-16 11:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
uiButViewItem *ui_block_view_find_matching_view_item_but_in_old_block(
|
2024-03-08 09:16:00 -05:00
|
|
|
const uiBlock &new_block, const ui::AbstractViewItem &new_item)
|
2021-10-06 16:29:10 +02:00
|
|
|
{
|
2024-03-08 09:16:00 -05:00
|
|
|
uiBlock *old_block = new_block.oldblock;
|
2021-09-23 18:56:29 +02:00
|
|
|
if (!old_block) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
const AbstractView *old_view = ui_block_view_find_matching_in_old_block_impl(
|
2024-03-08 09:16:00 -05:00
|
|
|
new_block, new_item.get_view());
|
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected.
There's plenty of duplicated code in the grid and the tree view, and I expect
this to become more. This starts the process of unifying these parts, which
should also make it easier to add new views. Complexity in the view classes is
reduced, and some type shenanigans for C compatibility and general view
management can be removed, since there is now a common base type.
For the start this ports some of the view reconstruction, where the view and
its items are compared to the version of itself in the previous redraw, so that
state (highlighted, active, renaming, collapsed, ...) can be preserved.
Notifier listening is also ported.
2022-07-02 21:49:21 +02:00
|
|
|
if (!old_view) {
|
2021-09-23 18:56:29 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 16:29:10 +02:00
|
|
|
LISTBASE_FOREACH (uiBut *, old_but, &old_block->buttons) {
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
if (old_but->type != UI_BTYPE_VIEW_ITEM) {
|
2021-10-06 16:29:10 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
uiButViewItem *old_item_but = (uiButViewItem *)old_but;
|
|
|
|
|
if (!old_item_but->view_item) {
|
2021-10-06 16:29:10 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
AbstractViewItem &old_item = *reinterpret_cast<AbstractViewItem *>(old_item_but->view_item);
|
|
|
|
|
/* Check if the item is from the expected view. */
|
|
|
|
|
if (&old_item.get_view() != old_view) {
|
2021-10-06 16:29:10 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 09:16:00 -05:00
|
|
|
if (UI_view_item_matches(new_item, old_item)) {
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
return old_item_but;
|
2021-09-23 18:56:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|