cgv
Loading...
Searching...
No Matches
help_menu_entry.cxx
1#include "help_menu_entry.h"
2
3#include <cgv/gui/gui_driver.h>
4
5namespace cgv {
6 namespace gui {
7
9 // TODO: Prevent double registration/creation of window.
10
11 auto driver = cgv::gui::get_gui_driver();
12 wnd = driver->create_window(400, 300, "Help: " + get_name(), "generic");
13 std::string value = "scroll_group";
14 wnd->set_void("group", "string", &value);
15
16 for(const auto& section : sections) {
17 switch(section.type) {
18 case SectionType::kHeading1:
19 wnd->add_decorator(section.content, "heading", "level=0", "");
20 break;
21 case SectionType::kHeading2:
22 wnd->add_decorator(section.content, "heading", "level=1", "");
23 break;
24 case SectionType::kHeading3:
25 wnd->add_decorator(section.content, "heading", "level=2", "");
26 break;
27 case SectionType::kHeading4:
28 wnd->add_decorator(section.content, "heading", "level=3", "");
29 break;
30 case SectionType::kText:
31 wnd->add_decorator(section.content, "text", "", "");
32 break;
33 case SectionType::kItems:
34 {
35 std::vector<cgv::utils::token> tokens;
36 cgv::utils::bite_all(cgv::utils::tokenizer(section.content).set_skip("'\"", "'\"", "\\\\").set_ws(";"), tokens);
37
38 if(tokens.empty())
39 break;
40
41 for(const auto& token : tokens) {
42 std::string text = " -\t" + to_string(token);
43 // TODO: Prevent y-spacing between items.
44 wnd->add_decorator(text, "text", "", "");
45 }
46
47 break;
48 }
49 case SectionType::kKeyBindings:
50 {
51 std::vector<cgv::utils::token> tokens;
52 cgv::utils::bite_all(cgv::utils::tokenizer(section.content).set_skip("'\"", "'\"", "\\\\").set_ws(";"), tokens);
53
54 if(tokens.empty())
55 break;
56
57 std::string group_options = "layout=table;border-style=framed;cols=2";
58 group_options += ";rows=" + std::to_string(tokens.size());
59
60 auto group = wnd->add_group("", "layout_group", group_options, "");
61 groups.push_back(group);
62
63 for(const auto& token : tokens) {
64 std::vector<cgv::utils::token> sides;
65 cgv::utils::bite_all(cgv::utils::tokenizer(token).set_skip("'\"", "'\"", "\\\\").set_ws("="), sides);
66
67 if(sides.size() != 2) {
68 //if(report_error)
69 // std::cerr << "property assignment >" << to_string(toks[i]).c_str() << "< does not match pattern lhs=rhs" << std::endl;
70 continue;
71 }
72
73 std::string lhs = cgv::utils::trim(to_string(sides[0]), " ");
74 std::string rhs = cgv::utils::trim(to_string(sides[1]), "'");
75
76 group->add_decorator(" " + lhs, "text", "w=100;border=true", "S");
77 group->add_decorator(rhs, "text", "border=true", "sSxX");
78 }
79
80 break;
81 }
82 default:
83 break;
84 }
85 }
86
87 wnd->show();
88
89 // TODO: Do we need to register the window?
90 //cgv::base::register_object(wnd, "register help window");
91
92 // TODO: Do we need to unregister/clear or whatever the window before we unregister this instance?
93 //driver->remove_window(wnd);
94 //wnd.clear();
95
97}
98
100 // TODO: Do potential unregister actions.
101}
102
103 }
104}
const std::string & get_name() const
return the parent node
Definition named.cxx:9
void unregister() override
Unregister the node.
void on_register() override
Register the node and create a separate (non-blocking) window to show the stored information.
the tokenizer allows to split text into tokens in a convenient way.
Definition tokenizer.h:68
tokenizer & set_ws(const std::string &ws)
set the list of white spaces, that separate tokens and are skipped
Definition tokenizer.cxx:38
tokenizer & set_skip(const std::string &open, const std::string &close)
set several character pairs that enclose tokens that are not split
Definition tokenizer.cxx:44
void unregister_object(base_ptr object, const std::string &options)
unregister an object and send event to all current registration ref_listeners()
Definition register.cxx:617
gui_driver_ptr get_gui_driver()
return the currently registered gui driver or an empty pointer if non has been registered
std::string & trim(std::string &str, const std::string &chars)
trim white space or other characters from start and end of string
Definition scan.cxx:709
void bite_all(tokenizer &t, std::vector< token > &result)
bite all tokens into a token vector
Definition tokenizer.h:121
the cgv namespace
Definition print.h:11