Loading...
Searching...
No Matches
NativeMenuBar.h
Go to the documentation of this file.
1// Copyright 2025 Dave R. Smith
2// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
3
4#pragma once
5
7#include <functional>
8#include <memory>
9#include <string>
10#include <vector>
11
12namespace ml
13{
42 {
43 public:
44 struct Item
45 {
46 enum class Type { Action, Separator };
48 std::string label;
49 std::function<void()> action;
50 };
51
52 class MALENA_API Menu
53 {
54 public:
56 Menu& addItem(const std::string& label, std::function<void()> action);
57
59 Menu& addSeparator();
60
61 const std::string& getLabel() const { return _label; }
62 const std::vector<Item>& getItems() const { return _items; }
63
64 private:
65 friend class NativeMenuBar;
66 explicit Menu(std::string label);
67 std::string _label;
68 std::vector<Item> _items;
69 };
70
71 NativeMenuBar() = default;
73
74 NativeMenuBar(const NativeMenuBar&) = delete;
76
78 Menu& addMenu(const std::string& label);
79
81 void attach();
82
84 void detach();
85
86 private:
87 std::vector<std::unique_ptr<Menu>> _menus;
88 void* _nativeHandle = nullptr;
89 void* _targetList = nullptr;
90 };
91
92} // namespace ml
Menu & addItem(const std::string &label, std::function< void()> action)
Add a clickable menu item with a callback.
Menu & addSeparator()
Add a horizontal separator line.
const std::vector< Item > & getItems() const
const std::string & getLabel() const
NativeMenuBar(const NativeMenuBar &)=delete
void attach()
Build and attach the menu bar to the OS.
NativeMenuBar()=default
void detach()
Remove the menu bar and release platform resources.
NativeMenuBar & operator=(const NativeMenuBar &)=delete
Menu & addMenu(const std::string &label)
Add a top-level menu and return it for chaining.
#define MALENA_API
Definition Component.h:22
std::function< void()> action