AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ATreeView.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//
   13// Created by alex2 on 7/1/2021.
   14//
   15
   16
   17#pragma once
   18
   19
   20#include "AUI/Model/ATreeModelIndex.h"
   21#include "AViewContainer.h"
   22#include "AScrollbar.h"
   23#include <AUI/Model/ITreeModel.h>
   24
   31class API_AUI_VIEWS ATreeView: public AViewContainerBase {
   32private:
   33    class ContainerView;
   34    class ItemView;
   35
   36public:
   37    ATreeView();
   38    ATreeView(const _<ITreeModel<AString>>& model);
   39    void setModel(const _<ITreeModel<AString>>& model);
   40    void onScroll(const AScrollEvent& event) override;
   41    void setSize(glm::ivec2 size) override;
   42    int getContentMinimumHeight() override;
   43    void handleMouseMove(ItemView* pView);
   44
   45    void setViewFactory(const std::function<_<AView>(const _<ITreeModel<AString>>&, const ATreeModelIndex&)>& viewFactory) {
   46        mViewFactory = viewFactory;
   47    }
   48
   49    void select(const ATreeModelIndex& indexToSelect);
   50
   51signals:
   52    emits<ATreeModelIndex> itemSelected;
   53    emits<ATreeModelIndex> itemMouseClicked;
   54    emits<ATreeModelIndex> itemMouseDoubleClicked;
   55    emits<ATreeModelIndex> itemMouseHover;
   56
   57private:
   58    _<ITreeModel<AString>> mModel;
   59    _<ContainerView> mContent;
   60    _<AScrollbar> mScrollbar;
   61    _weak<ItemView> mPrevSelection;
   62
   63    std::function<_<AView>(const _<ITreeModel<AString>>&, const ATreeModelIndex& index)> mViewFactory;
   64
   65
   66    void updateScrollbarDimensions();
   67    void handleMousePressed(ItemView* v);
   68    void handleMouseDoubleClicked(ItemView* v);
   69    void handleSelected(ItemView* v);
   70
   71    void fillViewsRecursively(const _<AViewContainer>& content, const ATreeModelIndexOrRoot& index);
   72    void makeElement(const _<AViewContainer>& container, const ATreeModelIndex& childIndex, bool isGroup, const _<ATreeView::ItemView>& itemView);
   73    _<ItemView> indexToView(const ATreeModelIndex& target);
   74};
   75
   76
Valid index of ITreeModel.
Definition ATreeModelIndex.h:10
void onScroll(const AScrollEvent &event) override
int getContentMinimumHeight() override
auto size() const
Size, including content area, border and padding.
Definition AView.h:114
Tree model.
Definition ITreeModel.h:35
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:570
Pointing method scroll event.
Definition AScrollEvent.h:20
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:51