neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_menu.hpp
Go to the documentation of this file.
1// i_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>
26
27namespace neogfx
28{
29 enum class menu_type : uint32_t
30 {
31 MenuBar,
32 Popup
33 };
34
36 {
37 public:
38 struct no_widget : std::logic_error { no_widget() : std::logic_error{ "neogfx::i_menu::no_widget" } {} };
39 public:
40 typedef uint32_t item_index;
41 public:
42 declare_event(menu_changed)
43 declare_event(item_added, item_index)
45 declare_event(item_changed, item_index)
47 declare_event(closed)
48 declare_event(item_selected, i_menu_item&)
49 declare_event(selection_cleared)
50 declare_event(open_sub_menu, i_menu&)
51 public:
52 typedef uint32_t item_index;
53 public:
54 struct no_parent : std::logic_error { no_parent() : std::logic_error("neogfx::i_menu::no_parent") {} };
55 struct bad_item_index : std::logic_error { bad_item_index() : std::logic_error("neogfx::i_menu::bad_item_index") {} };
56 struct item_not_found : std::logic_error { item_not_found() : std::logic_error("neogfx::i_menu::item_not_found") {} };
57 struct no_selected_item : std::logic_error { no_selected_item() : std::logic_error("neogfx::i_menu::no_selected_item") {} };
58 struct cannot_select_item : std::logic_error { cannot_select_item() : std::logic_error("neogfx::i_menu::cannot_select_item") {} };
59 struct no_available_items : std::logic_error { no_available_items() : std::logic_error("neogfx::i_menu::no_available_items") {} };
60 struct already_closed : std::logic_error { already_closed() : std::logic_error("neogfx::i_menu::already_closed") {} };
61 public:
62 virtual ~i_menu() = default;
63 public:
64 virtual const i_widget& as_widget() const = 0;
65 virtual i_widget& as_widget() = 0;
66 virtual bool has_parent() const = 0;
67 virtual i_menu& parent() = 0;
68 virtual void set_parent(i_menu& aParent) = 0;
69 virtual menu_type type() const = 0;
70 virtual uuid const& group() const = 0;
71 virtual void set_group(uuid const& aGroup) = 0;
72 virtual i_string const& title() const = 0;
73 virtual void set_title(i_string const& aTitle) = 0;
74 virtual const i_texture& image() const = 0;
75 virtual void set_image(i_string const& aUri) = 0;
76 virtual void set_image(i_image const& aImage) = 0;
77 virtual void set_image(i_texture const& aTexture) = 0;
78 virtual uint32_t count() const = 0;
79 virtual uint32_t ideal_insert_index(uuid const& aGroup) const = 0;
80 virtual const i_menu_item& item_at(item_index aItemIndex) const = 0;
81 virtual i_menu_item& item_at(item_index aItemIndex) = 0;
82 virtual void add_sub_menu(i_menu& aSubMenu) = 0;
83 virtual i_menu& add_sub_menu(i_string const& aSubMenuTitle, uuid const& aGroup = {}) = 0;
84 virtual void add_separator(uuid const& aGroup = {}) = 0;
85 virtual void insert_sub_menu_at(item_index aItemIndex, i_menu& aSubMenu) = 0;
86 virtual i_menu& insert_sub_menu_at(item_index aItemIndex, i_string const& aSubMenuTitle, uuid const& aGroup = {}) = 0;
87 virtual void insert_action_at(item_index aItemIndex, i_action& aAction) = 0;
88 virtual void insert_action_at(item_index aItemIndex, i_ref_ptr<i_action> const& aAction) = 0;
89 virtual void insert_separator_at(item_index aItemIndex, uuid const& aGroup = {}) = 0;
90 virtual void remove_at(item_index aItemIndex) = 0;
91 virtual item_index find_sub_menu(uuid const& aGroup) const = 0;
92 virtual item_index find(i_menu_item const& aItem) const = 0;
93 virtual item_index find(i_menu const& aSubMenu) const = 0;
94 virtual bool has_selected_item() const = 0;
95 virtual item_index selected_item() const = 0;
96 virtual void select_item_at(item_index aItemIndex, bool aOpenAnySubMenu = true) = 0;
97 virtual void clear_selection() = 0;
98 virtual bool has_available_items() const = 0;
99 virtual bool item_available_at(item_index aItemIndex) const = 0;
100 virtual item_index first_available_item() const = 0;
101 virtual item_index previous_available_item(item_index aCurrentIndex) const = 0;
102 virtual item_index next_available_item(item_index aCurrentIndex) const = 0;
103 virtual bool is_open() const = 0;
104 virtual void open() = 0;
105 virtual void close() = 0;
106 virtual bool is_modal() const = 0;
107 virtual void set_modal(bool aModal) = 0;
108 public:
109 uint32_t ideal_insert_index(i_action const& aAction) const
110 {
111 return ideal_insert_index(aAction.group());
112 }
113 uint32_t ideal_insert_index(i_menu const& aSubMenu) const
114 {
115 return ideal_insert_index(aSubMenu.group());
116 }
117 };
118}
virtual uuid const & group() const =0
virtual void insert_action_at(item_index aItemIndex, i_action &aAction)=0
virtual i_menu & insert_sub_menu_at(item_index aItemIndex, i_string const &aSubMenuTitle, uuid const &aGroup={})=0
virtual void remove_at(item_index aItemIndex)=0
virtual i_menu & add_sub_menu(i_string const &aSubMenuTitle, uuid const &aGroup={})=0
uint32_t ideal_insert_index(i_menu const &aSubMenu) const
Definition i_menu.hpp:113
virtual void set_group(uuid const &aGroup)=0
virtual ~i_menu()=default
virtual i_widget & as_widget()=0
virtual item_index previous_available_item(item_index aCurrentIndex) const =0
uint32_t ideal_insert_index(i_action const &aAction) const
Definition i_menu.hpp:109
virtual menu_type type() const =0
virtual const i_texture & image() const =0
virtual void insert_sub_menu_at(item_index aItemIndex, i_menu &aSubMenu)=0
virtual bool has_selected_item() const =0
virtual bool is_open() const =0
virtual bool item_available_at(item_index aItemIndex) const =0
virtual void set_image(i_image const &aImage)=0
virtual void select_item_at(item_index aItemIndex, bool aOpenAnySubMenu=true)=0
virtual const i_menu_item & item_at(item_index aItemIndex) const =0
virtual i_menu & parent()=0
virtual void set_image(i_texture const &aTexture)=0
virtual item_index next_available_item(item_index aCurrentIndex) const =0
virtual item_index find(i_menu_item const &aItem) const =0
virtual uuid const & group() const =0
virtual item_index selected_item() const =0
virtual item_index find(i_menu const &aSubMenu) const =0
virtual bool is_modal() const =0
virtual void set_parent(i_menu &aParent)=0
virtual void open()=0
virtual i_string const & title() const =0
virtual const i_widget & as_widget() const =0
virtual item_index find_sub_menu(uuid const &aGroup) const =0
virtual void insert_action_at(item_index aItemIndex, i_ref_ptr< i_action > const &aAction)=0
virtual uint32_t ideal_insert_index(uuid const &aGroup) const =0
declare_event(menu_changed) declare_event(item_added
virtual bool has_available_items() const =0
uint32_t item_index
Definition i_menu.hpp:40
virtual void set_title(i_string const &aTitle)=0
virtual void clear_selection()=0
virtual item_index first_available_item() const =0
virtual bool has_parent() const =0
virtual void close()=0
virtual void add_separator(uuid const &aGroup={})=0
virtual void insert_separator_at(item_index aItemIndex, uuid const &aGroup={})=0
virtual void add_sub_menu(i_menu &aSubMenu)=0
virtual void set_modal(bool aModal)=0
virtual i_menu_item & item_at(item_index aItemIndex)=0
virtual uint32_t count() const =0
virtual void set_image(i_string const &aUri)=0
menu_type
Definition i_menu.hpp:30
Definition plf_hive.h:79
#define declare_event(declName,...)
Definition i_event.hpp:305