载入中...
搜索中...
未找到
EditorShell.cpp
浏览该文件的文档.
1#include "ui/EditorShell.h"
2
3#include "ui/UIHost.h"
4
5namespace eve::ui {
6namespace {
7
8constexpr const char* kShellHostName = "eve_editor";
9
10} // namespace
11
13 if (host_) host_->setTree(window("", {}));
14}
15
16void EditorShell::open(UIHost *inspector, UIHost *database, UIHost *scene) {
17 inspector_ = inspector;
18 database_ = database;
19 scene_ = scene;
20 if (!host_) {
21 host_ = UIHost::createHost(kShellHostName);
22 }
23 auto meta = host_->meta();
24 meta->overlay = true; // no title bar
25 meta->hasPos = true;
26 meta->posX = 0.f;
27 meta->posY = 0.f;
28 meta->hasSize = true;
29 meta->sizeX = 0.f; // width = full display (percentW below)
30 meta->sizeY = 34.f;
31 meta->percentW = 1.f;
32 meta->visible = true;
33 host_->setTree(build());
34 relayout();
35}
36
38 if (host_) host_->setVisible(false);
39 if (inspector_) inspector_->setVisible(false);
40 if (database_) database_->setVisible(false);
41}
42
43bool EditorShell::isOpen() const {
44 return host_ && host_->meta()->visible;
45}
46
47bool EditorShell::selectPanel(const std::string &name) {
48 if (!host_ || !host_->meta()->visible) return false;
49 if (name == "inspector") {
50 if (inspector_) inspector_->setVisible(true);
51 if (database_) database_->setVisible(false);
52 if (scene_) scene_->setVisible(false);
53 return true;
54 }
55 if (name == "database") {
56 if (database_) database_->setVisible(true);
57 if (inspector_) inspector_->setVisible(false);
58 if (scene_) scene_->setVisible(false);
59 return true;
60 }
61 if (name == "scene") {
62 if (scene_) scene_->setVisible(true);
63 if (inspector_) inspector_->setVisible(false);
64 if (database_) database_->setVisible(false);
65 return true;
66 }
67 if (name.empty()) {
68 if (inspector_) inspector_->setVisible(false);
69 if (database_) database_->setVisible(false);
70 if (scene_) scene_->setVisible(false);
71 return true;
72 }
73 return false;
74}
75
77 std::vector<WidgetDesc> menu;
78 menu.push_back(text("DevTools", "lbl_title"));
79 menu.push_back(spacer("menu_spacer"));
80 menu.push_back(button("Inspector##menu", "menu_inspector",
81 [this]() { selectPanel("inspector"); }));
82 menu.push_back(button("Database##menu", "menu_database",
83 [this]() { selectPanel("database"); }));
84 menu.push_back(button("Scene##menu", "menu_scene",
85 [this]() { selectPanel("scene"); }));
86 menu.push_back(button("Close##menu", "menu_close",
87 [this]() { selectPanel(""); }));
88 return window("Editor", {row(std::move(menu), "menubar")}, "root");
89}
90
91void EditorShell::relayout() {
92 // Simple dock (MVP): inspector / database / scene left-to-right, below the
93 // menu bar. Panels use fixed pixel sizes so they never overlap on the
94 // default window; a full flex dock layout can replace this later.
95 if (inspector_) {
96 auto meta = inspector_->meta();
97 meta->hasPos = true;
98 meta->posX = 0.f;
99 meta->posY = 34.f;
100 meta->hasSize = true;
101 meta->sizeX = 280.f;
102 meta->sizeY = 600.f;
103 meta->percentW = 0.f;
104 meta->percentH = 0.f;
105 }
106 if (database_) {
107 auto meta = database_->meta();
108 meta->hasPos = true;
109 meta->posX = 280.f;
110 meta->posY = 34.f;
111 meta->hasSize = true;
112 meta->sizeX = 280.f;
113 meta->sizeY = 600.f;
114 meta->percentW = 0.f;
115 meta->percentH = 0.f;
116 }
117 if (scene_) {
118 auto meta = scene_->meta();
119 meta->hasPos = true;
120 meta->posX = 560.f;
121 meta->posY = 34.f;
122 meta->hasSize = true;
123 meta->sizeX = 280.f;
124 meta->sizeY = 600.f;
125 meta->percentW = 0.f;
126 meta->percentH = 0.f;
127 }
128}
129
130} // namespace eve::ui
const char * name
Definition RockMesh.cpp:21
void open(UIHost *inspector, UIHost *database, UIHost *scene)
Mounts the menu bar and docks the given panel hosts.
bool selectPanel(const std::string &name)
Shows one panel and hides the others.
void close()
Hides the menu bar and every docked panel.
bool isOpen() const
True while the shell is mounted and visible.
WidgetDesc build()
Declarative tree of the menu bar.
ECS mount point for one UI panel/screen. Subclass to attach UI to game entities, e....
Definition UIHost.h:130
static UIHost * createHost(const std::string &name="")
Definition UIHost.cpp:11
void setTree(WidgetDesc root)
Full replace.
Definition UIHost.cpp:26
void setVisible(bool v)
Host visibility / layer / modality.
Definition UIHost.h:208
WidgetDesc spacer(std::string id, float grow)
Flexible empty space; default flexGrow=1 so it absorbs free space in a Flex parent.
Definition Widget.cpp:439
WidgetDesc text(std::string content, std::string id)
Static text label.
Definition Widget.cpp:235
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:225
WidgetDesc button(std::string label, std::string id, std::function< void()> onClick)
Clickable button; fires onClick.
Definition Widget.cpp:244
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
Definition Widget.cpp:431
Declarative widget description (build once / on dirty → flatten into UIHost::Tree).
Definition Widget.h:13