cgv
Loading...
Searching...
No Matches
help_menu_entry.h
1#pragma once
2
3#include <cgv/gui/gui_group.h>
4#include <cgv/gui/window.h>
5#include <cgv/utils/scan.h>
6#include <cgv/utils/token.h>
7#include <cgv/utils/tokenizer.h>
8
9#include "lib_begin.h"
10
11namespace cgv {
12 namespace gui {
13
15class CGV_API help_menu_entry : public cgv::base::node
16{
17private:
18 enum class SectionType {
19 kHeading1,
20 kHeading2,
21 kHeading3,
22 kHeading4,
23 kText,
24 kItems,
25 kKeyBindings
26 };
27
28 struct section {
29 SectionType type = SectionType::kText;
30 std::string content;
31 };
32
33 std::vector<section> sections;
34
35 void add_section(SectionType type, const std::string& content) {
36 sections.push_back({ type, content });
37 }
38
39public:
40 window_ptr wnd;
41 std::vector<gui_group_ptr> groups;
42
44 help_menu_entry(const std::string& name = "") : cgv::base::node(name) {}
45
46 // TODO: Do we need a destructor to clean up?
47 //~help_menu_entry() {}
48
52 void on_register() override;
53
55 void unregister() override;
57
61 void add_heading1(const std::string& text) {
62 add_section(SectionType::kHeading1, text);
63 }
64
66 void add_heading2(const std::string& text) {
67 add_section(SectionType::kHeading2, text);
68 }
69
71 void add_heading3(const std::string& text) {
72 add_section(SectionType::kHeading3, text);
73 }
74
76 void add_heading4(const std::string& text) {
77 add_section(SectionType::kHeading4, text);
78 }
79
81 void add_text(const std::string& text) {
82 add_section(SectionType::kText, text);
83 }
84
88 void add_items(const std::string& items) {
89 add_section(SectionType::kItems, items);
90 }
91
95 void add_key_bindings(const std::string& key_bindings) {
96 add_section(SectionType::kKeyBindings, key_bindings);
97 }
99};
100
102template <class T>
106
110 help_menu_entry_registration(const std::string& _created_type_name, const std::string& _menu_entry_name = "") {
111 static_assert(std::is_base_of<help_menu_entry, T>::value, "T must inherit from cgv::gui::help_menu_entry");
112 cgv::base::register_object(new cgv::base::factory_impl<T>(_created_type_name, true, ""), "menu_text='Help/" + _menu_entry_name + "'");
113 }
114};
115
116 }
117}
118
119#include <cgv/config/lib_end.h>
The node class keeps a pointer to its parent.
Definition node.h:19
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
derive from this class to provide a menu entry that can open a seperate window showing help informati...
help_menu_entry(const std::string &name="")
Construct a help menu entry with the given name.
void add_key_bindings(const std::string &key_bindings)
Add a list of key bindings that will be displayed as a table.
void add_heading3(const std::string &text)
Add a heading with level=2.
void add_text(const std::string &text)
Add a text paragraph that supports word wrapping.
void add_heading4(const std::string &text)
Add a heading with level=3.
void add_heading1(const std::string &text)
Add a heading with level=0.
void add_heading2(const std::string &text)
Add a heading with level=1.
void add_items(const std::string &items)
Add a list of text items that will be displayed as bullet points.
void register_object(base_ptr object, const std::string &options)
register an object and send event to all current registration ref_listeners()
Definition register.cxx:581
the cgv namespace
Definition print.h:11
Helper functions to process strings.
convenience class to register a factory of the given class type that must be derived from cgv::gui::h...
help_menu_entry_registration(const std::string &_created_type_name, const std::string &_menu_entry_name="")
this registers an instance of a factory implementation that only takes classes derived from cgv::gui:...