malena
Why malena
Quick start
Tutorials
API docs
GitHub
GitHub
Tutorials
Loading...
Searching...
No Matches
Graphics
Controls
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
6
#include <
Malena/Core/malena_export.h
>
7
#include <functional>
8
#include <memory>
9
#include <string>
10
#include <vector>
11
12
namespace
ml
13
{
41
class
MALENA_API
NativeMenuBar
42
{
43
public
:
44
struct
Item
45
{
46
enum class
Type
{ Action, Separator };
47
Type
type
;
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
;
72
~NativeMenuBar
();
73
74
NativeMenuBar
(
const
NativeMenuBar
&) =
delete
;
75
NativeMenuBar
&
operator=
(
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
ml::NativeMenuBar::Menu
Definition
NativeMenuBar.h:53
ml::NativeMenuBar::Menu::addItem
Menu & addItem(const std::string &label, std::function< void()> action)
Add a clickable menu item with a callback.
ml::NativeMenuBar::Menu::addSeparator
Menu & addSeparator()
Add a horizontal separator line.
ml::NativeMenuBar::Menu::NativeMenuBar
friend class NativeMenuBar
Definition
NativeMenuBar.h:65
ml::NativeMenuBar::Menu::getItems
const std::vector< Item > & getItems() const
Definition
NativeMenuBar.h:62
ml::NativeMenuBar::Menu::getLabel
const std::string & getLabel() const
Definition
NativeMenuBar.h:61
ml::NativeMenuBar::NativeMenuBar
NativeMenuBar(const NativeMenuBar &)=delete
ml::NativeMenuBar::~NativeMenuBar
~NativeMenuBar()
ml::NativeMenuBar::attach
void attach()
Build and attach the menu bar to the OS.
ml::NativeMenuBar::NativeMenuBar
NativeMenuBar()=default
ml::NativeMenuBar::detach
void detach()
Remove the menu bar and release platform resources.
ml::NativeMenuBar::operator=
NativeMenuBar & operator=(const NativeMenuBar &)=delete
ml::NativeMenuBar::addMenu
Menu & addMenu(const std::string &label)
Add a top-level menu and return it for chaining.
malena_export.h
MALENA_API
#define MALENA_API
Definition
malena_export.h:18
ml
Definition
Component.h:22
ml::NativeMenuBar::Item
Definition
NativeMenuBar.h:45
ml::NativeMenuBar::Item::label
std::string label
Definition
NativeMenuBar.h:48
ml::NativeMenuBar::Item::type
Type type
Definition
NativeMenuBar.h:47
ml::NativeMenuBar::Item::Type
Type
Definition
NativeMenuBar.h:46
ml::NativeMenuBar::Item::action
std::function< void()> action
Definition
NativeMenuBar.h:49