RADLib
RADical C++ application framework
RADAppKit.h
Go to the documentation of this file.
1 #ifndef RADAPPKIT_H
2 #define RADAPPKIT_H
3 
9 #pragma once
10 
11 #include <RADCore/RADCore.h>
12 #include <RADUi/RADWidgets.h>
13 
14 #include <cstdint>
15 #include <map>
16 #include <optional>
17 #include <string>
18 #include <vector>
19 
20 namespace RADUi {
21 
23  enum class DockArea {
25  Left,
27  Right,
29  Bottom,
31  Floating
32  };
33 
35  struct DockPanel {
37  std::string id;
39  std::string title;
43  bool visible = true;
45  bool selected = false;
47  double size = 240.0;
48  };
49 
52  public:
53  RADEvents:
56 
58  const std::vector<DockPanel>& panels() const;
60  void setPanels(std::vector<DockPanel> panels);
62  void addPanel(DockPanel panel);
64  bool setVisible(const std::string& id, bool visible);
66  bool select(const std::string& id);
68  bool setSize(const std::string& id, double size);
72  void fromJson(const RADCore::RADJsonValue& value);
73 
74  private:
75  std::vector<DockPanel> panels_;
76  };
77 
79  struct DocumentTab {
81  std::string id;
83  std::string title;
85  std::string fileName;
87  bool modified = false;
89  bool closeable = true;
90  };
91 
94  public:
95  RADEvents:
99  RAD_EVENT(closeRequested, (std::string));
100 
102  const std::vector<DocumentTab>& tabs() const;
104  const std::string& activeId() const;
108  bool setActive(std::string id);
110  bool removeTab(const std::string& id);
112  bool setModified(const std::string& id, bool modified);
114  bool requestClose(const std::string& id);
116  bool hasModifiedTabs() const;
118  void clear();
119 
120  private:
121  std::vector<DocumentTab> tabs_;
122  std::string activeId_;
123  };
124 
126  struct Command {
128  std::string id;
130  std::string title;
132  std::string category;
134  std::string shortcut;
136  bool enabled = true;
137  };
138 
141  public:
142  RADEvents:
146  RAD_EVENT(triggered, (std::string));
147 
149  const std::vector<Command>& commands() const;
151  void setCommands(std::vector<Command> commands);
153  void setFilter(std::string filter);
155  const std::string& filter() const;
157  std::vector<Command> filteredCommands() const;
159  bool trigger(const std::string& id);
160 
161  private:
162  std::vector<Command> commands_;
163  std::string filter_;
164  };
165 
167  enum class NotificationSeverity {
169  Info,
171  Success,
173  Warning,
175  Error
176  };
177 
179  struct Notification {
181  uint64_t id = 0;
185  std::string title;
187  std::string message;
189  std::string actionId;
191  int timeoutMs = 4000;
192  };
193 
196  public:
197  RADEvents:
201  RAD_EVENT(actionTriggered, (uint64_t, std::string));
202 
204  uint64_t push(Notification notification);
206  bool dismiss(uint64_t id);
208  void clear();
210  const std::vector<Notification>& notifications() const;
212  bool triggerAction(uint64_t id);
213 
214  private:
215  uint64_t nextId_ = 1;
216  std::vector<Notification> notifications_;
217  };
218 
220  struct TableColumn {
222  std::string id;
224  std::string title;
226  double width = 120.0;
228  bool sortable = true;
229  };
230 
233  public:
234  RADEvents:
239 
241  void setColumns(std::vector<TableColumn> columns);
243  const std::vector<TableColumn>& columns() const;
245  void setRows(std::vector<std::vector<std::string>> rows);
247  void appendRow(std::vector<std::string> row);
249  size_t rowCount() const;
251  size_t columnCount() const;
253  std::vector<size_t> filteredIndexes() const;
255  std::string value(size_t row, size_t column) const;
257  void setFilter(std::string filter);
259  const std::string& filter() const;
261  void setSelectedRow(std::optional<size_t> row);
263  std::optional<size_t> selectedRow() const;
265  bool activateRow(size_t row);
267  void clear();
268 
269  private:
270  std::vector<TableColumn> columns_;
271  std::vector<std::vector<std::string>> rows_;
272  std::string filter_;
273  std::optional<size_t> selectedRow_;
274  };
275 
279  std::string name;
281  std::string path;
283  bool directory = false;
285  uintmax_t size = 0;
286  };
287 
290  public:
291  RADEvents:
295  RAD_EVENT(fileActivated, (std::string));
296 
298  bool setDirectory(std::string directory);
300  const std::string& directory() const;
302  bool refresh();
304  bool goUp();
308  bool showHidden() const;
310  const std::vector<FileBrowserEntry>& entries() const;
312  bool activate(size_t index);
314  void setSelectedIndex(std::optional<size_t> index);
316  std::optional<size_t> selectedIndex() const;
317 
318  private:
319  std::string directory_;
320  bool showHidden_ = false;
321  std::vector<FileBrowserEntry> entries_;
322  std::optional<size_t> selectedIndex_;
323  };
324 
326  enum class LogLevel {
328  Trace,
330  Debug,
332  Info,
334  Warning,
336  Error
337  };
338 
340  struct LogEntry {
344  std::string category;
346  std::string message;
348  int64_t unixMs = 0;
349  };
350 
353  public:
354  RADEvents:
357 
359  void append(LogEntry entry);
361  void setMaxEntries(size_t maxEntries);
363  void setFilter(std::string filter);
365  const std::string& filter() const;
367  std::vector<LogEntry> filteredEntries() const;
369  const std::vector<LogEntry>& entries() const;
371  void clear();
372 
373  private:
374  std::vector<LogEntry> entries_;
375  size_t maxEntries_ = 5000;
376  std::string filter_;
377  };
378 
381  public:
382  RADEvents:
385 
387  void setQuery(std::string query);
389  const std::string& query() const;
393  bool caseSensitive() const;
394 
395  private:
396  std::string query_;
397  bool caseSensitive_ = false;
398  };
399 
402  public:
403  RADEvents:
406 
408  void setRange(double minimum, double maximum);
410  void setValue(double value);
412  void setBusy(bool busy);
414  double minimum() const;
416  double maximum() const;
418  double value() const;
420  bool busy() const;
422  double normalized() const;
423 
424  private:
425  double minimum_ = 0.0;
426  double maximum_ = 1.0;
427  double value_ = 0.0;
428  bool busy_ = false;
429  };
430 
433  public:
434  RADEvents:
437 
453  void setTitle(std::string title);
455  const std::string& title() const;
456 
457  private:
458  std::string title_;
459  MenuBarModel menuBar_;
460  ToolBarModel toolBar_;
461  StatusBarModel statusBar_;
462  DockLayoutModel dockLayout_;
463  DocumentWorkspaceModel workspace_;
464  CommandPaletteModel commandPalette_;
465  NotificationModel notifications_;
466  };
467 
468 } // namespace RADUi
469 
470 #endif
#define RAD_EVENT(Name, Signature)
Declares a typed RADCore event; example: RAD_EVENT(done, (int)).
Definition: RADCore.h:65
#define RADEvents
Marks a public event declaration block in RADObject-derived classes.
Definition: RADCore.h:43
JSON value supporting null, bool, number, string, array, and object.
Definition: RADCore.h:509
Base class for event receivers, senders, and thread-affinity aware objects.
Definition: RADCore.h:931
High-level application shell state.
Definition: RADAppKit.h:432
MenuBarModel & menuBar()
Returns menu model.
DocumentWorkspaceModel & workspace()
Returns document workspace model.
void setTitle(std::string title)
Sets application title.
CommandPaletteModel & commandPalette()
Returns command palette model.
RADCore::Event< void() > changed
Raised when shell state changes.
Definition: RADAppKit.h:436
ToolBarModel & toolBar()
Returns toolbar model.
DockLayoutModel & dockLayout()
Returns dock layout model.
const std::string & title() const
Returns application title.
NotificationModel & notifications()
Returns notification model.
StatusBarModel & statusBar()
Returns status model.
Searchable command palette model.
Definition: RADAppKit.h:140
std::vector< Command > filteredCommands() const
Returns filtered commands.
const std::string & filter() const
Returns filter text.
RADCore::Event< void(std::string) > triggered
Raised when a command is triggered.
Definition: RADAppKit.h:146
void setCommands(std::vector< Command > commands)
Replaces commands.
void setFilter(std::string filter)
Sets filter text.
RADCore::Event< void() > changed
Raised when commands or filter text changes.
Definition: RADAppKit.h:144
const std::vector< Command > & commands() const
Returns all commands.
bool trigger(const std::string &id)
Triggers an enabled command by id.
Dock layout model for IDE-style tools.
Definition: RADAppKit.h:51
const std::vector< DockPanel > & panels() const
Returns panel descriptors.
void fromJson(const RADCore::RADJsonValue &value)
Restores panel layout.
void addPanel(DockPanel panel)
Adds one panel.
RADCore::RADJsonValue toJson() const
Serializes panel layout.
bool setSize(const std::string &id, double size)
Sets preferred panel size by id.
bool select(const std::string &id)
Selects panel by id and deselects siblings in the same area.
bool setVisible(const std::string &id, bool visible)
Shows or hides panel by id.
RADCore::Event< void() > changed
Raised when panel state changes.
Definition: RADAppKit.h:55
void setPanels(std::vector< DockPanel > panels)
Replaces panel descriptors.
Document workspace model for tabbed editors and browsers.
Definition: RADAppKit.h:93
void upsertTab(DocumentTab tab)
Adds or replaces a tab.
const std::string & activeId() const
Returns active tab id.
RADCore::Event< void() > changed
Raised when tabs or active tab changes.
Definition: RADAppKit.h:97
bool removeTab(const std::string &id)
Removes tab by id.
bool hasModifiedTabs() const
Returns true when any tab is modified.
void clear()
Clears all tabs.
bool setActive(std::string id)
Sets active tab id.
bool setModified(const std::string &id, bool modified)
Marks a tab modified or clean.
RADCore::Event< void(std::string) > closeRequested
Raised when a tab close is requested.
Definition: RADAppKit.h:99
bool requestClose(const std::string &id)
Emits closeRequested for a closeable tab.
const std::vector< DocumentTab > & tabs() const
Returns all tabs.
File browser/navigation model.
Definition: RADAppKit.h:289
bool showHidden() const
Returns hidden-file visibility.
bool activate(size_t index)
Activates entry by index.
void setSelectedIndex(std::optional< size_t > index)
Sets selected entry index.
const std::vector< FileBrowserEntry > & entries() const
Returns entries.
RADCore::Event< void() > changed
Raised when directory, entries, or selection changes.
Definition: RADAppKit.h:293
bool goUp()
Navigates to parent directory.
const std::string & directory() const
Returns current directory.
std::optional< size_t > selectedIndex() const
Returns selected entry index.
bool refresh()
Refreshes entries from current directory.
RADCore::Event< void(std::string) > fileActivated
Raised when a file is activated.
Definition: RADAppKit.h:295
bool setDirectory(std::string directory)
Sets current directory and refreshes entries.
void setShowHidden(bool showHidden)
Sets hidden-file visibility.
Filterable log view model.
Definition: RADAppKit.h:352
void setMaxEntries(size_t maxEntries)
Sets maximum retained entries.
void append(LogEntry entry)
Appends one entry.
const std::string & filter() const
Returns text filter.
void setFilter(std::string filter)
Sets text filter.
const std::vector< LogEntry > & entries() const
Returns all entries.
void clear()
Clears entries.
RADCore::Event< void() > changed
Raised when log entries or filter changes.
Definition: RADAppKit.h:356
std::vector< LogEntry > filteredEntries() const
Returns filtered entries.
State model for a conventional menu bar.
Definition: RADWidgets.h:91
Notification collection model.
Definition: RADAppKit.h:195
RADCore::Event< void(uint64_t, std::string) > actionTriggered
Raised when a notification action is triggered.
Definition: RADAppKit.h:201
uint64_t push(Notification notification)
Adds a notification and returns assigned id.
bool dismiss(uint64_t id)
Removes a notification by id.
const std::vector< Notification > & notifications() const
Returns notifications.
bool triggerAction(uint64_t id)
Triggers notification action.
RADCore::Event< void() > changed
Raised when notifications change.
Definition: RADAppKit.h:199
void clear()
Clears all notifications.
Progress state model.
Definition: RADAppKit.h:401
void setRange(double minimum, double maximum)
Sets range.
bool busy() const
Returns true when busy.
void setBusy(bool busy)
Sets busy/indeterminate state.
RADCore::Event< void() > changed
Raised when progress changes.
Definition: RADAppKit.h:405
void setValue(double value)
Sets current value.
double minimum() const
Returns minimum.
double normalized() const
Returns normalized 0..1 progress.
double value() const
Returns value.
double maximum() const
Returns maximum.
Search box model.
Definition: RADAppKit.h:380
RADCore::Event< void() > changed
Raised when search state changes.
Definition: RADAppKit.h:384
bool caseSensitive() const
Returns case sensitivity.
const std::string & query() const
Returns query text.
void setCaseSensitive(bool caseSensitive)
Sets case sensitivity.
void setQuery(std::string query)
Sets query text.
Status bar text item model.
Definition: RADWidgets.h:620
Toolbar state model.
Definition: RADWidgets.h:598
Virtual string table with columns, filter, and selected row.
Definition: RADAppKit.h:232
bool activateRow(size_t row)
Activates source row.
const std::vector< TableColumn > & columns() const
Returns columns.
size_t rowCount() const
Returns unfiltered row count.
void appendRow(std::vector< std::string > row)
Appends one row.
std::optional< size_t > selectedRow() const
Returns selected source row.
void setRows(std::vector< std::vector< std::string >> rows)
Sets all rows.
std::vector< size_t > filteredIndexes() const
Returns filtered row indexes.
void setSelectedRow(std::optional< size_t > row)
Sets selected source row.
void setFilter(std::string filter)
Sets filter text.
const std::string & filter() const
Returns filter text.
std::string value(size_t row, size_t column) const
Returns value by source row and column.
size_t columnCount() const
Returns column count.
RADCore::Event< void() > changed
Raised when table state changes.
Definition: RADAppKit.h:236
RADCore::Event< void(size_t) > rowActivated
Raised when a row is activated.
Definition: RADAppKit.h:238
void clear()
Removes all rows.
void setColumns(std::vector< TableColumn > columns)
Sets column descriptors.
Definition: RADAppKit.h:20
DockArea
Dock area for app panels.
Definition: RADAppKit.h:23
@ Bottom
Bottom panel area.
@ Right
Right side panel area.
@ Left
Left side panel area.
@ Floating
Floating panel area.
LogLevel
Log severity level.
Definition: RADAppKit.h:326
@ Warning
Warning message.
@ Info
Informational message.
@ Error
Error message.
@ Debug
Debug message.
@ Trace
Trace message.
NotificationSeverity
Notification severity.
Definition: RADAppKit.h:167
@ Warning
Warning notification.
@ Info
Informational notification.
@ Success
Success notification.
@ Error
Error notification.
Command palette command descriptor.
Definition: RADAppKit.h:126
std::string title
Display title.
Definition: RADAppKit.h:130
std::string id
Stable id.
Definition: RADAppKit.h:128
std::string category
Category label.
Definition: RADAppKit.h:132
std::string shortcut
Shortcut display text.
Definition: RADAppKit.h:134
bool enabled
Whether command can run.
Definition: RADAppKit.h:136
Dockable panel descriptor.
Definition: RADAppKit.h:35
std::string id
Stable id.
Definition: RADAppKit.h:37
bool selected
Whether the panel is selected in its area.
Definition: RADAppKit.h:45
bool visible
Whether the panel is visible.
Definition: RADAppKit.h:43
std::string title
Display title.
Definition: RADAppKit.h:39
double size
Preferred size in logical pixels.
Definition: RADAppKit.h:47
DockArea area
Dock area.
Definition: RADAppKit.h:41
Open document tab.
Definition: RADAppKit.h:79
bool closeable
Whether tab can be closed.
Definition: RADAppKit.h:89
bool modified
Whether content has unsaved changes.
Definition: RADAppKit.h:87
std::string fileName
File path when present.
Definition: RADAppKit.h:85
std::string id
Stable tab id.
Definition: RADAppKit.h:81
std::string title
Display title.
Definition: RADAppKit.h:83
File browser entry.
Definition: RADAppKit.h:277
bool directory
True for directories.
Definition: RADAppKit.h:283
std::string name
Display name.
Definition: RADAppKit.h:279
uintmax_t size
File size in bytes when known.
Definition: RADAppKit.h:285
std::string path
Full path.
Definition: RADAppKit.h:281
One log view entry.
Definition: RADAppKit.h:340
int64_t unixMs
Unix timestamp in milliseconds.
Definition: RADAppKit.h:348
std::string message
Message text.
Definition: RADAppKit.h:346
std::string category
Category label.
Definition: RADAppKit.h:344
LogLevel level
Severity.
Definition: RADAppKit.h:342
Toast/status notification.
Definition: RADAppKit.h:179
std::string message
Body text.
Definition: RADAppKit.h:187
int timeoutMs
Timeout in milliseconds; 0 means persistent.
Definition: RADAppKit.h:191
NotificationSeverity severity
Severity.
Definition: RADAppKit.h:183
std::string title
Title text.
Definition: RADAppKit.h:185
std::string actionId
Optional action id.
Definition: RADAppKit.h:189
Table column descriptor.
Definition: RADAppKit.h:220
std::string id
Stable id.
Definition: RADAppKit.h:222
bool sortable
Whether sort is allowed.
Definition: RADAppKit.h:228
std::string title
Display title.
Definition: RADAppKit.h:224
double width
Width in logical pixels.
Definition: RADAppKit.h:226