libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
listview.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/namespace.h>
11#include <promeki/string.h>
12#include <promeki/stringlist.h>
13#include <promeki/tui/widget.h>
14
15PROMEKI_NAMESPACE_BEGIN
16
17class TuiPainter;
18class TuiPalette;
19
32class TuiListView : public TuiWidget {
33 PROMEKI_OBJECT(TuiListView, TuiWidget)
34 public:
35 TuiListView(ObjectBase *parent = nullptr);
36 ~TuiListView() override;
37
38 void addItem(const String &item);
39 void insertItem(int index, const String &item);
40 void setItems(const StringList &items);
41 void clear();
42
43 int currentIndex() const { return _currentIndex; }
44 void setCurrentIndex(int index);
45
46 String currentItem() const;
47 int count() const { return static_cast<int>(_items.size()); }
48
50 int scrollOffset() const { return _scrollOffset; }
51
62 void scrollBy(int delta);
63
68 void ensureVisible(int index);
69
70 Size2Di32 sizeHint() const override;
71
72 PROMEKI_SIGNAL(currentItemChanged, int)
73 PROMEKI_SIGNAL(itemActivated, int)
74
75 protected:
76 void paintEvent(PaintEvent *e) override;
77 void keyPressEvent(KeyEvent *e) override;
78 void mouseEvent(MouseEvent *e) override;
79
80 private:
81 StringList _items;
82 int _currentIndex = -1;
83 int _scrollOffset = 0;
84 bool _dragging = false;
85 int _dragOffset = 0;
86
87 int contentWidth() const;
88 void paintScrollbar(TuiPainter &painter, const TuiPalette &pal);
89 int thumbPos() const;
90 int thumbSize() const;
91 int trackHeight() const;
92};
93
94PROMEKI_NAMESPACE_END
Scrollable list of items with keyboard and mouse navigation.
Definition listview.h:32
void ensureVisible(int index)
Adjusts the scroll offset so that the given index is visible.
void scrollBy(int delta)
Scrolls the viewport by the given number of items.
int scrollOffset() const
Returns the current scroll offset.
Definition listview.h:50
Painting context for TUI widgets.
Definition painter.h:33
Style palette for TUI widgets.
Definition palette.h:41
TUI-specific widget base class.
Definition widget.h:33