AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AListView.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <AUI/Model/AListModelIndex.h>
15#include <AUI/Model/AListModelObserver.h>
16#include <AUI/Model/AListModelSelection.h>
17#include <AUI/Model/IListModel.h>
18
19#include "AScrollArea.h"
20
21class AListItem;
23
28class API_AUI_VIEWS AListView : public AScrollArea, public AListModelObserver<AString>::IListModelListener {
29 friend class AListItem;
30
31 private:
32 _<AListViewContainer> mContent;
33 ASet<AListModelIndex> mSelectionModel;
35 bool mAllowMultipleSelection = false;
36
37 void handleMousePressed(AListItem* item);
38 void handleMouseDoubleClicked(AListItem* item);
39
40 void clearSelectionInternal();
41
42 public:
46 enum class SelectAction {
50 CLEAR_SELECTION_AND_SET,
51
55 SET,
56
60 UNSET,
61
65 TOGGLE,
66 };
67
68 AListView() : AListView(nullptr) {}
69 explicit AListView(const _<IListModel<AString>>& model);
70 virtual ~AListView();
71
72 void setModel(const _<IListModel<AString>>& model);
73
74 void updateSelectionOnItem(size_t i, AListView::SelectAction action);
75
79 void selectItem(size_t i) { updateSelectionOnItem(i, SelectAction::CLEAR_SELECTION_AND_SET); }
80
81 int getContentFullHeight() { return getLayout()->getMinimumHeight() + 8; }
82
83 void setAllowMultipleSelection(bool allowMultipleSelection);
84
85 [[nodiscard]] AListModelSelection<AString> getSelectionModel() const {
86 return AListModelSelection<AString>(mSelectionModel, mObserver->getModel());
87 }
88
89 void insertItem(size_t at, const AString& value) override;
90 void updateItem(size_t at, const AString& value) override;
91 void removeItem(size_t at) override;
92
93 void onDataCountChanged() override;
94 void onDataChanged() override;
95
96signals:
97 emits<AListModelSelection<AString>> selectionChanged;
98 emits<unsigned> itemDoubleClicked;
99
100 void clearSelection();
101};
Definition: AListView.cpp:65
Definition: AListModelObserver.h:22
Definition: AListModelSelection.h:28
Definition: AListView.cpp:24
Displays a list model of strings.
Definition: AListView.h:28
void selectItem(size_t i)
Acts on the item at index i as if the user were left-clicked without keyboard modifiers on it.
Definition: AListView.h:79
SelectAction
Selection action for updateSelectionOnItem.
Definition: AListView.h:46
A scrollable container with vertical and horizontal scrollbars.
Definition: AScrollArea.h:37
A std::set with AUI extensions.
Definition: ASet.h:25
Represents a Unicode character string.
Definition: AString.h:37
const _unique< ALayout > & getLayout() const noexcept
Get layout manager of the container.
Definition: AViewContainerBase.h:140
Definition: IListModel.h:23
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177