neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
menu.hpp
Go to the documentation of this file.
1// menu.hpp
2/*
3neogfx C++ App/Game Engine
4Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6This program is free software: you can redistribute it and / or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <neogfx/core/event.hpp>
24#include <neogfx/app/action.hpp>
25#include <neogfx/app/i_help.hpp>
28
29namespace neogfx
30{
31 class menu : public i_menu
32 {
33 public:
34 define_declared_event(MenuChanged, menu_changed)
36 define_declared_event(ItemRemoved, item_removed, item_index)
38 define_declared_event(Opened, opened)
39 define_declared_event(Closed, closed)
40 define_declared_event(ItemSelected, item_selected, i_menu_item&)
41 define_declared_event(SelectionCleared, selection_cleared)
42 define_declared_event(OpenSubMenu, open_sub_menu, i_menu&)
43 private:
44 typedef std::unique_ptr<i_menu_item> item_pointer;
45 typedef std::vector<item_pointer> item_list;
46 public:
47 menu(i_menu& aParent, std::string const& aTitle = std::string{}, menu_type aType = menu_type::Popup);
48 menu(std::string const& aTitle = std::string{}, menu_type aType = menu_type::Popup);
50 public:
51 const i_widget& as_widget() const override;
52 i_widget& as_widget() override;
53 bool has_parent() const override;
54 i_menu& parent() override;
55 void set_parent(i_menu& aParent) override;
56 menu_type type() const override;
57 uuid const& group() const override;
58 void set_group(uuid const& aGroup) override;
59 i_string const& title() const override;
60 void set_title(i_string const& aTitle) override;
61 const i_texture& image() const override;
62 void set_image(i_string const& aUri) override;
63 void set_image(const i_image& aImage) override;
64 void set_image(const i_texture& aTexture) override;
65 uint32_t count() const override;
66 uint32_t ideal_insert_index(uuid const& aGroup) const override;
67 const i_menu_item& item_at(item_index aItemIndex) const override;
68 i_menu_item& item_at(item_index aItemIndex) override;
69 void add_sub_menu(i_menu& aSubMenu) override;
70 i_menu& add_sub_menu(i_string const& aSubMenuTitle, uuid const& aGroup = {}) override;
71 i_action& add_action(i_action& aAction) override;
72 i_action& add_action(i_ref_ptr<i_action> const& aAction) override;
73 void add_separator(uuid const& aGroup = {}) override;
74 void insert_sub_menu_at(item_index aItemIndex, i_menu& aSubMenu) override;
75 i_menu& insert_sub_menu_at(item_index aItemIndex, i_string const& aSubMenuText, uuid const& aGroup = {}) override;
76 void insert_action_at(item_index aItemIndex, i_action& aAction) override;
77 void insert_action_at(item_index aItemIndex, i_ref_ptr<i_action> const& aAction) override;
78 void insert_separator_at(item_index aItemIndex, uuid const& aGroup = {}) override;
79 void remove_at(item_index aItemIndex) override;
80 item_index find_sub_menu(uuid const& aGroup) const override;
81 item_index find(const i_menu_item& aItem) const override;
82 item_index find(const i_menu& aSubMenu) const override;
83 bool has_selected_item() const override;
84 item_index selected_item() const override;
85 void select_item_at(item_index aItemIndex, bool aOpenAnySubMenu = true) override;
86 void clear_selection() override;
87 bool has_available_items() const override;
88 bool item_available_at(item_index aItemIndex) const override;
90 item_index previous_available_item(item_index aCurrentIndex) const override;
91 item_index next_available_item(item_index aCurrentIndex) const override;
92 bool is_open() const override;
93 void open() override;
94 void close() override;
95 bool is_modal() const override;
96 void set_modal(bool aModal) override;
97 public:
99 private:
100 item_index update_grouping_separators(item_index aItemIndex);
101 private:
102 i_menu* iParent;
103 menu_type iType;
104 uuid iGroup;
105 string iTitle;
106 texture iImage;
107 item_list iItems;
108 action iSeparator;
109 uint32_t iOpenCount;
110 std::optional<item_index> iSelection;
111 bool iModal;
112 };
113}
virtual uint32_t ideal_insert_index(uuid const &aGroup) const =0
uint32_t item_index
Definition i_menu.hpp:40
bool has_available_items() const override
const i_menu_item & item_at(item_index aItemIndex) const override
i_menu & insert_sub_menu_at(item_index aItemIndex, i_string const &aSubMenuText, uuid const &aGroup={}) override
bool has_parent() const override
void insert_action_at(item_index aItemIndex, i_ref_ptr< i_action > const &aAction) override
const i_texture & image() const override
void insert_separator_at(item_index aItemIndex, uuid const &aGroup={}) override
uuid const & group() const override
menu(std::string const &aTitle=std::string{}, menu_type aType=menu_type::Popup)
item_index find(const i_menu &aSubMenu) const override
void insert_sub_menu_at(item_index aItemIndex, i_menu &aSubMenu) override
void set_image(i_string const &aUri) override
void open() override
bool item_available_at(item_index aItemIndex) const override
void insert_action_at(item_index aItemIndex, i_action &aAction) override
const i_widget & as_widget() const override
bool is_open() const override
i_action & add_action(i_ref_ptr< i_action > const &aAction) override
void clear_selection() override
item_index find(const i_menu_item &aItem) const override
item_index selected_item() const override
i_menu & add_sub_menu(i_string const &aSubMenuTitle, uuid const &aGroup={}) override
void add_sub_menu(i_menu &aSubMenu) override
void add_separator(uuid const &aGroup={}) override
void set_title(i_string const &aTitle) override
i_menu & parent() override
i_widget & as_widget() override
item_index item_index closed selection_cleared define_declared_event(OpenSubMenu, open_sub_menu, i_menu &) private typedef std::vector< item_pointer > item_list
Definition menu.hpp:42
item_index find_sub_menu(uuid const &aGroup) const override
void set_image(const i_image &aImage) override
void select_item_at(item_index aItemIndex, bool aOpenAnySubMenu=true) override
uint32_t ideal_insert_index(uuid const &aGroup) const override
void set_group(uuid const &aGroup) override
void close() override
item_index next_available_item(item_index aCurrentIndex) const override
menu_type type() const override
i_action & add_action(i_action &aAction) override
item_index first_available_item() const override
i_string const & title() const override
void remove_at(item_index aItemIndex) override
void set_image(const i_texture &aTexture) override
i_menu_item & item_at(item_index aItemIndex) override
define_declared_event(MenuChanged, menu_changed) define_declared_event(ItemAdded
void set_parent(i_menu &aParent) override
item_index item_changed
Definition menu.hpp:37
bool is_modal() const override
item_index previous_available_item(item_index aCurrentIndex) const override
uint32_t count() const override
bool has_selected_item() const override
void set_modal(bool aModal) override
menu_type
Definition i_menu.hpp:30
Definition plf_hive.h:79
#define define_declared_event(name, declName,...)
Definition event.hpp:195