载入中...
搜索中...
未找到
WorkspaceLayoutShell.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::ui_editor {
7namespace {
8
11
12float clampRatio(float value) {
13 if (!std::isfinite(value)) return 0.25f;
14 return std::max(0.1f, std::min(0.9f, value));
15}
16
17std::vector<WidgetDesc> defaultContent(const WorkspacePanelDescriptor &panel) {
18 std::vector<WidgetDesc> body;
19 body.push_back(ui::text(panel.title.empty() ? panel.id : panel.title,
20 panel.id.empty() ? "placeholder" : panel.id + "/title"));
21 if (!panel.capability.empty() || !panel.context.empty()) {
22 body.push_back(ui::text("capability=" + panel.capability + " context=" + panel.context,
23 panel.id + "/meta"));
24 }
25 return body;
26}
27
28WidgetDesc fillPanel(const WorkspacePanelDescriptor &panel, WorkspaceLayoutShell::ContentBuilder content) {
29 std::vector<WidgetDesc> body =
30 content ? content(panel) : defaultContent(panel);
31 WidgetDesc page = ui::panelFrame(panel.title.empty() ? panel.id : panel.title, std::move(body),
32 panel.id);
33 // TabContainer uses page.text as the tab label and page.id as the page key.
34 page.text = panel.title.empty() ? panel.id : panel.title;
35 return page;
36}
37
38WidgetDesc regionContent(const std::vector<WorkspacePanelDescriptor> &panels,
39 const std::string &activePanel, bool tabStack,
41 if (panels.empty()) {
42 return ui::panelFrame("Empty", {ui::text("No panel", "empty")}, "empty");
43 }
44 if (panels.size() == 1 || !tabStack) {
45 return fillPanel(panels.front(), content);
46 }
47 std::vector<WidgetDesc> pages;
48 pages.reserve(panels.size());
49 std::string active = activePanel;
50 bool activeFound = false;
51 for (const auto &panel : panels) {
52 if (panel.id == active) activeFound = true;
53 pages.push_back(fillPanel(panel, content));
54 }
55 if (!activeFound) active = panels.front().id;
56 return ui::tabContainer(std::move(pages), active, panels.front().region + "/tabs");
57}
58
59WidgetDesc wrapDock(const std::string &region, WidgetDesc child) {
60 std::vector<WidgetDesc> children;
61 children.reserve(1);
62 children.emplace_back(std::move(child));
63 return ui::dockArea(region, std::move(children), "dock/" + region);
64}
65
66} // namespace
67
68std::vector<WorkspacePanelDescriptor> WorkspaceLayoutShell::panelsInRegion(
69 const editor::EditorWorkspace &workspace, std::string_view region) {
70 std::vector<WorkspacePanelDescriptor> out;
71 const int count = workspace.getPanelCount();
72 out.reserve(size_t(std::max(0, count)));
73 for (int i = 0; i < count; ++i) {
74 auto panel = workspace.panelAt(size_t(i));
75 if (!panel.ok()) continue;
76 if (!panel.value().visible) continue;
77 if (panel.value().region != region) continue;
78 out.push_back(std::move(panel).takeValue());
79 }
80 std::stable_sort(out.begin(), out.end(),
81 [](const WorkspacePanelDescriptor &a, const WorkspacePanelDescriptor &b) {
82 if (a.order != b.order) return a.order < b.order;
83 return a.id < b.id;
84 });
85 return out;
86}
87
89 ContentBuilder content,
91 const auto left = panelsInRegion(workspace, "left");
92 const auto right = panelsInRegion(workspace, "right");
93 const auto center = panelsInRegion(workspace, "center");
94 const auto bottom = panelsInRegion(workspace, "bottom");
95 const auto top = panelsInRegion(workspace, "top");
96 const std::string &active = workspace.getActivePanel();
97 const bool tabStack = options.tabStackRegions;
98
99 WidgetDesc centerPane =
100 wrapDock("center", regionContent(center, active, tabStack, content));
101 if (!right.empty()) {
102 centerPane = ui::splitPane(ui::FlexDirection::Row, std::move(centerPane),
103 wrapDock("right", regionContent(right, active, tabStack, content)),
104 1.f - clampRatio(options.rightRatio), "split/center-right");
105 }
106 WidgetDesc mainRow = std::move(centerPane);
107 if (!left.empty()) {
109 wrapDock("left", regionContent(left, active, tabStack, content)),
110 std::move(mainRow), clampRatio(options.leftRatio), "split/left-main");
111 }
112
113 WidgetDesc body = std::move(mainRow);
114 if (!top.empty()) {
116 wrapDock("top", regionContent(top, active, tabStack, content)),
117 std::move(body), 0.12f, "split/top-main");
118 }
119 if (!bottom.empty()) {
121 wrapDock("bottom", regionContent(bottom, active, tabStack, content)),
122 1.f - clampRatio(options.bottomRatio), "split/main-bottom");
123 }
124 body.flexGrow = 1.f;
125 return body;
126}
127
129 ContentBuilder content,
131 auto toolbar = std::move(options.toolbar);
132 auto statusBar = std::move(options.statusBar);
133 auto windowId = std::move(options.windowId);
134 WidgetDesc body = buildDockBody(workspace, std::move(content), std::move(options));
135 WidgetDesc frame = ui::appFrame(std::move(body), std::move(toolbar), std::move(statusBar), "app-frame");
136 std::vector<WidgetDesc> children;
137 children.reserve(1);
138 children.emplace_back(std::move(frame));
139 return ui::window(workspace.getTitle(), std::move(children), std::move(windowId));
140}
141
142} // namespace eve::ui_editor
bool & active
std::string title
ScriptFieldRegion region
HexVec3 left
HexVec3 right
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
ssq::Object frame
glm::dvec2 center
std::string body
Object::Ptr value
ScriptStructure out
const SquirrelValueOptions & options
int count
int children
Definition TreeMesh.cpp:432
float bottom
Composition model shared by project-specific developer and runtime editors.
Result< WorkspacePanelDescriptor > panelAt(std::size_t index) const
Return an owning panel snapshot instead of an ambiguous empty field.
int getPanelCount() const
Number of registered panels in deterministic region/order/id order.
const std::string & getActivePanel() const
Active panel id, or an empty string.
const std::string & getTitle() const
User-facing workspace title.
static std::vector< editor::WorkspacePanelDescriptor > panelsInRegion(const editor::EditorWorkspace &workspace, std::string_view region)
Collect visible panels for one region in deterministic order.
static ui::WidgetDesc buildDockBody(const editor::EditorWorkspace &workspace, ContentBuilder content={}, WorkspaceShellOptions options={})
Compose only the dock body (SplitPane + DockArea tree) without a Window. Useful when the caller alrea...
std::function< std::vector< ui::WidgetDesc >(const editor::WorkspacePanelDescriptor &panel)> ContentBuilder
Build panel body content for one workspace descriptor.
static ui::WidgetDesc buildWindow(const editor::EditorWorkspace &workspace, ContentBuilder content={}, WorkspaceShellOptions options={})
Compose a full Window tree for the workspace.
SQInteger top
Definition Snapshot.cpp:115
WidgetDesc panelFrame(std::string title, std::vector< WidgetDesc > children, std::string id)
Fixed titled panel chrome for dock regions (not a free-floating Window host).
Definition Widget.cpp:767
WidgetDesc tabContainer(std::vector< WidgetDesc > pages, std::string activePageId, std::string id, std::function< void(const std::string &)> onSelect)
Tab strip plus page bodies; only the active page is visible.
Definition Widget.cpp:739
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:326
WidgetDesc appFrame(WidgetDesc body, WidgetDesc toolbarWidget, WidgetDesc statusBarWidget, std::string id)
Fixed editor frame: optional toolbar, growing body, optional status bar. Place as a Window child (Men...
Definition Widget.cpp:793
WidgetDesc text(std::string content, std::string id)
Static text label.
Definition Widget.cpp:336
WidgetDesc splitPane(FlexDirection direction, WidgetDesc first, WidgetDesc second, float ratio, std::string id, std::function< void(float)> onResize)
Two resizable panes separated by a drag handle.
Definition Widget.cpp:699
WidgetDesc dockArea(std::string region, std::vector< WidgetDesc > children, std::string id)
Named dock fill slot; region name is stored in valueText (left/right/top/bottom/center)....
Definition Widget.cpp:780
UI-neutral description of one composable editor panel.
Declarative widget description (build once / on dirty → flatten into UIHost::Tree).
Definition Widget.h:15
std::string text
Definition Widget.h:20
Options that control the fixed IDE chrome produced by WorkspaceLayoutShell.