AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
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:
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 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
@ TOGGLE
Selects or deselects the specified index depending on it's current state.
Definition AListView.h:65
@ UNSET
Deselects the specified index.
Definition AListView.h:60
@ SET
Selects the specified index. In single selection mode, acts like CLEAR_SELECTION_AND_SET.
Definition AListView.h:55
@ CLEAR_SELECTION_AND_SET
Clears old selection and selects the specified index. Used by selectItem.
Definition AListView.h:50
A std::set with AUI extensions.
Definition ASet.h:25
const _unique< ALayout > & getLayout() const noexcept
Get layout manager of the container.
Definition AViewContainerBase.h:140
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348