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-2025 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;
   22class AListViewContainer;
   23
   28class API_AUI_VIEWS AListView : public AScrollArea, public AListModelObserver<AString>::IListModelListener {
   29    friend class AListItem;
   30
   31public:
   35    enum class SelectAction {
   40
   44        SET,
   45
   49        UNSET,
   50
   54        TOGGLE,
   55    };
   56
   57    AListView() : AListView(nullptr) {}
   58    explicit AListView(_<IListModel<AString>> model);
   59    virtual ~AListView();
   60
   61    void setModel(_<IListModel<AString>> model);
   62
   63    void updateSelectionOnItem(size_t i, AListView::SelectAction action);
   64
   68    void selectItem(size_t i) { updateSelectionOnItem(i, SelectAction::CLEAR_SELECTION_AND_SET); }
   69
   70    int getContentFullHeight() { return getLayout()->getMinimumHeight() + 8; }
   71
   72    void setAllowMultipleSelection(bool allowMultipleSelection);
   73
   74    [[nodiscard]] AListModelSelection<AString> getSelectionModel() const {
   75        return AListModelSelection<AString>(mSelectionModel, mObserver->getModel());
   76    }
   77
   78    void insertItem(size_t at, const AString& value) override;
   79    void updateItem(size_t at, const AString& value) override;
   80    void removeItem(size_t at) override;
   81
   82    void onDataCountChanged() override;
   83    void onDataChanged() override;
   84
   85signals:
   86    emits<AListModelSelection<AString>> selectionChanged;
   87    emits<unsigned> itemDoubleClicked;
   88
   89    void clearSelection();
   90
   91private:
   92    _<AListViewContainer> mContent;
   93    ASet<AListModelIndex> mSelectionModel;
   94    _<AListModelObserver<AString>> mObserver;
   95    bool mAllowMultipleSelection = false;
   96
   97    void handleMousePressed(AListItem* item);
   98    void handleMouseDoubleClicked(AListItem* item);
   99
  100    void clearSelectionInternal();
  101};
Definition AListModelObserver.h:22
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:68
SelectAction
Selection action for updateSelectionOnItem.
Definition AListView.h:35
@ TOGGLE
Selects or deselects the specified index depending on it's current state.
Definition AListView.h:54
@ UNSET
Deselects the specified index.
Definition AListView.h:49
@ SET
Selects the specified index. In single selection mode, acts like CLEAR_SELECTION_AND_SET.
Definition AListView.h:44
@ CLEAR_SELECTION_AND_SET
Clears old selection and selects the specified index. Used by selectItem.
Definition AListView.h:39
const _unique< ALayout > & getLayout() const noexcept
Get layout manager of the container.
Definition AViewContainerBase.h:140
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572