载入中...
搜索中...
未找到
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
10void setHostVisible(UIHostHandle handle, bool visible) {
12 if (host) host->get().setVisible(visible);
13}
14
15} // namespace
16
18 auto host = UIHost::resolve(host_);
19 if (host) host->get().setTree(window("", {}));
20}
21
22void EditorShell::open(UIHostHandle inspector, UIHostHandle database, UIHostHandle scene) {
23 inspector_ = inspector;
24 database_ = database;
25 scene_ = scene;
26 auto host = UIHost::resolve(host_);
27 if (!host) {
28 host_ = UIHost::createHost(kShellHostName);
29 host = UIHost::resolve(host_);
30 }
31 if (!host) return;
32 UIHost& shell = host->get();
33 auto meta = shell.meta();
34 meta->overlay = true; // no title bar
35 meta->hasPos = true;
36 meta->lockPos = true;
37 meta->posX = 0.f;
38 meta->posY = 0.f;
39 meta->hasSize = true;
40 meta->sizeX = 0.f; // width = full display (percentW below)
41 meta->sizeY = toolbarHeight_;
42 meta->lockSize = true;
43 meta->percentW = 1.f;
44 meta->visible = true;
45 meta->overlayBgAlpha = 1.f;
46 meta->overlayFlush = true;
47 shell.setTree(build());
48 relayout();
49 setHostVisible(inspector_, true);
50 setHostVisible(database_, true);
51 setHostVisible(scene_, true);
52}
53
55 setHostVisible(host_, false);
56 setHostVisible(inspector_, false);
57 setHostVisible(database_, false);
58 setHostVisible(scene_, false);
59}
60
61bool EditorShell::isOpen() const {
62 auto host = UIHost::resolve(host_);
63 return host && host->get().meta()->visible;
64}
65
66bool EditorShell::selectPanel(const std::string& name) {
67 auto host = UIHost::resolve(host_);
68 if (!host || !host->get().meta()->visible) return false;
69 if (name == "inspector") {
70 setHostVisible(inspector_, true);
71 setHostVisible(database_, false);
72 setHostVisible(scene_, false);
73 return true;
74 }
75 if (name == "database") {
76 setHostVisible(database_, true);
77 setHostVisible(inspector_, false);
78 setHostVisible(scene_, false);
79 return true;
80 }
81 if (name == "scene") {
82 setHostVisible(scene_, true);
83 setHostVisible(inspector_, false);
84 setHostVisible(database_, false);
85 return true;
86 }
87 if (name.empty()) {
88 setHostVisible(inspector_, false);
89 setHostVisible(database_, false);
90 setHostVisible(scene_, false);
91 return true;
92 }
93 return false;
94}
95
96bool EditorShell::togglePanel(const std::string& name) {
97 auto host = UIHost::resolve(host_);
98 if (!host || !host->get().meta()->visible) return false;
100 if (name == "inspector") handle = inspector_;
101 if (name == "database") handle = database_;
102 if (name == "scene") handle = scene_;
103 auto panel = UIHost::resolve(handle);
104 if (!panel) return false;
105 UIHost& panelHost = panel->get();
106 panelHost.setVisible(!panelHost.meta()->visible);
107 return true;
108}
109
111 std::vector<WidgetDesc> commands;
112 commands.push_back(icon(Icon::Cubes, "brand_icon"));
113 commands.push_back(text("EVEngine Editor", "lbl_title"));
114 commands.push_back(badge("Workspace", "workspace_badge"));
115 commands.push_back(spacer("menu_spacer"));
116 commands.push_back(iconButton(Icon::Sliders, "", "menu_inspector", [this]() {
117 togglePanel("inspector");
118 }).withTooltip("Show or hide the Inspector"));
119 commands.push_back(iconButton(Icon::Database, "", "menu_database", [this]() {
120 togglePanel("database");
121 }).withTooltip("Show or hide the object database"));
122 commands.push_back(iconButton(Icon::Layers, "", "menu_scene", [this]() {
123 togglePanel("scene");
124 }).withTooltip("Show or hide the scene hierarchy"));
125 commands.push_back(iconButton(Icon::EyeSlash, "", "menu_close", [this]() {
126 selectPanel("");
127 }).withTooltip("Hide all editor panels"));
128 return window("Editor", {toolbar(std::move(commands), "editor_toolbar")}, "root");
129}
130
131void EditorShell::relayout() {
132 // Seed a responsive three-column workspace once. lockPos/lockSize are
133 // disabled so subsequent user adjustments are stored/restored by ImGui's
134 // standard ini workspace persistence.
135 if (auto inspector = UIHost::resolve(inspector_)) {
136 auto meta = inspector->get().meta();
137 meta->hasPos = true;
138 meta->posX = 0.f;
139 meta->posY = toolbarHeight_;
140 meta->anchorX = 0.f;
141 meta->anchorY = 0.f;
142 meta->lockPos = false;
143 meta->hasSize = true;
144 meta->sizeX = 0.f;
145 meta->sizeY = 0.f;
146 meta->percentW = 0.3f;
147 meta->percentH = 0.9f;
148 meta->lockSize = false;
149 }
150 if (auto database = UIHost::resolve(database_)) {
151 auto meta = database->get().meta();
152 meta->hasPos = true;
153 meta->posX = 0.f;
154 meta->posY = toolbarHeight_;
155 meta->anchorX = 0.3f;
156 meta->anchorY = 0.f;
157 meta->lockPos = false;
158 meta->hasSize = true;
159 meta->sizeX = 0.f;
160 meta->sizeY = 0.f;
161 meta->percentW = 0.35f;
162 meta->percentH = 0.9f;
163 meta->lockSize = false;
164 }
165 if (auto scene = UIHost::resolve(scene_)) {
166 auto meta = scene->get().meta();
167 meta->hasPos = true;
168 meta->posX = 0.f;
169 meta->posY = toolbarHeight_;
170 meta->anchorX = 0.65f;
171 meta->anchorY = 0.f;
172 meta->lockPos = false;
173 meta->hasSize = true;
174 meta->sizeX = 0.f;
175 meta->sizeY = 0.f;
176 meta->percentW = 0.35f;
177 meta->percentH = 0.9f;
178 meta->lockSize = false;
179 }
180}
181
182} // namespace eve::ui
Icon icon
Definition Icons.cpp:11
std::string text
std::string name
std::weak_ptr< PrimitiveScene > scene
PrimitiveHandle handle
bool visible
UIHostHandle host
std::vector< VegetationPresetCommand > commands
~EditorShell()
Editor shell.
bool togglePanel(const std::string &name)
Toggles one panel without hiding the other docked panels.
bool selectPanel(const std::string &name)
Shows one panel and hides the others.
void close()
Hides the menu bar and every docked panel.
UIHostHandle host() const noexcept
Returns the menu-bar host handle, or an empty handle until open().
Definition EditorShell.h:42
bool isOpen() const
True while the shell is mounted and visible.
void open(UIHostHandle inspector, UIHostHandle database, UIHostHandle scene)
Mounts the menu bar and docks the given panel hosts.
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:243
void setTree(WidgetDesc root)
Full replace.
Definition UIHost.cpp:99
void setVisible(bool v)
Host visibility / layer / modality.
Definition UIHost.h:443
static UIHostHandle createHost(const std::string &name="")
Creates an ECS-owned UI host.
Definition UIHost.cpp:48
static eve::OptionalRef< UIHost > resolve(UIHostHandle handle) noexcept
Resolves a UI host handle with ECS generation checking.
Definition UIHost.cpp:61
WidgetDesc badge(std::string label, std::string id)
Compact status/category pill. Tint controls its background color.
Definition Widget.cpp:489
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:292
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:697
WidgetDesc toolbar(std::vector< WidgetDesc > children, std::string id)
Horizontal editor command strip; Spacer children absorb free width.
Definition Widget.cpp:563
WidgetDesc iconButton(Icon value, std::string label, std::string id, std::function< void()> onClick)
Button containing a semantic icon and optional visible label.
Definition Widget.cpp:323
ecs::EntityHandle UIHostHandle
Definition UIHost.h:16
Declarative widget description (build once / on dirty → flatten into UIHost::Tree).
Definition Widget.h:15