Add new shared pointer and make use of it

This commit is contained in:
Gericom
2026-03-28 12:03:06 +01:00
parent bec797ffe7
commit 21a8790ebc
66 changed files with 1098 additions and 523 deletions

View File

@@ -25,25 +25,20 @@ public:
height = 24;
}
View* CreateView() const override
SharedPtr<View> CreateView() const override
{
return new CheatListItemView(_vramOffsets, _materialColorScheme, _fontRepository);
return SharedPtr<CheatListItemView>::MakeShared(_vramOffsets, _materialColorScheme, _fontRepository);
}
void DestroyView(View* view) const override
void BindView(SharedPtr<View> view, int index) const override
{
delete (CheatListItemView*)view;
}
void BindView(View* view, int index) const override
{
auto listItemView = static_cast<CheatListItemView*>(view);
auto listItemView = static_cast<CheatListItemView*>(view.GetPointer());
u32 numberOfSubEntries = 0;
auto subEntries = _cheatCategory->GetSubEntries(numberOfSubEntries);
listItemView->SetEntry(&subEntries[index]);
}
void ReleaseView(View* view, int index) const override
void ReleaseView(SharedPtr<View> view, int index) const override
{
// Nothing to do
}

View File

@@ -37,7 +37,7 @@ CheatsBottomSheetView::CheatsBottomSheetView(std::unique_ptr<CheatsViewModel> vi
, _titleLabel(64, 16, 25, fontRepository->GetFont(FontType::Medium11))
, _secondaryLabel(177, 16, 64, fontRepository->GetFont(FontType::Regular10))
, _descriptionLabel(224, 16, 256, fontRepository->GetFont(FontType::Medium7_5))
, _cheatListRecycler(std::make_unique<RecyclerView>(
, _cheatListRecycler(RecyclerView::CreateShared(
LIST_X, LIST_Y, LIST_WIDTH, LIST_HEIGHT, RecyclerView::Mode::VerticalList))
, _materialColorScheme(materialColorScheme)
, _fontRepository(fontRepository)
@@ -51,7 +51,7 @@ CheatsBottomSheetView::CheatsBottomSheetView(std::unique_ptr<CheatsViewModel> vi
AddChildTail(&_titleLabel);
AddChildTail(&_secondaryLabel);
AddChildTail(&_descriptionLabel);
AddChildTail(_cheatListRecycler.get());
AddChildTail(_cheatListRecycler.GetPointer());
}
void CheatsBottomSheetView::InitVram(const VramContext& vramContext)
@@ -96,9 +96,9 @@ void CheatsBottomSheetView::Update()
_cheatListRecycler->SetPosition(LIST_X, _position.y + LIST_Y);
if (_viewModel->GetState() == CheatsViewModel::State::DisplayCheats)
{
if (_cheatsAdapter == nullptr && _objVramManager != nullptr)
if (!_cheatsAdapter && _objVramManager != nullptr)
{
_cheatsAdapter = new CheatsAdapter(
_cheatsAdapter = SharedPtr<CheatsAdapter>::MakeShared(
_viewModel->GetCurrentCheatCategory(), _materialColorScheme, _fontRepository, _vramOffsets);
_cheatListRecycler->SetAdapter(_cheatsAdapter);
@@ -199,7 +199,7 @@ bool CheatsBottomSheetView::HandleInput(const InputProvider& inputProvider, Focu
{
if (inputProvider.Triggered(InputKey::A))
{
if (focusManager.IsFocusInside(_cheatListRecycler.get()))
if (focusManager.IsFocusInside(_cheatListRecycler.GetPointer()))
{
auto oldCategory = _viewModel->GetCurrentCheatCategory();
_viewModel->ActivateSelectedItem();
@@ -240,11 +240,9 @@ void CheatsBottomSheetView::UpdateCheatList()
// Need to unfocus first, otherwise the focus manager still contains a pointer to a view that is going to be destroyed
_focusManager->Unfocus();
auto oldAdapter = _cheatsAdapter;
_cheatsAdapter = new CheatsAdapter(
_cheatsAdapter = SharedPtr<CheatsAdapter>::MakeShared(
_viewModel->GetCurrentCheatCategory(), _materialColorScheme, _fontRepository, _vramOffsets);
_cheatListRecycler->SetAdapter(_cheatsAdapter, _viewModel->GetSelectedItem());
delete oldAdapter;
// Ugly hack
((DescendingStackVramManager*)_objVramManager)->SetState(_savedVramState);

View File

@@ -1,5 +1,6 @@
#pragma once
#include <memory>
#include "core/SharedPtr.h"
#include "romBrowser/views/BottomSheetView.h"
#include "gui/views/Label2DView.h"
#include "gui/views/RecyclerView.h"
@@ -19,15 +20,6 @@ public:
const MaterialColorScheme* materialColorScheme, const IFontRepository* fontRepository,
FocusManager* focusManager);
~CheatsBottomSheetView() override
{
_cheatListRecycler.reset();
if (_cheatsAdapter != nullptr)
{
delete _cheatsAdapter;
}
}
void InitVram(const VramContext& vramContext) override;
void Update() override;
void Draw(GraphicsContext& graphicsContext) override;
@@ -43,8 +35,8 @@ private:
Label2DView _titleLabel;
Label2DView _secondaryLabel;
Label2DView _descriptionLabel;
std::unique_ptr<RecyclerView> _cheatListRecycler;
CheatsAdapter* _cheatsAdapter = nullptr;
SharedPtr<RecyclerView> _cheatListRecycler;
SharedPtr<CheatsAdapter> _cheatsAdapter;
const MaterialColorScheme* _materialColorScheme;
const IFontRepository* _fontRepository;
IVramManager* _objVramManager = nullptr;