Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
context_menu.hpp
Go to the documentation of this file.
1
/*
2
Copyright 2026 JigSawFr
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
#pragma once
18
19
#include <functional>
20
#include <string>
21
#include <
aurore/core/box.hpp
>
22
#include <
aurore/views/label.hpp
>
23
24
namespace
aurore
25
{
26
27
// A line of a ContextMenu: an icon (optional), a label, what it does.
28
class
ContextMenuItem
:
public
Box
29
{
30
public
:
31
ContextMenuItem
(
const
std::string& label,
View
* icon);
32
33
Label
*
getLabel
()
const
{
return
this->label; }
34
35
private
:
36
Label
* label;
37
};
38
39
// A short list of actions in a popup next to a view: below it, or above
40
// when there is no room below, kept on screen. It opens over the screen
41
// (the screen stays visible around it); B, a touch or a click outside it,
42
// or choosing a line closes it.
43
//
44
// auto* menu = new aurore::ContextMenu(cell);
45
// menu->addItem("Rename", [] { ... }, "\uE3C9"); // a Material Icons glyph
46
// menu->addItem("Delete", [] { ... }, "@res/img/delete.png");
47
// menu->open();
48
//
49
// ContextMenu::attach() opens one with X (and a long press) on a view.
50
class
ContextMenu
:
public
Box
51
{
52
public
:
53
explicit
ContextMenu
(
View
* anchor);
54
55
// A line. `icon`: a picture ("@res/…" or a file path), or one Material
56
// Icons glyph; empty: none. `action` runs once the menu is closed.
57
ContextMenuItem
*
addItem
(
const
std::string& label, std::function<
void
()> action,
const
std::string& icon =
""
);
58
59
// The same with a view of the app's as the icon (a vector icon…).
60
ContextMenuItem
*
addItem
(
const
std::string& label, std::function<
void
()> action,
View
* icon);
61
62
// A line between two groups of lines.
63
void
addSeparator
();
64
65
// A title above the lines.
66
void
setTitle
(
const
std::string& title);
67
68
// Pushes the menu over the current screen.
69
void
open
();
70
71
// Closes it, then runs `then` (if any).
72
void
close
(std::function<
void
()> then =
nullptr
);
73
74
// Opens a menu, which `fill` fills, with `button` on `view` (its hint
75
// reads `hint`, "Options" when empty), and with a long press on it
76
// when `longPress`.
77
static
void
attach
(
View
* view, std::function<
void
(
ContextMenu
* menu)> fill,
ControllerButton
button =
BUTTON_X
,
78
const
std::string& hint =
""
,
bool
longPress =
true
);
79
80
bool
isTranslucent
()
override
{
return
true
; }
81
View
*
getDefaultFocus
()
override
;
82
void
draw
(NVGcontext* vg,
float
x,
float
y,
float
width,
float
height,
Style
style,
FrameContext
* ctx)
override
;
83
void
onThemeChanged
()
override
;
84
85
private
:
86
View
* anchor;
87
Box
* panel;
88
Label
* title =
nullptr
;
89
bool
closing =
false
;
90
Rect
anchorFrame;
91
92
void
place();
93
void
dimBackground();
94
};
95
96
}
// namespace aurore
box.hpp
aurore::Box
Generic FlexBox layout.
Definition
box.hpp:74
aurore::ContextMenuItem
Definition
context_menu.hpp:29
aurore::ContextMenuItem::ContextMenuItem
ContextMenuItem(const std::string &label, View *icon)
aurore::ContextMenuItem::getLabel
Label * getLabel() const
Definition
context_menu.hpp:33
aurore::ContextMenu
Definition
context_menu.hpp:51
aurore::ContextMenu::ContextMenu
ContextMenu(View *anchor)
aurore::ContextMenu::setTitle
void setTitle(const std::string &title)
aurore::ContextMenu::draw
void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
aurore::ContextMenu::addItem
ContextMenuItem * addItem(const std::string &label, std::function< void()> action, View *icon)
aurore::ContextMenu::addItem
ContextMenuItem * addItem(const std::string &label, std::function< void()> action, const std::string &icon="")
aurore::ContextMenu::close
void close(std::function< void()> then=nullptr)
aurore::ContextMenu::isTranslucent
bool isTranslucent() override
Definition
context_menu.hpp:80
aurore::ContextMenu::open
void open()
aurore::ContextMenu::attach
static void attach(View *view, std::function< void(ContextMenu *menu)> fill, ControllerButton button=BUTTON_X, const std::string &hint="", bool longPress=true)
aurore::ContextMenu::addSeparator
void addSeparator()
aurore::ContextMenu::getDefaultFocus
View * getDefaultFocus() override
aurore::ContextMenu::onThemeChanged
void onThemeChanged() override
aurore::FrameContext
Definition
frame_context.hpp:30
aurore::Label
Definition
label.hpp:65
aurore::Style
Simple wrapper around StyleValues for the array operator.
Definition
style.hpp:115
aurore::View
Definition
view.hpp:232
label.hpp
aurore
Definition
actions.hpp:25
aurore::ControllerButton
ControllerButton
Definition
input.hpp:179
aurore::BUTTON_X
@ BUTTON_X
Definition
input.hpp:199
aurore::Rect
Definition
geometry.hpp:70
aurore
views
context_menu.hpp
Generated by
1.9.8