libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
menu.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/list.h>
13#include <promeki/tui/widget.h>
14
15PROMEKI_NAMESPACE_BEGIN
16
25class TuiAction : public ObjectBase {
26 PROMEKI_OBJECT(TuiAction, ObjectBase)
27 public:
28 TuiAction(const String &text, ObjectBase *parent = nullptr) : ObjectBase(parent), _text(text) {}
29
30 const String &text() const { return _text; }
31 void setText(const String &text) { _text = text; }
32
33 bool isEnabled() const { return _enabled; }
34 void setEnabled(bool enabled) { _enabled = enabled; }
35
36 PROMEKI_SIGNAL(triggered)
37
38 private:
39 String _text;
40 bool _enabled = true;
41};
42
49class TuiMenu : public TuiWidget {
50 PROMEKI_OBJECT(TuiMenu, TuiWidget)
51 public:
52 TuiMenu(const String &title = String(), ObjectBase *parent = nullptr);
53 ~TuiMenu() override;
54
55 const String &title() const { return _title; }
56 void setTitle(const String &title) {
57 _title = title;
58 update();
59 }
60
61 TuiAction *addAction(const String &text);
62 void addSeparator();
63
64 const List<TuiAction *> &actions() const { return _actions; }
65
66 int currentIndex() const { return _currentIndex; }
67 void setCurrentIndex(int index);
68
69 bool isOpen() const { return _open; }
70 void open();
71 void close();
72
73 Size2Di32 sizeHint() const override;
74
75 protected:
76 void paintEvent(PaintEvent *e) override;
77 void keyPressEvent(KeyEvent *e) override;
78
79 private:
80 String _title;
81 List<TuiAction *> _actions;
82 List<int> _separators; // 1 = separator at this index
83 int _currentIndex = 0;
84 bool _open = false;
85};
86
93class TuiMenuBar : public TuiWidget {
94 PROMEKI_OBJECT(TuiMenuBar, TuiWidget)
95 public:
96 TuiMenuBar(ObjectBase *parent = nullptr);
97 ~TuiMenuBar() override;
98
99 TuiMenu *addMenu(const String &title);
100 const List<TuiMenu *> &menus() const { return _menus; }
101
102 int currentIndex() const { return _currentIndex; }
103
104 Size2Di32 sizeHint() const override;
105
106 protected:
107 void paintEvent(PaintEvent *e) override;
108 void keyPressEvent(KeyEvent *e) override;
109
110 private:
111 List<TuiMenu *> _menus;
112 int _currentIndex = 0;
113 bool _active = false;
114};
115
116PROMEKI_NAMESPACE_END
A menu action item.
Definition menu.h:25
Top-of-screen menu bar with dropdown menus.
Definition menu.h:93
Dropdown menu.
Definition menu.h:49
TUI-specific widget base class.
Definition widget.h:33