1 | // Aseprite UI Library |
2 | // Copyright (C) 2020-2022 Igara Studio S.A. |
3 | // Copyright (C) 2001-2017 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef UI_LISTBOX_H_INCLUDED |
9 | #define UI_LISTBOX_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "obs/signal.h" |
13 | #include "ui/widget.h" |
14 | |
15 | #include <vector> |
16 | |
17 | namespace ui { |
18 | |
19 | class ListItem; |
20 | |
21 | class ListBox : public Widget { |
22 | public: |
23 | ListBox(); |
24 | |
25 | bool isMultiselect() const { return m_multiselect; } |
26 | void setMultiselect(const bool multiselect); |
27 | |
28 | Widget* getSelectedChild(); |
29 | int getSelectedIndex(); |
30 | |
31 | void selectChild(Widget* item, Message* msg = nullptr); |
32 | void selectIndex(int index, Message* msg = nullptr); |
33 | |
34 | int getItemsCount() const; |
35 | |
36 | void makeChildVisible(Widget* item); |
37 | void centerScroll(); |
38 | void sortItems(); |
39 | void sortItems(bool (*cmp)(Widget* a, Widget* b)); |
40 | |
41 | obs::signal<void()> Change; |
42 | obs::signal<void()> DoubleClickItem; |
43 | |
44 | protected: |
45 | virtual bool onProcessMessage(Message* msg) override; |
46 | virtual void onPaint(PaintEvent& ev) override; |
47 | virtual void onResize(ResizeEvent& ev) override; |
48 | virtual void onSizeHint(SizeHintEvent& ev) override; |
49 | virtual void onChange(); |
50 | virtual void onDoubleClickItem(); |
51 | |
52 | int advanceIndexThroughVisibleItems( |
53 | int startIndex, int delta, const bool loop); |
54 | |
55 | // True if this listbox accepts selecting multiple items at the |
56 | // same time. |
57 | bool m_multiselect; |
58 | |
59 | // Range of items selected when we click down/up. Used to specify |
60 | // the range of selected items in a multiselect operation. |
61 | int m_firstSelectedIndex; |
62 | int m_lastSelectedIndex; |
63 | |
64 | // Initial state (isSelected()) of each list item when the |
65 | // selection operation started. It's used to switch the state of |
66 | // items in case that the user is Ctrl+clicking items several |
67 | // items at the same time. |
68 | std::vector<bool> m_states; |
69 | }; |
70 | |
71 | } // namespace ui |
72 | |
73 | #endif |
74 | |