Skip to content

Commit 8beebf1

Browse files
committed
Improved project manager
1 parent 21d15f7 commit 8beebf1

File tree

2 files changed

+69
-59
lines changed

2 files changed

+69
-59
lines changed

Libs/Editor/Src/Utils/ProjectManager.cpp

+67-59
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,87 @@
1010

1111
namespace rift::Editor
1212
{
13+
void TextCentered(const char* text)
14+
{
15+
auto windowWidth = ImGui::GetWindowSize().x;
16+
auto textWidth = ImGui::CalcTextSize(text).x;
17+
18+
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
19+
ImGui::Text(text);
20+
}
21+
1322
void DrawProjectManager(ast::Tree& ast)
1423
{
1524
// Center modal when appearing
1625
UI::SetNextWindowPos(UI::GetMainViewport()->GetCenter(), ImGuiCond_Always, {0.5f, 0.5f});
1726

1827
p::v2 viewportSize = UI::GetMainViewport()->Size;
19-
p::v2 modalSize = p::v2{600.f, 400.f};
28+
p::v2 modalSize = p::v2{600.f, 0.f};
2029
modalSize.x = p::Min(modalSize.x, viewportSize.x - 20.f);
2130
modalSize.y = p::Min(modalSize.y, viewportSize.y - 20.f);
2231

2332
UI::SetNextWindowSize(modalSize, ImGuiCond_Always);
2433

2534
if (UI::BeginPopupModal("Project Manager", nullptr,
26-
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize))
35+
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize))
2736
{
28-
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
29-
UI::Text("Projects");
37+
UI::PushFont("WorkSans", UI::FontMode::Regular, 24.f);
38+
TextCentered("Projects");
3039
UI::PopFont();
31-
UI::Separator();
40+
41+
UI::Spacing();
3242
UI::Spacing();
3343

44+
static p::String folder;
45+
46+
ImGui::BeginTable("table", 2);
47+
ImGui::TableNextColumn();
48+
{
49+
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
50+
UI::Text("Open");
51+
UI::PopFont();
52+
UI::Separator();
53+
UI::Spacing();
54+
55+
UI::SetItemDefaultFocus();
56+
{
57+
UI::Text("Recent projects:");
58+
static const char* recentProjects[]{"Project.rift"};
59+
static int selectedN = 0;
60+
UI::SetNextItemWidth(-FLT_MIN);
61+
62+
for (int n = 0; n < IM_ARRAYSIZE(recentProjects); ++n)
63+
{
64+
const bool isSelected = (selectedN == n);
65+
UI::BulletText(recentProjects[n]);
66+
UI::SameLine(ImGui::GetContentRegionAvail().x - 30.f);
67+
if (UI::SmallButton("open")) {}
68+
}
69+
}
70+
UI::Dummy({10.f, 40.f});
71+
}
72+
ImGui::TableNextColumn();
73+
{
74+
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
75+
UI::Text("Create");
76+
UI::PopFont();
77+
UI::Separator();
78+
UI::Spacing();
79+
80+
UI::PushItemWidth(-32.f);
81+
UI::InputTextWithHint("##path", "project path...", folder);
82+
UI::PopItemWidth();
83+
UI::SameLine();
84+
if (UI::Button("...", p::v2{24.f, 0.f}))
85+
{
86+
p::Path selectedFolder =
87+
p::files::SelectFolderDialog("Select project folder", p::GetCurrentPath());
88+
folder = p::ToString(selectedFolder);
89+
}
90+
}
91+
92+
ImGui::TableNextRow();
93+
ImGui::TableNextColumn();
3494
if (UI::Button("Open", p::v2{-FLT_MIN, 0.0f}))
3595
{
3696
p::String folder =
@@ -45,60 +105,7 @@ namespace rift::Editor
45105
p::Strings::Format("Failed to open project at '{}'", p::ToString(folder))});
46106
}
47107
}
48-
UI::SetItemDefaultFocus();
49-
{
50-
UI::Text("Recent Projects");
51-
static const char* recentProjects[]{"One recent project"};
52-
static int selectedN = 0;
53-
UI::SetNextItemWidth(-FLT_MIN);
54-
if (UI::BeginListBox("##RecentProjects"))
55-
{
56-
for (int n = 0; n < IM_ARRAYSIZE(recentProjects); ++n)
57-
{
58-
const bool isSelected = (selectedN == n);
59-
if (UI::Selectable(recentProjects[n], isSelected))
60-
{
61-
selectedN = n;
62-
}
63-
64-
// Set the initial focus when opening the combo (scrolling + keyboard
65-
// navigation focus)
66-
if (isSelected)
67-
{
68-
UI::SetItemDefaultFocus();
69-
}
70-
}
71-
UI::EndListBox();
72-
}
73-
}
74-
75-
76-
UI::Spacing();
77-
UI::Spacing();
78-
UI::Spacing();
79-
UI::Spacing();
80-
81-
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
82-
UI::Text("New");
83-
UI::PopFont();
84-
UI::Separator();
85-
UI::Spacing();
86-
87-
UI::AlignTextToFramePadding();
88-
UI::Text("Destination");
89-
UI::SameLine();
90-
static p::String folder;
91-
UI::PushItemWidth(-32.f);
92-
UI::InputText("##path", folder);
93-
UI::PopItemWidth();
94-
UI::SameLine();
95-
if (UI::Button("...", p::v2{24.f, 0.f}))
96-
{
97-
p::Path selectedFolder =
98-
p::files::SelectFolderDialog("Select project folder", p::GetCurrentPath());
99-
folder = p::ToString(selectedFolder);
100-
}
101-
108+
ImGui::TableNextColumn();
102109
if (UI::Button("Create", p::v2{-FLT_MIN, 0.0f}))
103110
{
104111
if (Editor::Get().CreateProject(folder))
@@ -112,6 +119,7 @@ namespace rift::Editor
112119
p::Strings::Format("Failed to create project at '{}'", folder)});
113120
}
114121
}
122+
ImGui::EndTable();
115123

116124
UI::EndPopup();
117125
}

Libs/UI/Src/Style.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ namespace rift::UI
120120
"WorkSans", UI::FontMode::Regular, 14.f, resources / "Fonts/WorkSans-Regular.ttf");
121121
AddTextFont(
122122
"WorkSans", UI::FontMode::Regular, 18.f, resources / "Fonts/WorkSans-Regular.ttf");
123+
AddTextFont(
124+
"WorkSans", UI::FontMode::Regular, 24.f, resources / "Fonts/WorkSans-Regular.ttf");
123125

124126
// Karla
125127
AddTextFont("Karla", UI::FontMode::Bold, 14.f, resources / "Fonts/Karla-Bold.ttf");

0 commit comments

Comments
 (0)